@twreporter/react-article-components 2.5.2-rc.1 → 2.5.2-rc.3
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.
|
@@ -15,6 +15,7 @@ var _body = _interopRequireDefault(require("../../constants/prop-types/body"));
|
|
|
15
15
|
var _color = require("@twreporter/core/lib/constants/color");
|
|
16
16
|
var _zIndex = _interopRequireDefault(require("@twreporter/core/lib/constants/z-index"));
|
|
17
17
|
var _theme = require("@twreporter/core/lib/constants/theme");
|
|
18
|
+
var _excluded = ["isScrollingToAnchor"];
|
|
18
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
20
21
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
@@ -26,6 +27,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
26
27
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
27
28
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
28
29
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
30
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
31
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
29
32
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
30
33
|
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); } }
|
|
31
34
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -80,6 +83,9 @@ function dispatchWindowLoadEvent() {
|
|
|
80
83
|
}
|
|
81
84
|
window.dispatchEvent(loadEvent);
|
|
82
85
|
}
|
|
86
|
+
var dispatchInlineScriptLoadEvent = function dispatchInlineScriptLoadEvent(scriptText) {
|
|
87
|
+
return "".concat(scriptText, "\n // Manually trigger the load event on the script itself\n const loadEvent = new Event('load');\n document.currentScript.dispatchEvent(loadEvent); // Dispatches load event on this script element\n ");
|
|
88
|
+
};
|
|
83
89
|
var EmbeddedCode = /*#__PURE__*/function (_React$PureComponent) {
|
|
84
90
|
_inherits(EmbeddedCode, _React$PureComponent);
|
|
85
91
|
var _super = _createSuper(EmbeddedCode);
|
|
@@ -94,38 +100,41 @@ var EmbeddedCode = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
94
100
|
_defineProperty(_assertThisInitialized(_this), "executeScript", function () {
|
|
95
101
|
var node = _this._embedded.current;
|
|
96
102
|
var scripts = _.get(_this.props, ['data', 'content', 0, 'scripts']);
|
|
97
|
-
if (node
|
|
98
|
-
|
|
99
|
-
var loadScriptsCount = 0;
|
|
100
|
-
var scriptsFragment = new DocumentFragment(); // eslint-disable-line no-undef
|
|
101
|
-
_.forEach(scripts, function (script) {
|
|
102
|
-
var scriptEle = document.createElement('script');
|
|
103
|
-
var attribs = script.attribs;
|
|
104
|
-
_.forEach(attribs, function (value, name) {
|
|
105
|
-
try {
|
|
106
|
-
scriptEle.setAttribute(name, value);
|
|
107
|
-
} catch (err) {
|
|
108
|
-
console.error('Failed to set an attribute to the embbeded script.\n', "embedded element id: ".concat(_.get(_this.props, 'data.id', ''), "\n"), "attribute name: ".concat(name, "\n"), "attribute value: ".concat(value, "\n"), 'error:\n', err);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
scriptEle.text = script.text || '';
|
|
112
|
-
// `dispatchWindowLoadEvent` is a workaround to trigger rendering of venngage infographics:
|
|
113
|
-
// The embedded venngage code (https://infograph.venngage.com/js/embed/v1/embed.js)
|
|
114
|
-
// will only initiate when `load` event on `window` is emitted.
|
|
115
|
-
// Hence, we need to emit the `load` event of `window` manually after all scripts are load.
|
|
116
|
-
var handleLoad = function handleLoad() {
|
|
117
|
-
loadScriptsCount += 1;
|
|
118
|
-
if (loadScriptsCount === scriptsCount) {
|
|
119
|
-
/* all scripts are load */
|
|
120
|
-
dispatchWindowLoadEvent();
|
|
121
|
-
}
|
|
122
|
-
scriptEle.removeEventListener('load', handleLoad);
|
|
123
|
-
};
|
|
124
|
-
scriptEle.addEventListener('load', handleLoad);
|
|
125
|
-
scriptsFragment.appendChild(scriptEle);
|
|
126
|
-
});
|
|
127
|
-
node.appendChild(scriptsFragment);
|
|
103
|
+
if (!node || !Array.isArray(scripts)) {
|
|
104
|
+
return;
|
|
128
105
|
}
|
|
106
|
+
var scriptsCount = scripts.length;
|
|
107
|
+
var loadScriptsCount = 0;
|
|
108
|
+
var scriptsFragment = new DocumentFragment(); // eslint-disable-line no-undef
|
|
109
|
+
_.forEach(scripts, function (script, index) {
|
|
110
|
+
var scriptEle = document.createElement('script');
|
|
111
|
+
var attribs = script.attribs;
|
|
112
|
+
var isInlineScript = !attribs.src;
|
|
113
|
+
_.forEach(attribs, function (value, name) {
|
|
114
|
+
try {
|
|
115
|
+
scriptEle.setAttribute(name, value);
|
|
116
|
+
} catch (err) {
|
|
117
|
+
console.error('Failed to set an attribute to the embbeded script.\n', "embedded element id: ".concat(_.get(_this.props, 'data.id', ''), "\n"), "attribute name: ".concat(name, "\n"), "attribute value: ".concat(value, "\n"), 'error:\n', err);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
scriptEle.text = (isInlineScript ? dispatchInlineScriptLoadEvent(script.text) : script.text) || '';
|
|
121
|
+
// `dispatchWindowLoadEvent` is a workaround to trigger rendering of venngage infographics:
|
|
122
|
+
// The embedded venngage code (https://infograph.venngage.com/js/embed/v1/embed.js)
|
|
123
|
+
// will only initiate when `load` event on `window` is emitted.
|
|
124
|
+
// Hence, we need to emit the `load` event of `window` manually after all scripts are load.
|
|
125
|
+
var handleLoad = function handleLoad() {
|
|
126
|
+
loadScriptsCount += 1;
|
|
127
|
+
if (loadScriptsCount === scriptsCount) {
|
|
128
|
+
/* all scripts are load */
|
|
129
|
+
dispatchWindowLoadEvent();
|
|
130
|
+
_this.props.handleFinishLoaded();
|
|
131
|
+
}
|
|
132
|
+
scriptEle.removeEventListener('load', handleLoad);
|
|
133
|
+
};
|
|
134
|
+
scriptEle.addEventListener('load', handleLoad);
|
|
135
|
+
scriptsFragment.appendChild(scriptEle);
|
|
136
|
+
});
|
|
137
|
+
node.appendChild(scriptsFragment);
|
|
129
138
|
});
|
|
130
139
|
_defineProperty(_assertThisInitialized(_this), "loadEmbed", function () {
|
|
131
140
|
if (!_this.state.isLoaded) {
|
|
@@ -208,15 +217,18 @@ _defineProperty(EmbeddedCode, "propTypes", {
|
|
|
208
217
|
className: _propTypes["default"].string,
|
|
209
218
|
data: _body["default"].elementData,
|
|
210
219
|
showCaption: _propTypes["default"].bool,
|
|
211
|
-
handleIsLoaded: _propTypes["default"].func
|
|
220
|
+
handleIsLoaded: _propTypes["default"].func,
|
|
221
|
+
handleFinishLoaded: _propTypes["default"].func
|
|
212
222
|
});
|
|
213
223
|
_defineProperty(EmbeddedCode, "defaultProps", {
|
|
214
224
|
className: '',
|
|
215
225
|
showCaption: true,
|
|
216
226
|
handleIsLoaded: function handleIsLoaded() {}
|
|
217
227
|
});
|
|
218
|
-
var WayPointWrapper = function WayPointWrapper(
|
|
219
|
-
var
|
|
228
|
+
var WayPointWrapper = function WayPointWrapper(_ref) {
|
|
229
|
+
var _ref$isScrollingToAnc = _ref.isScrollingToAnchor,
|
|
230
|
+
isScrollingToAnchor = _ref$isScrollingToAnc === void 0 ? false : _ref$isScrollingToAnc,
|
|
231
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
220
232
|
var _useState = (0, _react.useState)(false),
|
|
221
233
|
_useState2 = _slicedToArray(_useState, 2),
|
|
222
234
|
isInViewPort = _useState2[0],
|
|
@@ -253,12 +265,7 @@ var WayPointWrapper = function WayPointWrapper(props) {
|
|
|
253
265
|
}))))
|
|
254
266
|
);
|
|
255
267
|
};
|
|
256
|
-
WayPointWrapper.defaultProps = {
|
|
257
|
-
isScrollingToAnchor: false,
|
|
258
|
-
showCaption: true
|
|
259
|
-
};
|
|
260
268
|
WayPointWrapper.propTypes = {
|
|
261
|
-
isScrollingToAnchor: _propTypes["default"].bool
|
|
262
|
-
showCaption: _propTypes["default"].bool
|
|
269
|
+
isScrollingToAnchor: _propTypes["default"].bool
|
|
263
270
|
};
|
|
264
271
|
var _default = exports["default"] = WayPointWrapper;
|
|
@@ -101,8 +101,11 @@ var Embedded = function Embedded(_ref) {
|
|
|
101
101
|
var onTopicClick = function onTopicClick() {
|
|
102
102
|
navigate.push(topicHref);
|
|
103
103
|
};
|
|
104
|
-
var
|
|
105
|
-
|
|
104
|
+
var handleFinishLoaded = function handleFinishLoaded() {
|
|
105
|
+
// add timeout before hidding loading to prevent content shifting
|
|
106
|
+
window.setTimeout(function () {
|
|
107
|
+
return setIsLoading(false);
|
|
108
|
+
}, 500);
|
|
106
109
|
};
|
|
107
110
|
(0, _react.useEffect)(function () {
|
|
108
111
|
if (embedded.length > 0) {
|
|
@@ -124,15 +127,10 @@ var Embedded = function Embedded(_ref) {
|
|
|
124
127
|
});
|
|
125
128
|
}
|
|
126
129
|
}, []);
|
|
127
|
-
(0, _react.useEffect)(function () {
|
|
128
|
-
window.addEventListener('load', handleIsLoaded, true);
|
|
129
|
-
return function () {
|
|
130
|
-
return window.removeEventListener('load', handleIsLoaded, true);
|
|
131
|
-
};
|
|
132
|
-
}, []);
|
|
133
130
|
return /*#__PURE__*/_react["default"].createElement("div", null, isLoading ? /*#__PURE__*/_react["default"].createElement(LoaderContainer, null, /*#__PURE__*/_react["default"].createElement(Loader, null)) : null, embeddedCode ? /*#__PURE__*/_react["default"].createElement(EmbeddedBlock, null, /*#__PURE__*/_react["default"].createElement(_embeddedCode["default"], {
|
|
134
131
|
data: embeddedCode,
|
|
135
|
-
showCaption: !captionText
|
|
132
|
+
showCaption: !captionText,
|
|
133
|
+
handleFinishLoaded: handleFinishLoaded
|
|
136
134
|
})) : null, /*#__PURE__*/_react["default"].createElement(ContentBlock, null, /*#__PURE__*/_react["default"].createElement(TitleBlock, null, isTopicPublished && shortTitle ? /*#__PURE__*/_react["default"].createElement(TopicTitle, {
|
|
137
135
|
onClick: onTopicClick
|
|
138
136
|
}, /*#__PURE__*/_react["default"].createElement(_paragraph.P2, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twreporter/react-article-components",
|
|
3
|
-
"version": "2.5.2-rc.
|
|
3
|
+
"version": "2.5.2-rc.3",
|
|
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",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"files": [
|
|
42
42
|
"lib"
|
|
43
43
|
],
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "b0221e49ef87d15b3d934f3007700a2e51501e97"
|
|
45
45
|
}
|