@twreporter/react-article-components 2.1.1-beta.0 → 2.1.1-rc.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 TwReporter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -78,8 +78,7 @@ var _ = {
78
78
  };
79
79
  var embedNamespace = {
80
80
  infogram: 'infogram',
81
- twreporter: '__twreporterEmbeddedData',
82
- storyTellingReporter: '@story-telling-reporter'
81
+ twreporter: '__twreporterEmbeddedData'
83
82
  };
84
83
 
85
84
  var Block = /*#__PURE__*/_styledComponents["default"].div.withConfig({
@@ -208,23 +207,17 @@ var EmbeddedCode = /*#__PURE__*/function (_React$PureComponent) {
208
207
  _createClass(EmbeddedCode, [{
209
208
  key: "componentDidMount",
210
209
  value: function componentDidMount() {
211
- var _this$_embeddedCode, _this$_embeddedCode2;
212
-
213
- // !! WORKAROUND !!
214
- // After upgrading to react v18,
215
- // `EmbeddedCode` component becomes abnormal.
216
- // One case is that `EmbeddedCode` will `executeScript()` twice.
217
- // Therefore, the embedded code will generate duplicate contents.
218
- //
219
- // To avoid `executeScript()` twice,
220
- // temporarily comment out the following condition.
221
- //
222
- // Delay loading infogram in loadEmbed()
223
- // if (!this._embeddedCodeWithoutScript?.includes(embedNamespace.infogram)) {
224
- // this.setState({ isLoaded: true }, this.executeScript)
225
- // }
226
- // Deliberately set z-index for embeded from @twreporter
227
- if ((_this$_embeddedCode = this._embeddedCode) !== null && _this$_embeddedCode !== void 0 && _this$_embeddedCode.includes(embedNamespace.twreporter) || (_this$_embeddedCode2 = this._embeddedCode) !== null && _this$_embeddedCode2 !== void 0 && _this$_embeddedCode2.includes(embedNamespace.storyTellingReporter)) {
210
+ var _this$_embeddedCodeWi, _this$_embeddedCode;
211
+
212
+ // Delay loading infogram in loadEmbed()
213
+ if (!((_this$_embeddedCodeWi = this._embeddedCodeWithoutScript) !== null && _this$_embeddedCodeWi !== void 0 && _this$_embeddedCodeWi.includes(embedNamespace.infogram))) {
214
+ this.setState({
215
+ isLoaded: true
216
+ }, this.executeScript);
217
+ } // Deliberately set z-index for embeded from @twreporter
218
+
219
+
220
+ if ((_this$_embeddedCode = this._embeddedCode) !== null && _this$_embeddedCode !== void 0 && _this$_embeddedCode.includes(embedNamespace.twreporter)) {
228
221
  this.setState({
229
222
  shouldEscalateZIndex: true
230
223
  });
@@ -241,7 +234,7 @@ var EmbeddedCode = /*#__PURE__*/function (_React$PureComponent) {
241
234
  }, {
242
235
  key: "render",
243
236
  value: function render() {
244
- var _this$_embeddedCodeWi;
237
+ var _this$_embeddedCodeWi2;
245
238
 
246
239
  var className = this.props.className;
247
240
  var shouldEscalateZIndex = this.state.shouldEscalateZIndex;
@@ -256,7 +249,7 @@ var EmbeddedCode = /*#__PURE__*/function (_React$PureComponent) {
256
249
  }
257
250
  }), this._caption ? /*#__PURE__*/_react["default"].createElement(Caption, null, this._caption) : null);
258
251
 
259
- if ((_this$_embeddedCodeWi = this._embeddedCodeWithoutScript) !== null && _this$_embeddedCodeWi !== void 0 && _this$_embeddedCodeWi.includes(embedNamespace.infogram)) {
252
+ if ((_this$_embeddedCodeWi2 = this._embeddedCodeWithoutScript) !== null && _this$_embeddedCodeWi2 !== void 0 && _this$_embeddedCodeWi2.includes(embedNamespace.infogram)) {
260
253
  return this.state.isLoaded ? embed : null;
261
254
  }
262
255
 
@@ -316,7 +309,7 @@ var WayPointWrapper = function WayPointWrapper(props) {
316
309
  onEnter: onEnter,
317
310
  onLeave: onLeave,
318
311
  fireOnRapidScroll: false,
319
- topOffset: "-150%"
312
+ topOffset: 5
320
313
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(EmbeddedCode, _extends({}, props, {
321
314
  ref: embedRef
322
315
  }))))
@@ -25,6 +25,8 @@ var _releaseBranch = _interopRequireDefault(require("@twreporter/core/lib/consta
25
25
 
26
26
  var _zIndex = _interopRequireDefault(require("@twreporter/core/lib/constants/z-index"));
27
27
 
28
+ var _mediaQuery = require("@twreporter/core/lib/utils/media-query");
29
+
28
30
  var _image = require("../../utils/image");
29
31
 
30
32
  var _imgWithPlaceholder = _interopRequireDefault(require("../../constants/prop-types/img-with-placeholder"));
@@ -33,6 +35,8 @@ var _get = _interopRequireDefault(require("lodash/get"));
33
35
 
34
36
  var _map = _interopRequireDefault(require("lodash/map"));
35
37
 
38
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
39
+
36
40
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
37
41
 
38
42
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -79,7 +83,8 @@ PlaceholderIcon.defaultProps = {
79
83
  };
80
84
  var _ = {
81
85
  get: _get["default"],
82
- map: _map["default"]
86
+ map: _map["default"],
87
+ debounce: _debounce["default"]
83
88
  };
84
89
  var objectFitConsts = {
85
90
  contain: 'contain',
@@ -174,13 +179,24 @@ var Img = /*#__PURE__*/function (_React$PureComponent) {
174
179
  _classCallCheck(this, Img);
175
180
 
176
181
  _this = _super.call(this, props);
182
+
183
+ _defineProperty(_assertThisInitialized(_this), "_handleWindowResize", function () {
184
+ var windowWidth = window.innerWidth;
185
+
186
+ _this.setState({
187
+ isMobile: windowWidth < _mediaQuery.DEFAULT_SCREEN.tablet.minWidth
188
+ });
189
+ });
190
+
177
191
  _this.state = {
178
192
  isLoaded: false,
179
193
  toShowPlaceholder: true,
180
- showFullScreenImg: false
194
+ showFullScreenImg: false,
195
+ isMobile: false
181
196
  };
182
197
  _this._img = /*#__PURE__*/_react["default"].createRef();
183
198
  _this.handleImageLoaded = _this.handleImageLoaded.bind(_assertThisInitialized(_this));
199
+ _this.handleWindowResize = _.debounce(_this._handleWindowResize, 500).bind(_assertThisInitialized(_this));
184
200
  _this._isMounted = false;
185
201
  _this._supportObjectFit = true;
186
202
  return _this;
@@ -198,11 +214,15 @@ var Img = /*#__PURE__*/function (_React$PureComponent) {
198
214
  if (_.get(this._img.current, 'complete')) {
199
215
  this.handleImageLoaded();
200
216
  }
217
+
218
+ window.addEventListener('resize', this.handleWindowResize);
219
+ this.handleWindowResize();
201
220
  }
202
221
  }, {
203
222
  key: "componentWillUnmount",
204
223
  value: function componentWillUnmount() {
205
224
  this._isMounted = false;
225
+ window.removeEventListener('resize', this.handleWindowResize);
206
226
  }
207
227
  }, {
208
228
  key: "handleImageLoaded",
@@ -264,7 +284,8 @@ var Img = /*#__PURE__*/function (_React$PureComponent) {
264
284
 
265
285
  var _this$state = this.state,
266
286
  isLoaded = _this$state.isLoaded,
267
- showFullScreenImg = _this$state.showFullScreenImg;
287
+ showFullScreenImg = _this$state.showFullScreenImg,
288
+ isMobile = _this$state.isMobile;
268
289
  var _this$props2 = this.props,
269
290
  alt = _this$props2.alt,
270
291
  className = _this$props2.className,
@@ -278,7 +299,7 @@ var Img = /*#__PURE__*/function (_React$PureComponent) {
278
299
  var releaseBranch = (this === null || this === void 0 ? void 0 : (_this$context = this.context) === null || _this$context === void 0 ? void 0 : _this$context.releaseBranch) || _releaseBranch["default"].release;
279
300
 
280
301
  var openFullScreen = function openFullScreen() {
281
- if (!clickable) return;
302
+ if (isMobile) return;
282
303
 
283
304
  _this3.setState({
284
305
  showFullScreenImg: true
@@ -321,7 +342,7 @@ var Img = /*#__PURE__*/function (_React$PureComponent) {
321
342
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(ImgContainer, {
322
343
  className: appendedClassName,
323
344
  $heightString: isObjectFit ? "height: 100%;" : "padding-top: ".concat(heightWidthRatio * 100, "%;"),
324
- onClick: openFullScreen
345
+ onClick: clickable ? openFullScreen : undefined
325
346
  }, this._renderImagePlaceholder(), /*#__PURE__*/_react["default"].createElement(ImgBox, {
326
347
  $toShow: isLoaded
327
348
  }, isObjectFit ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(ImgWithObjectFit, _extends({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twreporter/react-article-components",
3
- "version": "2.1.1-beta.0",
3
+ "version": "2.1.1-rc.0",
4
4
  "description": "The Reporter react article components, which are used in article page",
5
5
  "main": "lib/components/article-page.js",
6
6
  "repository": "https://github.com/twreporter/twreporter-npm-packages.git",
@@ -24,10 +24,10 @@
24
24
  "webpack-dev-server": "^3.7.2"
25
25
  },
26
26
  "dependencies": {
27
- "@twreporter/core": "^1.22.0",
28
- "@twreporter/react-components": "^9.0.1",
29
- "@twreporter/redux": "^8.0.1",
30
- "@twreporter/universal-header": "^3.0.1",
27
+ "@twreporter/core": "^1.22.1-rc.0",
28
+ "@twreporter/react-components": "^9.0.2-rc.0",
29
+ "@twreporter/redux": "^8.0.2-rc.0",
30
+ "@twreporter/universal-header": "^3.0.2-rc.0",
31
31
  "howler": "^2.2.3",
32
32
  "lodash": "^4.17.11",
33
33
  "memoize-one": "^5.0.5",
@@ -40,5 +40,6 @@
40
40
  },
41
41
  "files": [
42
42
  "lib"
43
- ]
43
+ ],
44
+ "gitHead": "40ff2a4c83c47f90335072049e9bb65a789088a6"
44
45
  }