@automattic/social-previews 1.0.4 → 1.1.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.
@@ -1,75 +1,57 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _createSuper from "@babel/runtime/helpers/createSuper";
5
-
6
- /**
7
- * External dependencies
8
- */
9
- import PropTypes from 'prop-types';
10
- import React, { PureComponent } from 'react';
11
1
  import { compact } from 'lodash';
2
+ import PropTypes from 'prop-types';
3
+ import { PureComponent } from 'react';
12
4
  import { firstValid, hardTruncation, shortEnough, stripHtmlTags } from '../helpers';
13
- /**
14
- * Style dependencies
15
- */
16
-
17
5
  import './style.scss';
18
- var TITLE_LENGTH = 80;
19
- var DESCRIPTION_LENGTH = 200;
20
-
21
- var baseDomain = function baseDomain(url) {
22
- return url && url.replace(/^[^/]+[/]*/, '') // strip leading protocol
23
- .replace(/\/.*$/, '');
24
- }; // strip everything after the domain
25
-
26
-
27
- var facebookTitle = firstValid(shortEnough(TITLE_LENGTH), hardTruncation(TITLE_LENGTH));
28
- var facebookDescription = firstValid(shortEnough(DESCRIPTION_LENGTH), hardTruncation(DESCRIPTION_LENGTH));
29
- export var FacebookPreview = /*#__PURE__*/function (_PureComponent) {
30
- _inherits(FacebookPreview, _PureComponent);
31
-
32
- var _super = _createSuper(FacebookPreview);
33
-
34
- function FacebookPreview() {
35
- _classCallCheck(this, FacebookPreview);
36
-
37
- return _super.apply(this, arguments);
6
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
7
+ import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
8
+ const TITLE_LENGTH = 80;
9
+ const DESCRIPTION_LENGTH = 200;
10
+
11
+ const baseDomain = url => url && url.replace(/^[^/]+[/]*/, '') // strip leading protocol
12
+ .replace(/\/.*$/, ''); // strip everything after the domain
13
+
14
+
15
+ const facebookTitle = firstValid(shortEnough(TITLE_LENGTH), hardTruncation(TITLE_LENGTH));
16
+ const facebookDescription = firstValid(shortEnough(DESCRIPTION_LENGTH), hardTruncation(DESCRIPTION_LENGTH));
17
+ export class FacebookPreview extends PureComponent {
18
+ render() {
19
+ const {
20
+ url,
21
+ type,
22
+ title,
23
+ description,
24
+ image,
25
+ author
26
+ } = this.props;
27
+ return _jsx("div", {
28
+ className: `facebook-preview facebook-preview__${type}`,
29
+ children: _jsxs("div", {
30
+ className: "facebook-preview__content",
31
+ children: [_jsx("div", {
32
+ className: "facebook-preview__image",
33
+ children: image && _jsx("img", {
34
+ alt: "Facebook Preview Thumbnail",
35
+ src: image
36
+ })
37
+ }), _jsxs("div", {
38
+ className: "facebook-preview__body",
39
+ children: [_jsx("div", {
40
+ className: "facebook-preview__url",
41
+ children: compact([baseDomain(url), author]).join(' | ')
42
+ }), _jsx("div", {
43
+ className: "facebook-preview__title",
44
+ children: facebookTitle(title || '')
45
+ }), _jsx("div", {
46
+ className: "facebook-preview__description",
47
+ children: facebookDescription(stripHtmlTags(description))
48
+ })]
49
+ })]
50
+ })
51
+ });
38
52
  }
39
53
 
40
- _createClass(FacebookPreview, [{
41
- key: "render",
42
- value: function render() {
43
- var _this$props = this.props,
44
- url = _this$props.url,
45
- type = _this$props.type,
46
- title = _this$props.title,
47
- description = _this$props.description,
48
- image = _this$props.image,
49
- author = _this$props.author;
50
- return /*#__PURE__*/React.createElement("div", {
51
- className: "facebook-preview facebook-preview__".concat(type)
52
- }, /*#__PURE__*/React.createElement("div", {
53
- className: "facebook-preview__content"
54
- }, /*#__PURE__*/React.createElement("div", {
55
- className: "facebook-preview__image"
56
- }, image && /*#__PURE__*/React.createElement("img", {
57
- alt: "Facebook Preview Thumbnail",
58
- src: image
59
- })), /*#__PURE__*/React.createElement("div", {
60
- className: "facebook-preview__body"
61
- }, /*#__PURE__*/React.createElement("div", {
62
- className: "facebook-preview__url"
63
- }, compact([baseDomain(url), author]).join(' | ')), /*#__PURE__*/React.createElement("div", {
64
- className: "facebook-preview__title"
65
- }, facebookTitle(title || '')), /*#__PURE__*/React.createElement("div", {
66
- className: "facebook-preview__description"
67
- }, facebookDescription(stripHtmlTags(description))))));
68
- }
69
- }]);
70
-
71
- return FacebookPreview;
72
- }(PureComponent);
54
+ }
73
55
  FacebookPreview.propTypes = {
74
56
  url: PropTypes.string,
75
57
  type: PropTypes.string,
@@ -1,35 +1,16 @@
1
- /**
2
- * External dependencies
3
- */
4
1
  import { find } from 'lodash';
5
- export var shortEnough = function shortEnough(limit) {
6
- return function (title) {
7
- return title.length <= limit ? title : false;
8
- };
2
+ export const shortEnough = limit => title => title.length <= limit ? title : false;
3
+ export const truncatedAtSpace = (lower, upper) => fullTitle => {
4
+ const title = fullTitle.slice(0, upper);
5
+ const lastSpace = title.lastIndexOf(' ');
6
+ return lastSpace > lower && lastSpace < upper ? title.slice(0, lastSpace).concat('…') : false;
9
7
  };
10
- export var truncatedAtSpace = function truncatedAtSpace(lower, upper) {
11
- return function (fullTitle) {
12
- var title = fullTitle.slice(0, upper);
13
- var lastSpace = title.lastIndexOf(' ');
14
- return lastSpace > lower && lastSpace < upper ? title.slice(0, lastSpace).concat('…') : false;
15
- };
16
- };
17
- export var hardTruncation = function hardTruncation(limit) {
18
- return function (title) {
19
- return title.slice(0, limit).concat('…');
20
- };
21
- };
22
- export var firstValid = function firstValid() {
8
+ export const hardTruncation = limit => title => title.slice(0, limit).concat('…');
9
+ export const firstValid = function () {
23
10
  for (var _len = arguments.length, predicates = new Array(_len), _key = 0; _key < _len; _key++) {
24
11
  predicates[_key] = arguments[_key];
25
12
  }
26
13
 
27
- return function (a) {
28
- return find(predicates, function (p) {
29
- return false !== p(a);
30
- })(a);
31
- };
14
+ return a => find(predicates, p => false !== p(a))(a);
32
15
  };
33
- export var stripHtmlTags = function stripHtmlTags(description) {
34
- return description ? description.replace(/(<([^>]+)>)/gi, '') : '';
35
- };
16
+ export const stripHtmlTags = description => description ? description.replace(/(<([^>]+)>)/gi, '') : '';
@@ -1,41 +1,42 @@
1
- /**
2
- * External dependencies
3
- */
4
1
  import PropTypes from 'prop-types';
5
- import React from 'react';
6
2
  import { firstValid, hardTruncation, shortEnough, truncatedAtSpace, stripHtmlTags } from '../helpers';
7
- /**
8
- * Style dependencies
9
- */
10
-
11
3
  import './style.scss';
12
- var URL_LENGTH = 68;
13
- var TITLE_LENGTH = 63;
14
- var DESCRIPTION_LENGTH = 160;
4
+ import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
5
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
6
+ const URL_LENGTH = 68;
7
+ const TITLE_LENGTH = 63;
8
+ const DESCRIPTION_LENGTH = 160;
15
9
 
16
- var googleUrl = function googleUrl(url) {
17
- var breadcrumb = url.replace(/^[^/]+[/]*/, '').split('/').join(' › ');
18
- var truncateBreadcrumb = firstValid(shortEnough(URL_LENGTH), hardTruncation(URL_LENGTH));
10
+ const googleUrl = url => {
11
+ const breadcrumb = url.replace(/^[^/]+[/]*/, '').split('/').join(' › ');
12
+ const truncateBreadcrumb = firstValid(shortEnough(URL_LENGTH), hardTruncation(URL_LENGTH));
19
13
  return truncateBreadcrumb(breadcrumb);
20
14
  };
21
15
 
22
- var googleTitle = firstValid(shortEnough(TITLE_LENGTH), truncatedAtSpace(TITLE_LENGTH - 40, TITLE_LENGTH + 10), hardTruncation(TITLE_LENGTH));
23
- var googleDescription = firstValid(shortEnough(DESCRIPTION_LENGTH), truncatedAtSpace(DESCRIPTION_LENGTH - 80, DESCRIPTION_LENGTH + 10), hardTruncation(DESCRIPTION_LENGTH));
16
+ const googleTitle = firstValid(shortEnough(TITLE_LENGTH), truncatedAtSpace(TITLE_LENGTH - 40, TITLE_LENGTH + 10), hardTruncation(TITLE_LENGTH));
17
+ const googleDescription = firstValid(shortEnough(DESCRIPTION_LENGTH), truncatedAtSpace(DESCRIPTION_LENGTH - 80, DESCRIPTION_LENGTH + 10), hardTruncation(DESCRIPTION_LENGTH));
24
18
  export default function SearchPreview(_ref) {
25
- var description = _ref.description,
26
- title = _ref.title,
27
- url = _ref.url;
28
- return /*#__PURE__*/React.createElement("div", {
29
- className: "search-preview"
30
- }, /*#__PURE__*/React.createElement("div", {
31
- className: "search-preview__display"
32
- }, /*#__PURE__*/React.createElement("div", {
33
- className: "search-preview__url"
34
- }, googleUrl(url), " \u25BE"), /*#__PURE__*/React.createElement("div", {
35
- className: "search-preview__title"
36
- }, googleTitle(title)), /*#__PURE__*/React.createElement("div", {
37
- className: "search-preview__description"
38
- }, googleDescription(stripHtmlTags(description)))));
19
+ let {
20
+ description,
21
+ title,
22
+ url
23
+ } = _ref;
24
+ return _jsx("div", {
25
+ className: "search-preview",
26
+ children: _jsxs("div", {
27
+ className: "search-preview__display",
28
+ children: [_jsxs("div", {
29
+ className: "search-preview__url",
30
+ children: [googleUrl(url), " \u25BE"]
31
+ }), _jsx("div", {
32
+ className: "search-preview__title",
33
+ children: googleTitle(title)
34
+ }), _jsx("div", {
35
+ className: "search-preview__description",
36
+ children: googleDescription(stripHtmlTags(description))
37
+ })]
38
+ })
39
+ });
39
40
  }
40
41
  SearchPreview.propTypes = {
41
42
  title: PropTypes.string,
@@ -1,81 +1,37 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _createSuper from "@babel/runtime/helpers/createSuper";
5
-
6
- /**
7
- * External dependencies
8
- */
9
1
  import PropTypes from 'prop-types';
10
- import React, { PureComponent } from 'react';
11
- /**
12
- * Internal dependencies
13
- */
14
-
15
- import { firstValid, hardTruncation, shortEnough, stripHtmlTags } from '../helpers';
16
- /**
17
- * Style dependencies
18
- */
19
-
2
+ import { PureComponent } from 'react';
3
+ import { Tweet } from './tweet';
20
4
  import './style.scss';
21
- var DESCRIPTION_LENGTH = 200;
22
-
23
- var baseDomain = function baseDomain(url) {
24
- return url.replace(/^[^/]+[/]*/, '') // strip leading protocol
25
- .replace(/\/.*$/, '');
26
- }; // strip everything after the domain
27
-
28
-
29
- var twitterDescription = firstValid(shortEnough(DESCRIPTION_LENGTH), hardTruncation(DESCRIPTION_LENGTH));
30
- export var TwitterPreview = /*#__PURE__*/function (_PureComponent) {
31
- _inherits(TwitterPreview, _PureComponent);
32
-
33
- var _super = _createSuper(TwitterPreview);
34
-
35
- function TwitterPreview() {
36
- _classCallCheck(this, TwitterPreview);
37
-
38
- return _super.apply(this, arguments);
5
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
6
+ export class TwitterPreview extends PureComponent {
7
+ render() {
8
+ // Previous versions expected passed props to be the Twitter Card details for a single tweet,
9
+ // rather than an array of tweets. If the tweet array isn't passed, we can construct it from
10
+ // the old props.
11
+ const tweets = this.props.tweets || [{
12
+ text: '',
13
+ media: [],
14
+ card: { ...this.props,
15
+ type: 'large_image_summary' === this.props.type ? 'summary_large_image' : this.props.type
16
+ },
17
+ date: Date.now(),
18
+ name: 'Account Name',
19
+ profileImage: 'https://abs.twimg.com/sticky/default_profile_images/default_profile_bigger.png',
20
+ screenName: '@account'
21
+ }];
22
+ return _jsx("div", {
23
+ className: "twitter-preview",
24
+ children: tweets && tweets.map((tweet, index) => {
25
+ return _jsx(Tweet, {
26
+ isLast: index + 1 === tweets.length,
27
+ ...tweet
28
+ }, `twitter-preview__tweet-${index}`);
29
+ })
30
+ });
39
31
  }
40
32
 
41
- _createClass(TwitterPreview, [{
42
- key: "render",
43
- value: function render() {
44
- var _this$props = this.props,
45
- url = _this$props.url,
46
- title = _this$props.title,
47
- type = _this$props.type,
48
- description = _this$props.description,
49
- image = _this$props.image;
50
- var previewImageStyle = {
51
- backgroundImage: 'url(' + image + ')'
52
- };
53
- return /*#__PURE__*/React.createElement("div", {
54
- className: "twitter-preview"
55
- }, /*#__PURE__*/React.createElement("div", {
56
- className: "twitter-preview__".concat(type)
57
- }, image && /*#__PURE__*/React.createElement("div", {
58
- className: "twitter-preview__image",
59
- style: previewImageStyle
60
- }), /*#__PURE__*/React.createElement("div", {
61
- className: "twitter-preview__body"
62
- }, /*#__PURE__*/React.createElement("div", {
63
- className: "twitter-preview__title"
64
- }, title), /*#__PURE__*/React.createElement("div", {
65
- className: "twitter-preview__description"
66
- }, twitterDescription(stripHtmlTags(description))), /*#__PURE__*/React.createElement("div", {
67
- className: "twitter-preview__url"
68
- }, baseDomain(url || '')))));
69
- }
70
- }]);
71
-
72
- return TwitterPreview;
73
- }(PureComponent);
33
+ }
74
34
  TwitterPreview.propTypes = {
75
- url: PropTypes.string,
76
- title: PropTypes.string,
77
- type: PropTypes.string,
78
- description: PropTypes.string,
79
- image: PropTypes.string
35
+ tweets: PropTypes.array
80
36
  };
81
37
  export default TwitterPreview;