@times-components/article 7.9.10 → 7.10.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/CHANGELOG.md +27 -0
- package/babel.config.js +12 -5
- package/dist/article.js +98 -1
- package/dist/utils/index.js +68 -1
- package/package.json +11 -16
- package/rnw.js +1 -1
- package/tsconfig.jest.json +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [7.10.0](https://github.com/newsuk/times-components/compare/@times-components/article@7.9.12...@times-components/article@7.10.0) (2022-07-21)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **TDP-1712:** imported jest-config-web and updated with some local … ([#3043](https://github.com/newsuk/times-components/issues/3043)) ([d502434](https://github.com/newsuk/times-components/commit/d502434b1005da88567a3849155cf5fa2c6cc755))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [7.9.12](https://github.com/newsuk/times-components/compare/@times-components/article@7.9.11...@times-components/article@7.9.12) (2022-07-21)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @times-components/article
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [7.9.11](https://github.com/newsuk/times-components/compare/@times-components/article@7.9.10...@times-components/article@7.9.11) (2022-07-20)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package @times-components/article
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
## [7.9.10](https://github.com/newsuk/times-components/compare/@times-components/article@7.9.9...@times-components/article@7.9.10) (2022-07-20)
|
|
7
34
|
|
|
8
35
|
**Note:** Version bump only for package @times-components/article
|
package/babel.config.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
module.exports = api => {
|
|
2
2
|
api.cache(true);
|
|
3
3
|
return {
|
|
4
|
-
plugins: [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
plugins: ["babel-plugin-styled-components"],
|
|
5
|
+
presets: [
|
|
6
|
+
[
|
|
7
|
+
"@babel/preset-env",
|
|
8
|
+
{
|
|
9
|
+
targets: {
|
|
10
|
+
esmodules: true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"@babel/preset-react"
|
|
15
|
+
]
|
|
9
16
|
};
|
|
10
17
|
};
|
package/dist/article.js
CHANGED
|
@@ -1 +1,98 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.TakeoverBailout = exports.templates = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _articleMagazineComment = _interopRequireDefault(require("@times-components/article-magazine-comment"));
|
|
11
|
+
|
|
12
|
+
var _articleInDepth = _interopRequireDefault(require("@times-components/article-in-depth"));
|
|
13
|
+
|
|
14
|
+
var _articleMagazineStandard = _interopRequireDefault(require("@times-components/article-magazine-standard"));
|
|
15
|
+
|
|
16
|
+
var _articleMainStandard = _interopRequireDefault(require("@times-components/article-main-standard"));
|
|
17
|
+
|
|
18
|
+
var _articleMainComment = _interopRequireDefault(require("@times-components/article-main-comment"));
|
|
19
|
+
|
|
20
|
+
var _responsive = _interopRequireDefault(require("@times-components/responsive"));
|
|
21
|
+
|
|
22
|
+
var _tsStyleguide = require("@times-components/ts-styleguide");
|
|
23
|
+
|
|
24
|
+
var _messageBar = require("@times-components/message-bar");
|
|
25
|
+
|
|
26
|
+
var _utils = require("./utils");
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
31
|
+
|
|
32
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
33
|
+
|
|
34
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
const templates = {
|
|
39
|
+
indepth: _articleInDepth.default,
|
|
40
|
+
magazinecomment: _articleMagazineComment.default,
|
|
41
|
+
magazinestandard: _articleMagazineStandard.default,
|
|
42
|
+
maincomment: _articleMainComment.default,
|
|
43
|
+
mainstandard: _articleMainStandard.default
|
|
44
|
+
};
|
|
45
|
+
exports.templates = templates;
|
|
46
|
+
|
|
47
|
+
class TakeoverBailout extends Error {
|
|
48
|
+
constructor(message) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = "TakeoverBailout";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.TakeoverBailout = TakeoverBailout;
|
|
56
|
+
|
|
57
|
+
const Article = props => {
|
|
58
|
+
const article = props.article,
|
|
59
|
+
onImagePress = props.onImagePress;
|
|
60
|
+
|
|
61
|
+
const _ref = article || {},
|
|
62
|
+
leadAsset = _ref.leadAsset,
|
|
63
|
+
template = _ref.template;
|
|
64
|
+
|
|
65
|
+
let _ref2 = article || {},
|
|
66
|
+
content = _ref2.content;
|
|
67
|
+
|
|
68
|
+
if (template === "takeoverpage") {
|
|
69
|
+
throw new TakeoverBailout("Aborted react render: Takeover page");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let onImagePressArticle = null;
|
|
73
|
+
|
|
74
|
+
if (onImagePress) {
|
|
75
|
+
content = (0, _utils.addIndexesToInlineImages)(content, leadAsset);
|
|
76
|
+
const mediaList = (0, _utils.getMediaList)(content, leadAsset);
|
|
77
|
+
|
|
78
|
+
onImagePressArticle = index => onImagePress(index, mediaList);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const Component = templates[template] || _articleMainStandard.default;
|
|
82
|
+
|
|
83
|
+
const newProps = _objectSpread(_objectSpread({}, props), {}, {
|
|
84
|
+
article: _objectSpread(_objectSpread({}, article), {}, {
|
|
85
|
+
template: article && article.template ? article.template : "mainstandard"
|
|
86
|
+
})
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return /*#__PURE__*/_react.default.createElement(_responsive.default, null, /*#__PURE__*/_react.default.createElement(_messageBar.MessageManager, {
|
|
90
|
+
delay: 3000,
|
|
91
|
+
scale: _tsStyleguide.scales.medium
|
|
92
|
+
}, /*#__PURE__*/_react.default.createElement(Component, _extends({}, newProps, {
|
|
93
|
+
onImagePress: onImagePressArticle
|
|
94
|
+
}))));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
var _default = Article;
|
|
98
|
+
exports.default = _default;
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1,68 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getMediaList = exports.addIndexesToInlineImages = void 0;
|
|
7
|
+
|
|
8
|
+
const getMediaList = (content, leadAsset) => {
|
|
9
|
+
const ast = content || [];
|
|
10
|
+
let index = 0;
|
|
11
|
+
const mediaList = [];
|
|
12
|
+
|
|
13
|
+
if (leadAsset) {
|
|
14
|
+
index += 1;
|
|
15
|
+
mediaList.push({
|
|
16
|
+
index: 0,
|
|
17
|
+
name: "leadAsset",
|
|
18
|
+
value: leadAsset
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const inlineMediaList = ast.filter(item => item.name === "image" || item.name === "video");
|
|
23
|
+
inlineMediaList.forEach(item => {
|
|
24
|
+
let inlineMedia;
|
|
25
|
+
|
|
26
|
+
if (item.name === "video") {
|
|
27
|
+
const _item$attributes = item.attributes,
|
|
28
|
+
caption = _item$attributes.caption,
|
|
29
|
+
posterImageUrl = _item$attributes.posterImageUrl;
|
|
30
|
+
inlineMedia = {
|
|
31
|
+
index,
|
|
32
|
+
name: "inlineVideo",
|
|
33
|
+
value: {
|
|
34
|
+
caption,
|
|
35
|
+
posterImageUrl
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
} else {
|
|
39
|
+
inlineMedia = {
|
|
40
|
+
index,
|
|
41
|
+
name: "inlineImage",
|
|
42
|
+
value: item.attributes
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
index += 1;
|
|
47
|
+
mediaList.push(inlineMedia);
|
|
48
|
+
});
|
|
49
|
+
return mediaList;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.getMediaList = getMediaList;
|
|
53
|
+
|
|
54
|
+
const addIndexesToInlineImages = (content, leadAsset) => {
|
|
55
|
+
const mutatedContent = content || [];
|
|
56
|
+
let index = leadAsset ? 1 : 0;
|
|
57
|
+
mutatedContent.forEach(item => {
|
|
58
|
+
const contentItem = item;
|
|
59
|
+
|
|
60
|
+
if (contentItem.name === "image" || contentItem.name === "video") {
|
|
61
|
+
contentItem.attributes.imageIndex = index;
|
|
62
|
+
index += 1;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return mutatedContent;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
exports.addIndexesToInlineImages = addIndexesToInlineImages;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@times-components/article",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.10.0",
|
|
4
4
|
"description": "The article",
|
|
5
5
|
"main": "dist/article",
|
|
6
6
|
"dev": "src/article",
|
|
@@ -21,10 +21,7 @@
|
|
|
21
21
|
"url": "git+https://github.com/newsuk/times-components.git"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
|
24
|
-
"react-native-web",
|
|
25
24
|
"react",
|
|
26
|
-
"native",
|
|
27
|
-
"web",
|
|
28
25
|
"article",
|
|
29
26
|
"component"
|
|
30
27
|
],
|
|
@@ -35,8 +32,10 @@
|
|
|
35
32
|
"homepage": "https://github.com/newsuk/times-components#readme",
|
|
36
33
|
"devDependencies": {
|
|
37
34
|
"@babel/core": "7.4.4",
|
|
35
|
+
"@babel/preset-env": "7.4.4",
|
|
36
|
+
"@babel/preset-react": "7.9.1",
|
|
38
37
|
"@times-components/eslint-config-thetimes": "0.8.18",
|
|
39
|
-
"@times-components/jest-configurator": "
|
|
38
|
+
"@times-components/jest-configurator-web": "0.5.0",
|
|
40
39
|
"@times-components/provider-test-tools": "1.26.5",
|
|
41
40
|
"@times-components/storybook": "4.4.0",
|
|
42
41
|
"@times-components/tealium-utils": "0.7.75",
|
|
@@ -53,19 +52,17 @@
|
|
|
53
52
|
"react": "16.9.0",
|
|
54
53
|
"react-art": "16.6.3",
|
|
55
54
|
"react-dom": "16.9.0",
|
|
56
|
-
"react-native": "0.61.5",
|
|
57
|
-
"react-native-web": "0.11.4",
|
|
58
55
|
"react-test-renderer": "16.9.0",
|
|
59
56
|
"webpack": "4.30.0",
|
|
60
57
|
"webpack-cli": "3.3.1"
|
|
61
58
|
},
|
|
62
59
|
"dependencies": {
|
|
63
60
|
"@times-components/ad": "2.20.2",
|
|
64
|
-
"@times-components/article-in-depth": "3.55.
|
|
65
|
-
"@times-components/article-magazine-comment": "3.54.
|
|
66
|
-
"@times-components/article-magazine-standard": "3.53.
|
|
67
|
-
"@times-components/article-main-comment": "2.52.
|
|
68
|
-
"@times-components/article-main-standard": "3.59.
|
|
61
|
+
"@times-components/article-in-depth": "3.55.8",
|
|
62
|
+
"@times-components/article-magazine-comment": "3.54.8",
|
|
63
|
+
"@times-components/article-magazine-standard": "3.53.8",
|
|
64
|
+
"@times-components/article-main-comment": "2.52.8",
|
|
65
|
+
"@times-components/article-main-standard": "3.59.8",
|
|
69
66
|
"@times-components/context": "1.9.3",
|
|
70
67
|
"@times-components/message-bar": "0.6.4",
|
|
71
68
|
"@times-components/provider": "1.32.6",
|
|
@@ -78,12 +75,10 @@
|
|
|
78
75
|
},
|
|
79
76
|
"peerDependencies": {
|
|
80
77
|
"react": ">=16.9",
|
|
81
|
-
"react-dom": ">=16.9"
|
|
82
|
-
"react-native": ">=0.59",
|
|
83
|
-
"react-native-web": "0.11.4"
|
|
78
|
+
"react-dom": ">=16.9"
|
|
84
79
|
},
|
|
85
80
|
"publishConfig": {
|
|
86
81
|
"access": "public"
|
|
87
82
|
},
|
|
88
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "7dec87e28716d6db52b2486e39322e928a70aa07"
|
|
89
84
|
}
|
package/rnw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports=function(e){var t={};function r
|
|
1
|
+
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=9)}([function(e,t){e.exports=require("react")},function(e,t){e.exports=require("@times-components/article-main-standard/rnw")},function(e,t){e.exports=require("@times-components/article-magazine-comment/rnw")},function(e,t){e.exports=require("@times-components/article-in-depth/rnw")},function(e,t){e.exports=require("@times-components/article-magazine-standard/rnw")},function(e,t){e.exports=require("@times-components/article-main-comment/rnw")},function(e,t){e.exports=require("@times-components/responsive/rnw")},function(e,t){e.exports=require("@times-components/ts-styleguide/rnw")},function(e,t){e.exports=require("@times-components/message-bar/rnw")},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),a=n(2),i=n.n(a),c=n(3),s=n.n(c),u=n(4),l=n.n(u),m=n(1),p=n.n(m),f=n(5),d=n.n(f),b=n(6),g=n.n(b),y=n(7),v=n(8);function O(){return(O=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function j(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function x(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?j(Object(n),!0).forEach((function(t){w(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):j(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function w(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,"templates",(function(){return P})),n.d(t,"TakeoverBailout",(function(){return h}));const P={indepth:s.a,magazinecomment:i.a,magazinestandard:l.a,maincomment:d.a,mainstandard:p.a};class h extends Error{constructor(e){super(e),this.name="TakeoverBailout"}}t.default=e=>{const t=e.article,n=e.onImagePress,r=t||{},a=r.leadAsset,i=r.template;let c=(t||{}).content;if("takeoverpage"===i)throw new h("Aborted react render: Takeover page");let s=null;if(n){c=((e,t)=>{const n=e||[];let r=t?1:0;return n.forEach(e=>{const t=e;"image"!==t.name&&"video"!==t.name||(t.attributes.imageIndex=r,r+=1)}),n})(c,a);const e=((e,t)=>{const n=e||[];let r=0;const o=[];t&&(r+=1,o.push({index:0,name:"leadAsset",value:t}));return n.filter(e=>"image"===e.name||"video"===e.name).forEach(e=>{let t;if("video"===e.name){const n=e.attributes,o=n.caption,a=n.posterImageUrl;t={index:r,name:"inlineVideo",value:{caption:o,posterImageUrl:a}}}else t={index:r,name:"inlineImage",value:e.attributes};r+=1,o.push(t)}),o})(c,a);s=t=>n(t,e)}const u=P[i]||p.a,l=x(x({},e),{},{article:x(x({},t),{},{template:t&&t.template?t.template:"mainstandard"})});return o.a.createElement(g.a,null,o.a.createElement(v.MessageManager,{delay:3e3,scale:y.scales.medium},o.a.createElement(u,O({},l,{onImagePress:s}))))}}]);
|