@automattic/social-previews 1.1.1 → 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,335 +1,314 @@
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
- */
1
+ import { SandBox } from '@wordpress/components';
2
+ import { __ as alias__ } from '@wordpress/i18n';
3
+ const __ = alias__;
9
4
  import classnames from 'classnames';
10
- import PropTypes from 'prop-types';
11
- import React, { PureComponent } from 'react';
12
5
  import moment from 'moment';
13
- import { __ as alias__ } from '@wordpress/i18n';
14
- var __ = alias__;
15
- import { SandBox } from '@wordpress/components';
16
- /**
17
- * Internal dependencies
18
- */
19
-
6
+ import PropTypes from 'prop-types';
7
+ import { PureComponent } from 'react';
20
8
  import { firstValid, hardTruncation, shortEnough, stripHtmlTags } from '../helpers';
21
- /**
22
- * Style dependencies
23
- */
24
-
25
9
  import './style.scss';
26
- var DESCRIPTION_LENGTH = 200;
10
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
12
+ const DESCRIPTION_LENGTH = 200;
13
+
14
+ const baseDomain = url => url.replace(/^[^/]+[/]*(www\.)?/, '') // Strip leading protocol and "www.".
15
+ .replace(/\/.*$/, ''); // Strip everything after the domain.
16
+
17
+
18
+ const twitterDescription = firstValid(shortEnough(DESCRIPTION_LENGTH), hardTruncation(DESCRIPTION_LENGTH));
19
+ export class Tweet extends PureComponent {
20
+ /**
21
+ * Renders the sidebar beside the tweet.
22
+ *
23
+ * @param {string} profileImage URL of the Twitter profile image.
24
+ * @param {boolean} isLast Whether or not this is the last tweet in the in a thread.
25
+ * @returns {import('react').Element} The sidebar.
26
+ */
27
+ renderSidebar(profileImage, isLast) {
28
+ return _jsxs("div", {
29
+ className: "twitter-preview__sidebar",
30
+ children: [_jsx("div", {
31
+ className: "twitter-preview__profile-image",
32
+ children: _jsx("img", {
33
+ alt: __('Twitter profile image'),
34
+ src: profileImage
35
+ })
36
+ }), !isLast && _jsx("div", {
37
+ className: "twitter-preview__connector"
38
+ })]
39
+ });
40
+ }
41
+ /**
42
+ * Renders the header section of a single tweet.
43
+ *
44
+ * @param {string} name The display name of the Twitter account.
45
+ * @param {string} screenName The at-name of the Twitter account.
46
+ * @param {Date} date The date to be shown for this preview.
47
+ * @returns {import('react').Element} The header.
48
+ */
49
+
50
+
51
+ renderHeader(name, screenName, date) {
52
+ return _jsxs("div", {
53
+ className: "twitter-preview__header",
54
+ children: [_jsx("span", {
55
+ className: "twitter-preview__name",
56
+ children: name
57
+ }), _jsx("span", {
58
+ className: "twitter-preview__screen-name",
59
+ children: screenName
60
+ }), _jsx("span", {
61
+ className: "twitter-preview__date",
62
+ children: moment(date).format('MMM D')
63
+ })]
64
+ });
65
+ }
66
+ /**
67
+ * Renders the text section of the tweet.
68
+ *
69
+ * @param {string} text The text of the tweet.
70
+ * @param {Array} urls Optional. An array of URLs that are in the text.
71
+ * @param {object} card Optional. The card data for this tweet.
72
+ * @returns {import('react').Element} The text section.
73
+ */
27
74
 
28
- var baseDomain = function baseDomain(url) {
29
- return url.replace(/^[^/]+[/]*(www\.)?/, '') // Strip leading protocol and "www.".
30
- .replace(/\/.*$/, '');
31
- }; // Strip everything after the domain.
32
75
 
76
+ renderText(text) {
77
+ let urls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
78
+ let card = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
79
+ // If the text ends with the card URL, remove it.
80
+ const cardUrl = card.url || '';
81
+ const deCardedText = text.endsWith(cardUrl) ? text.substr(0, text.lastIndexOf(cardUrl)) : text;
33
82
 
34
- var twitterDescription = firstValid(shortEnough(DESCRIPTION_LENGTH), hardTruncation(DESCRIPTION_LENGTH));
35
- export var Tweet = /*#__PURE__*/function (_PureComponent) {
36
- _inherits(Tweet, _PureComponent);
83
+ const __html = urls.reduce((html, url) => html.replace(new RegExp('\\(' + url + '\\)', 'g'), `(<a href="${url}">${url}</a>)`), stripHtmlTags(deCardedText).replace(new RegExp('\\n', 'g'), '<br/>')); // We can enable dangerouslySetInnerHTML here, since the text we're using is stripped
84
+ // of all HTML tags, then only has safe tags added in createTweetMarkup().
37
85
 
38
- var _super = _createSuper(Tweet);
86
+ /* eslint-disable react/no-danger */
39
87
 
40
- function Tweet() {
41
- _classCallCheck(this, Tweet);
42
88
 
43
- return _super.apply(this, arguments);
89
+ return _jsx("div", {
90
+ className: "twitter-preview__text",
91
+ dangerouslySetInnerHTML: {
92
+ __html
93
+ }
94
+ });
95
+ /* eslint-enabled react/no-danger */
44
96
  }
97
+ /**
98
+ * Renders the media section of the tweet. It will render up to four individual images, or a single
99
+ * GIF, or a single video. Any media beyond these limits will be discarded.
100
+ *
101
+ * @param {Array} media The media to include in this tweet.
102
+ * @returns {import('react').Element} The media section.
103
+ */
45
104
 
46
- _createClass(Tweet, [{
47
- key: "renderSidebar",
48
- value:
49
- /**
50
- * Renders the sidebar beside the tweet.
51
- *
52
- * @param {string} profileImage URL of the Twitter profile image.
53
- * @param {boolean} isLast Whether or not this is the last tweet in the in a thread.
54
- *
55
- * @returns {React.Element} The sidebar.
56
- */
57
- function renderSidebar(profileImage, isLast) {
58
- return /*#__PURE__*/React.createElement("div", {
59
- className: "twitter-preview__sidebar"
60
- }, /*#__PURE__*/React.createElement("div", {
61
- className: "twitter-preview__profile-image"
62
- }, /*#__PURE__*/React.createElement("img", {
63
- alt: __('Twitter profile image'),
64
- src: profileImage
65
- })), !isLast && /*#__PURE__*/React.createElement("div", {
66
- className: "twitter-preview__connector"
67
- }));
68
- }
69
- /**
70
- * Renders the header section of a single tweet.
71
- *
72
- * @param {string} name The display name of the Twitter account.
73
- * @param {string} screenName The at-name of the Twitter account.
74
- * @param {Date} date The date to be shown for this preview.
75
- *
76
- * @returns {React.Element} The header.
77
- */
78
-
79
- }, {
80
- key: "renderHeader",
81
- value: function renderHeader(name, screenName, date) {
82
- return /*#__PURE__*/React.createElement("div", {
83
- className: "twitter-preview__header"
84
- }, /*#__PURE__*/React.createElement("span", {
85
- className: "twitter-preview__name"
86
- }, name), /*#__PURE__*/React.createElement("span", {
87
- className: "twitter-preview__screen-name"
88
- }, screenName), /*#__PURE__*/React.createElement("span", {
89
- className: "twitter-preview__date"
90
- }, moment(date).format('MMM D')));
91
- }
92
- /**
93
- * Renders the text section of the tweet.
94
- *
95
- * @param {string} text The text of the tweet.
96
- * @param {Array} urls Optional. An array of URLs that are in the text.
97
- * @param {object} card Optional. The card data for this tweet.
98
- *
99
- * @returns {React.Element} The text section.
100
- */
101
-
102
- }, {
103
- key: "renderText",
104
- value: function renderText(text) {
105
- var urls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
106
- var card = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
107
- // If the text ends with the card URL, remove it.
108
- var cardUrl = card.url || '';
109
- var deCardedText = text.endsWith(cardUrl) ? text.substr(0, text.lastIndexOf(cardUrl)) : text;
110
-
111
- var __html = urls.reduce(function (html, url) {
112
- return html.replace(new RegExp('\\(' + url + '\\)', 'g'), "(<a href=\"".concat(url, "\">").concat(url, "</a>)"));
113
- }, stripHtmlTags(deCardedText).replace(new RegExp('\\n', 'g'), '<br/>')); // We can enable dangerouslySetInnerHTML here, since the text we're using is stripped
114
- // of all HTML tags, then only has safe tags added in createTweetMarkup().
115
-
116
- /* eslint-disable react/no-danger */
117
-
118
-
119
- return /*#__PURE__*/React.createElement("div", {
120
- className: "twitter-preview__text",
121
- dangerouslySetInnerHTML: {
122
- __html: __html
123
- }
124
- });
125
- /* eslint-enabled react/no-danger */
126
- }
127
- /**
128
- * Renders the media section of the tweet. It will render up to four individual images, or a single
129
- * GIF, or a single video. Any media beyond these limits will be discarded.
130
- *
131
- * @param {Array} media The media to include in this tweet.
132
- *
133
- * @returns {React.Element} The media section.
134
- */
135
-
136
- }, {
137
- key: "renderMedia",
138
- value: function renderMedia(media) {
139
- if (!media) {
140
- return;
141
- } // Ensure we're only trying to show valid media, and the correct quantity.
142
-
143
-
144
- var filteredMedia = media // Only image/ and video/ mime types are supported.
145
- .filter(function (mediaItem) {
146
- return mediaItem.type.startsWith('image/') || mediaItem.type.startsWith('video/');
147
- }).filter(function (mediaItem, idx, array) {
148
- // We'll always keep the first item.
149
- if (0 === idx) {
150
- return true;
151
- } // If the first item was a video or GIF, discard all subsequent items.
152
-
153
-
154
- if (array[0].type.startsWith('video/') || 'image/gif' === array[0].type) {
155
- return false;
156
- } // The first item wasn't a video or GIF, so discard all subsequent videos and GIFs.
157
-
158
-
159
- if (mediaItem.type.startsWith('video/') || 'image/gif' === mediaItem.type) {
160
- return false;
161
- }
162
105
 
106
+ renderMedia(media) {
107
+ if (!media) {
108
+ return;
109
+ } // Ensure we're only trying to show valid media, and the correct quantity.
110
+
111
+
112
+ const filteredMedia = media // Only image/ and video/ mime types are supported.
113
+ .filter(mediaItem => mediaItem.type.startsWith('image/') || mediaItem.type.startsWith('video/')).filter((mediaItem, idx, array) => {
114
+ // We'll always keep the first item.
115
+ if (0 === idx) {
163
116
  return true;
164
- }) // We only want the first four items of the array, at most.
165
- .slice(0, 4);
166
- var isVideo = filteredMedia.length > 0 && filteredMedia[0].type.startsWith('video/');
167
- var mediaClasses = classnames(['twitter-preview__media', 'twitter-preview__media-children-' + filteredMedia.length]);
117
+ } // If the first item was a video or GIF, discard all subsequent items.
118
+
119
+
120
+ if (array[0].type.startsWith('video/') || 'image/gif' === array[0].type) {
121
+ return false;
122
+ } // The first item wasn't a video or GIF, so discard all subsequent videos and GIFs.
123
+
168
124
 
169
- if (0 === filteredMedia.length) {
170
- return;
125
+ if (mediaItem.type.startsWith('video/') || 'image/gif' === mediaItem.type) {
126
+ return false;
171
127
  }
172
128
 
173
- return /*#__PURE__*/React.createElement("div", {
174
- className: mediaClasses
175
- },
129
+ return true;
130
+ }) // We only want the first four items of the array, at most.
131
+ .slice(0, 4);
132
+ const isVideo = filteredMedia.length > 0 && filteredMedia[0].type.startsWith('video/');
133
+ const mediaClasses = classnames(['twitter-preview__media', 'twitter-preview__media-children-' + filteredMedia.length]);
134
+
135
+ if (0 === filteredMedia.length) {
136
+ return;
137
+ }
138
+
139
+ return _jsxs("div", {
140
+ className: mediaClasses,
141
+ children: [
176
142
  /* eslint-disable jsx-a11y/media-has-caption */
177
- isVideo && filteredMedia.map(function (mediaItem, index) {
178
- return /*#__PURE__*/React.createElement("video", {
179
- key: "twitter-preview__media-item-".concat(index),
180
- controls: true
181
- }, /*#__PURE__*/React.createElement("source", {
143
+ isVideo && filteredMedia.map((mediaItem, index) => _jsxs("video", {
144
+ controls: true,
145
+ children: [_jsx("source", {
182
146
  src: mediaItem.url,
183
147
  type: mediaItem.type
184
- }), ' ');
185
- })
148
+ }), ' ']
149
+ }, `twitter-preview__media-item-${index}`))
186
150
  /* eslint-disable jsx-a11y/media-has-caption */
187
- , !isVideo && filteredMedia.map(function (mediaItem, index) {
188
- return /*#__PURE__*/React.createElement("img", {
189
- key: "twitter-preview__media-item-".concat(index),
190
- alt: mediaItem.alt,
191
- src: mediaItem.url
192
- });
193
- }));
151
+ , !isVideo && filteredMedia.map((mediaItem, index) => _jsx("img", {
152
+ alt: mediaItem.alt,
153
+ src: mediaItem.url
154
+ }, `twitter-preview__media-item-${index}`))]
155
+ });
156
+ }
157
+ /**
158
+ * Given a tweet URL, renders it as a quoted tweet.
159
+ *
160
+ * @param {string} tweet The tweet URL.
161
+ * @returns {import('react').Element} The quoted tweet.
162
+ */
163
+
164
+
165
+ renderQuoteTweet(tweet) {
166
+ if (!tweet) {
167
+ return;
194
168
  }
195
- /**
196
- * Given a tweet URL, renders it as a quoted tweet.
197
- *
198
- * @param {string} tweet The tweet URL.
199
- *
200
- * @returns {React.Element} The quoted tweet.
201
- */
202
-
203
- }, {
204
- key: "renderQuoteTweet",
205
- value: function renderQuoteTweet(tweet) {
206
- if (!tweet) {
207
- return;
208
- }
209
169
 
210
- return /*#__PURE__*/React.createElement("div", {
211
- className: "twitter-preview__quote-tweet"
212
- }, /*#__PURE__*/React.createElement(SandBox, {
213
- html: "<blockquote class=\"twitter-tweet\" data-conversation=\"none\" data-dnt=\"true\"><a href=\"".concat(tweet, "\"></a></blockquote>"),
170
+ return _jsxs("div", {
171
+ className: "twitter-preview__quote-tweet",
172
+ children: [_jsx(SandBox, {
173
+ html: `<blockquote class="twitter-tweet" data-conversation="none" data-dnt="true"><a href="${tweet}"></a></blockquote>`,
214
174
  scripts: ['https://platform.twitter.com/widgets.js'],
215
175
  title: "Embedded tweet",
216
176
  onFocus: this.hideOverlay
217
- }), /*#__PURE__*/React.createElement("div", {
177
+ }), _jsx("div", {
218
178
  className: "twitter-preview__quote-tweet-overlay"
219
- }));
220
- }
221
- /**
222
- * Given card data, renders the Twitter-style card.
223
- *
224
- * @param {object} card The card data.
225
- *
226
- * @returns {React.Element} The card tweet.
227
- */
228
-
229
- }, {
230
- key: "renderCard",
231
- value: function renderCard(card) {
232
- if (!card) {
233
- return;
234
- }
179
+ })]
180
+ });
181
+ }
182
+ /**
183
+ * Given card data, renders the Twitter-style card.
184
+ *
185
+ * @param {object} card The card data.
186
+ * @returns {import('react').Element} The card tweet.
187
+ */
235
188
 
236
- var description = card.description,
237
- image = card.image,
238
- title = card.title,
239
- type = card.type,
240
- url = card.url;
241
- var cardClassNames = classnames("twitter-preview__card-".concat(type), {
242
- 'twitter-preview__card-has-image': !!image
243
- });
244
- return /*#__PURE__*/React.createElement("div", {
245
- className: "twitter-preview__card"
246
- }, /*#__PURE__*/React.createElement("div", {
247
- className: cardClassNames
248
- }, image && /*#__PURE__*/React.createElement("img", {
249
- className: "twitter-preview__card-image",
250
- src: image,
251
- alt: ""
252
- }), /*#__PURE__*/React.createElement("div", {
253
- className: "twitter-preview__card-body"
254
- }, /*#__PURE__*/React.createElement("div", {
255
- className: "twitter-preview__card-title"
256
- }, title), /*#__PURE__*/React.createElement("div", {
257
- className: "twitter-preview__card-description"
258
- }, twitterDescription(stripHtmlTags(description))), /*#__PURE__*/React.createElement("div", {
259
- className: "twitter-preview__card-url"
260
- }, /*#__PURE__*/React.createElement("svg", {
261
- viewBox: "0 0 24 24"
262
- }, /*#__PURE__*/React.createElement("g", null, /*#__PURE__*/React.createElement("path", {
263
- d: "M11.96 14.945c-.067 0-.136-.01-.203-.027-1.13-.318-2.097-.986-2.795-1.932-.832-1.125-1.176-2.508-.968-3.893s.942-2.605 2.068-3.438l3.53-2.608c2.322-1.716 5.61-1.224 7.33 1.1.83 1.127 1.175 2.51.967 3.895s-.943 2.605-2.07 3.438l-1.48 1.094c-.333.246-.804.175-1.05-.158-.246-.334-.176-.804.158-1.05l1.48-1.095c.803-.592 1.327-1.463 1.476-2.45.148-.988-.098-1.975-.69-2.778-1.225-1.656-3.572-2.01-5.23-.784l-3.53 2.608c-.802.593-1.326 1.464-1.475 2.45-.15.99.097 1.975.69 2.778.498.675 1.187 1.15 1.992 1.377.4.114.633.528.52.928-.092.33-.394.547-.722.547z"
264
- }), /*#__PURE__*/React.createElement("path", {
265
- d: "M7.27 22.054c-1.61 0-3.197-.735-4.225-2.125-.832-1.127-1.176-2.51-.968-3.894s.943-2.605 2.07-3.438l1.478-1.094c.334-.245.805-.175 1.05.158s.177.804-.157 1.05l-1.48 1.095c-.803.593-1.326 1.464-1.475 2.45-.148.99.097 1.975.69 2.778 1.225 1.657 3.57 2.01 5.23.785l3.528-2.608c1.658-1.225 2.01-3.57.785-5.23-.498-.674-1.187-1.15-1.992-1.376-.4-.113-.633-.527-.52-.927.112-.4.528-.63.926-.522 1.13.318 2.096.986 2.794 1.932 1.717 2.324 1.224 5.612-1.1 7.33l-3.53 2.608c-.933.693-2.023 1.026-3.105 1.026z"
266
- }))), baseDomain(url || '')))));
267
- }
268
- /**
269
- * Renders the footer section of a single tweet, showing (non-functioning) reply, retweet, etc buttons.
270
- *
271
- * @returns {React.Element} The footer.
272
- */
273
-
274
- }, {
275
- key: "renderFooter",
276
- value: function renderFooter() {
277
- return /*#__PURE__*/React.createElement("div", {
278
- className: "twitter-preview__footer"
279
- }, /*#__PURE__*/React.createElement("span", {
280
- className: "twitter-preview__icon-replies"
281
- }, /*#__PURE__*/React.createElement("svg", {
282
- viewBox: "0 0 24 24"
283
- }, /*#__PURE__*/React.createElement("path", {
284
- d: "M14.046 2.242l-4.148-.01h-.002c-4.374 0-7.8 3.427-7.8 7.802 0 4.098 3.186 7.206 7.465 7.37v3.828c0 .108.044.286.12.403.142.225.384.347.632.347.138 0 .277-.038.402-.118.264-.168 6.473-4.14 8.088-5.506 1.902-1.61 3.04-3.97 3.043-6.312v-.017c-.006-4.367-3.43-7.787-7.8-7.788zm3.787 12.972c-1.134.96-4.862 3.405-6.772 4.643V16.67c0-.414-.335-.75-.75-.75h-.396c-3.66 0-6.318-2.476-6.318-5.886 0-3.534 2.768-6.302 6.3-6.302l4.147.01h.002c3.532 0 6.3 2.766 6.302 6.296-.003 1.91-.942 3.844-2.514 5.176z"
285
- }))), /*#__PURE__*/React.createElement("span", {
286
- className: "twitter-preview__icon-retweets"
287
- }, /*#__PURE__*/React.createElement("svg", {
288
- viewBox: "0 0 24 24"
289
- }, /*#__PURE__*/React.createElement("path", {
290
- d: "M23.77 15.67c-.292-.293-.767-.293-1.06 0l-2.22 2.22V7.65c0-2.068-1.683-3.75-3.75-3.75h-5.85c-.414 0-.75.336-.75.75s.336.75.75.75h5.85c1.24 0 2.25 1.01 2.25 2.25v10.24l-2.22-2.22c-.293-.293-.768-.293-1.06 0s-.294.768 0 1.06l3.5 3.5c.145.147.337.22.53.22s.383-.072.53-.22l3.5-3.5c.294-.292.294-.767 0-1.06zm-10.66 3.28H7.26c-1.24 0-2.25-1.01-2.25-2.25V6.46l2.22 2.22c.148.147.34.22.532.22s.384-.073.53-.22c.293-.293.293-.768 0-1.06l-3.5-3.5c-.293-.294-.768-.294-1.06 0l-3.5 3.5c-.294.292-.294.767 0 1.06s.767.293 1.06 0l2.22-2.22V16.7c0 2.068 1.683 3.75 3.75 3.75h5.85c.414 0 .75-.336.75-.75s-.337-.75-.75-.75z"
291
- }))), /*#__PURE__*/React.createElement("span", {
292
- className: "twitter-preview__icon-likes"
293
- }, /*#__PURE__*/React.createElement("svg", {
294
- viewBox: "0 0 24 24"
295
- }, /*#__PURE__*/React.createElement("path", {
296
- d: "M12 21.638h-.014C9.403 21.59 1.95 14.856 1.95 8.478c0-3.064 2.525-5.754 5.403-5.754 2.29 0 3.83 1.58 4.646 2.73.814-1.148 2.354-2.73 4.645-2.73 2.88 0 5.404 2.69 5.404 5.755 0 6.376-7.454 13.11-10.037 13.157H12zM7.354 4.225c-2.08 0-3.903 1.988-3.903 4.255 0 5.74 7.034 11.596 8.55 11.658 1.518-.062 8.55-5.917 8.55-11.658 0-2.267-1.823-4.255-3.903-4.255-2.528 0-3.94 2.936-3.952 2.965-.23.562-1.156.562-1.387 0-.014-.03-1.425-2.965-3.954-2.965z"
297
- }))), /*#__PURE__*/React.createElement("span", {
298
- className: "twitter-preview__icon-share"
299
- }, /*#__PURE__*/React.createElement("svg", {
300
- viewBox: "0 0 24 24"
301
- }, /*#__PURE__*/React.createElement("path", {
302
- d: "M17.53 7.47l-5-5c-.293-.293-.768-.293-1.06 0l-5 5c-.294.293-.294.768 0 1.06s.767.294 1.06 0l3.72-3.72V15c0 .414.336.75.75.75s.75-.336.75-.75V4.81l3.72 3.72c.146.147.338.22.53.22s.384-.072.53-.22c.293-.293.293-.767 0-1.06z"
303
- }), /*#__PURE__*/React.createElement("path", {
304
- d: "M19.708 21.944H4.292C3.028 21.944 2 20.916 2 19.652V14c0-.414.336-.75.75-.75s.75.336.75.75v5.652c0 .437.355.792.792.792h15.416c.437 0 .792-.355.792-.792V14c0-.414.336-.75.75-.75s.75.336.75.75v5.652c0 1.264-1.028 2.292-2.292 2.292z"
305
- }))));
306
- }
307
- }, {
308
- key: "render",
309
- value: function render() {
310
- var _this$props = this.props,
311
- isLast = _this$props.isLast,
312
- profileImage = _this$props.profileImage,
313
- name = _this$props.name,
314
- screenName = _this$props.screenName,
315
- date = _this$props.date,
316
- text = _this$props.text,
317
- media = _this$props.media,
318
- tweet = _this$props.tweet,
319
- urls = _this$props.urls,
320
- card = _this$props.card;
321
- return /*#__PURE__*/React.createElement("div", {
322
- className: "twitter-preview__container"
323
- }, this.renderSidebar(profileImage, isLast), /*#__PURE__*/React.createElement("div", {
324
- className: "twitter-preview__main"
325
- }, this.renderHeader(name, screenName, date), /*#__PURE__*/React.createElement("div", {
326
- className: "twitter-preview__content"
327
- }, this.renderText(text, urls, card), this.renderMedia(media), this.renderQuoteTweet(tweet), this.renderCard(card)), this.renderFooter()));
189
+
190
+ renderCard(card) {
191
+ if (!card) {
192
+ return;
328
193
  }
329
- }]);
330
194
 
331
- return Tweet;
332
- }(PureComponent);
195
+ const {
196
+ description,
197
+ image,
198
+ title,
199
+ type,
200
+ url
201
+ } = card;
202
+ const cardClassNames = classnames(`twitter-preview__card-${type}`, {
203
+ 'twitter-preview__card-has-image': !!image
204
+ });
205
+ return _jsx("div", {
206
+ className: "twitter-preview__card",
207
+ children: _jsxs("div", {
208
+ className: cardClassNames,
209
+ children: [image && _jsx("img", {
210
+ className: "twitter-preview__card-image",
211
+ src: image,
212
+ alt: ""
213
+ }), _jsxs("div", {
214
+ className: "twitter-preview__card-body",
215
+ children: [_jsx("div", {
216
+ className: "twitter-preview__card-title",
217
+ children: title
218
+ }), _jsx("div", {
219
+ className: "twitter-preview__card-description",
220
+ children: twitterDescription(stripHtmlTags(description))
221
+ }), _jsxs("div", {
222
+ className: "twitter-preview__card-url",
223
+ children: [_jsx("svg", {
224
+ viewBox: "0 0 24 24",
225
+ children: _jsxs("g", {
226
+ children: [_jsx("path", {
227
+ d: "M11.96 14.945c-.067 0-.136-.01-.203-.027-1.13-.318-2.097-.986-2.795-1.932-.832-1.125-1.176-2.508-.968-3.893s.942-2.605 2.068-3.438l3.53-2.608c2.322-1.716 5.61-1.224 7.33 1.1.83 1.127 1.175 2.51.967 3.895s-.943 2.605-2.07 3.438l-1.48 1.094c-.333.246-.804.175-1.05-.158-.246-.334-.176-.804.158-1.05l1.48-1.095c.803-.592 1.327-1.463 1.476-2.45.148-.988-.098-1.975-.69-2.778-1.225-1.656-3.572-2.01-5.23-.784l-3.53 2.608c-.802.593-1.326 1.464-1.475 2.45-.15.99.097 1.975.69 2.778.498.675 1.187 1.15 1.992 1.377.4.114.633.528.52.928-.092.33-.394.547-.722.547z"
228
+ }), _jsx("path", {
229
+ d: "M7.27 22.054c-1.61 0-3.197-.735-4.225-2.125-.832-1.127-1.176-2.51-.968-3.894s.943-2.605 2.07-3.438l1.478-1.094c.334-.245.805-.175 1.05.158s.177.804-.157 1.05l-1.48 1.095c-.803.593-1.326 1.464-1.475 2.45-.148.99.097 1.975.69 2.778 1.225 1.657 3.57 2.01 5.23.785l3.528-2.608c1.658-1.225 2.01-3.57.785-5.23-.498-.674-1.187-1.15-1.992-1.376-.4-.113-.633-.527-.52-.927.112-.4.528-.63.926-.522 1.13.318 2.096.986 2.794 1.932 1.717 2.324 1.224 5.612-1.1 7.33l-3.53 2.608c-.933.693-2.023 1.026-3.105 1.026z"
230
+ })]
231
+ })
232
+ }), baseDomain(url || '')]
233
+ })]
234
+ })]
235
+ })
236
+ });
237
+ }
238
+ /**
239
+ * Renders the footer section of a single tweet, showing (non-functioning) reply, retweet, etc buttons.
240
+ *
241
+ * @returns {import('react').Element} The footer.
242
+ */
243
+
244
+
245
+ renderFooter() {
246
+ return _jsxs("div", {
247
+ className: "twitter-preview__footer",
248
+ children: [_jsx("span", {
249
+ className: "twitter-preview__icon-replies",
250
+ children: _jsx("svg", {
251
+ viewBox: "0 0 24 24",
252
+ children: _jsx("path", {
253
+ d: "M14.046 2.242l-4.148-.01h-.002c-4.374 0-7.8 3.427-7.8 7.802 0 4.098 3.186 7.206 7.465 7.37v3.828c0 .108.044.286.12.403.142.225.384.347.632.347.138 0 .277-.038.402-.118.264-.168 6.473-4.14 8.088-5.506 1.902-1.61 3.04-3.97 3.043-6.312v-.017c-.006-4.367-3.43-7.787-7.8-7.788zm3.787 12.972c-1.134.96-4.862 3.405-6.772 4.643V16.67c0-.414-.335-.75-.75-.75h-.396c-3.66 0-6.318-2.476-6.318-5.886 0-3.534 2.768-6.302 6.3-6.302l4.147.01h.002c3.532 0 6.3 2.766 6.302 6.296-.003 1.91-.942 3.844-2.514 5.176z"
254
+ })
255
+ })
256
+ }), _jsx("span", {
257
+ className: "twitter-preview__icon-retweets",
258
+ children: _jsx("svg", {
259
+ viewBox: "0 0 24 24",
260
+ children: _jsx("path", {
261
+ d: "M23.77 15.67c-.292-.293-.767-.293-1.06 0l-2.22 2.22V7.65c0-2.068-1.683-3.75-3.75-3.75h-5.85c-.414 0-.75.336-.75.75s.336.75.75.75h5.85c1.24 0 2.25 1.01 2.25 2.25v10.24l-2.22-2.22c-.293-.293-.768-.293-1.06 0s-.294.768 0 1.06l3.5 3.5c.145.147.337.22.53.22s.383-.072.53-.22l3.5-3.5c.294-.292.294-.767 0-1.06zm-10.66 3.28H7.26c-1.24 0-2.25-1.01-2.25-2.25V6.46l2.22 2.22c.148.147.34.22.532.22s.384-.073.53-.22c.293-.293.293-.768 0-1.06l-3.5-3.5c-.293-.294-.768-.294-1.06 0l-3.5 3.5c-.294.292-.294.767 0 1.06s.767.293 1.06 0l2.22-2.22V16.7c0 2.068 1.683 3.75 3.75 3.75h5.85c.414 0 .75-.336.75-.75s-.337-.75-.75-.75z"
262
+ })
263
+ })
264
+ }), _jsx("span", {
265
+ className: "twitter-preview__icon-likes",
266
+ children: _jsx("svg", {
267
+ viewBox: "0 0 24 24",
268
+ children: _jsx("path", {
269
+ d: "M12 21.638h-.014C9.403 21.59 1.95 14.856 1.95 8.478c0-3.064 2.525-5.754 5.403-5.754 2.29 0 3.83 1.58 4.646 2.73.814-1.148 2.354-2.73 4.645-2.73 2.88 0 5.404 2.69 5.404 5.755 0 6.376-7.454 13.11-10.037 13.157H12zM7.354 4.225c-2.08 0-3.903 1.988-3.903 4.255 0 5.74 7.034 11.596 8.55 11.658 1.518-.062 8.55-5.917 8.55-11.658 0-2.267-1.823-4.255-3.903-4.255-2.528 0-3.94 2.936-3.952 2.965-.23.562-1.156.562-1.387 0-.014-.03-1.425-2.965-3.954-2.965z"
270
+ })
271
+ })
272
+ }), _jsx("span", {
273
+ className: "twitter-preview__icon-share",
274
+ children: _jsxs("svg", {
275
+ viewBox: "0 0 24 24",
276
+ children: [_jsx("path", {
277
+ d: "M17.53 7.47l-5-5c-.293-.293-.768-.293-1.06 0l-5 5c-.294.293-.294.768 0 1.06s.767.294 1.06 0l3.72-3.72V15c0 .414.336.75.75.75s.75-.336.75-.75V4.81l3.72 3.72c.146.147.338.22.53.22s.384-.072.53-.22c.293-.293.293-.767 0-1.06z"
278
+ }), _jsx("path", {
279
+ d: "M19.708 21.944H4.292C3.028 21.944 2 20.916 2 19.652V14c0-.414.336-.75.75-.75s.75.336.75.75v5.652c0 .437.355.792.792.792h15.416c.437 0 .792-.355.792-.792V14c0-.414.336-.75.75-.75s.75.336.75.75v5.652c0 1.264-1.028 2.292-2.292 2.292z"
280
+ })]
281
+ })
282
+ })]
283
+ });
284
+ }
285
+
286
+ render() {
287
+ const {
288
+ isLast,
289
+ profileImage,
290
+ name,
291
+ screenName,
292
+ date,
293
+ text,
294
+ media,
295
+ tweet,
296
+ urls,
297
+ card
298
+ } = this.props;
299
+ return _jsxs("div", {
300
+ className: "twitter-preview__container",
301
+ children: [this.renderSidebar(profileImage, isLast), _jsxs("div", {
302
+ className: "twitter-preview__main",
303
+ children: [this.renderHeader(name, screenName, date), _jsxs("div", {
304
+ className: "twitter-preview__content",
305
+ children: [this.renderText(text, urls, card), this.renderMedia(media), this.renderQuoteTweet(tweet), this.renderCard(card)]
306
+ }), this.renderFooter()]
307
+ })]
308
+ });
309
+ }
310
+
311
+ }
333
312
  Tweet.propTypes = {
334
313
  tweets: PropTypes.array,
335
314
  isLast: PropTypes.bool,