@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.
- package/CHANGELOG.md +4 -0
- package/dist/cjs/facebook-preview/index.js +50 -71
- package/dist/cjs/helpers.js +10 -29
- package/dist/cjs/index.js +7 -7
- package/dist/cjs/search-preview/index.js +30 -30
- package/dist/cjs/twitter-preview/index.js +29 -63
- package/dist/cjs/twitter-preview/tweet.js +283 -299
- package/dist/esm/facebook-preview/index.js +49 -67
- package/dist/esm/helpers.js +9 -28
- package/dist/esm/search-preview/index.js +31 -30
- package/dist/esm/twitter-preview/index.js +28 -58
- package/dist/esm/twitter-preview/tweet.js +281 -302
- package/package.json +58 -61
- package/src/facebook-preview/index.jsx +2 -9
- package/src/helpers.js +5 -7
- package/src/search-preview/index.jsx +0 -8
- package/src/twitter-preview/index.jsx +1 -11
- package/src/twitter-preview/tweet.jsx +13 -39
- package/LICENSE.md +0 -257
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
|
|
5
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
4
|
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -9,340 +7,326 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
9
7
|
});
|
|
10
8
|
exports.default = exports.Tweet = void 0;
|
|
11
9
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
10
|
+
var _components = require("@wordpress/components");
|
|
17
11
|
|
|
18
|
-
var
|
|
12
|
+
var _i18n = require("@wordpress/i18n");
|
|
19
13
|
|
|
20
14
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
21
15
|
|
|
22
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
23
|
-
|
|
24
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
25
|
-
|
|
26
16
|
var _moment = _interopRequireDefault(require("moment"));
|
|
27
17
|
|
|
28
|
-
var
|
|
18
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
29
19
|
|
|
30
|
-
var
|
|
20
|
+
var _react = require("react");
|
|
31
21
|
|
|
32
22
|
var _helpers = require("../helpers");
|
|
33
23
|
|
|
34
24
|
require("./style.scss");
|
|
35
25
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
27
|
+
|
|
28
|
+
const __ = _i18n.__;
|
|
29
|
+
const DESCRIPTION_LENGTH = 200;
|
|
30
|
+
|
|
31
|
+
const baseDomain = url => url.replace(/^[^/]+[/]*(www\.)?/, '') // Strip leading protocol and "www.".
|
|
32
|
+
.replace(/\/.*$/, ''); // Strip everything after the domain.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const twitterDescription = (0, _helpers.firstValid)((0, _helpers.shortEnough)(DESCRIPTION_LENGTH), (0, _helpers.hardTruncation)(DESCRIPTION_LENGTH));
|
|
36
|
+
|
|
37
|
+
class Tweet extends _react.PureComponent {
|
|
38
|
+
/**
|
|
39
|
+
* Renders the sidebar beside the tweet.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} profileImage URL of the Twitter profile image.
|
|
42
|
+
* @param {boolean} isLast Whether or not this is the last tweet in the in a thread.
|
|
43
|
+
* @returns {import('react').Element} The sidebar.
|
|
44
|
+
*/
|
|
45
|
+
renderSidebar(profileImage, isLast) {
|
|
46
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
47
|
+
className: "twitter-preview__sidebar",
|
|
48
|
+
children: [(0, _jsxRuntime.jsx)("div", {
|
|
49
|
+
className: "twitter-preview__profile-image",
|
|
50
|
+
children: (0, _jsxRuntime.jsx)("img", {
|
|
51
|
+
alt: __('Twitter profile image'),
|
|
52
|
+
src: profileImage
|
|
53
|
+
})
|
|
54
|
+
}), !isLast && (0, _jsxRuntime.jsx)("div", {
|
|
55
|
+
className: "twitter-preview__connector"
|
|
56
|
+
})]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Renders the header section of a single tweet.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} name The display name of the Twitter account.
|
|
63
|
+
* @param {string} screenName The at-name of the Twitter account.
|
|
64
|
+
* @param {Date} date The date to be shown for this preview.
|
|
65
|
+
* @returns {import('react').Element} The header.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
renderHeader(name, screenName, date) {
|
|
70
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
71
|
+
className: "twitter-preview__header",
|
|
72
|
+
children: [(0, _jsxRuntime.jsx)("span", {
|
|
73
|
+
className: "twitter-preview__name",
|
|
74
|
+
children: name
|
|
75
|
+
}), (0, _jsxRuntime.jsx)("span", {
|
|
76
|
+
className: "twitter-preview__screen-name",
|
|
77
|
+
children: screenName
|
|
78
|
+
}), (0, _jsxRuntime.jsx)("span", {
|
|
79
|
+
className: "twitter-preview__date",
|
|
80
|
+
children: (0, _moment.default)(date).format('MMM D')
|
|
81
|
+
})]
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Renders the text section of the tweet.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} text The text of the tweet.
|
|
88
|
+
* @param {Array} urls Optional. An array of URLs that are in the text.
|
|
89
|
+
* @param {object} card Optional. The card data for this tweet.
|
|
90
|
+
* @returns {import('react').Element} The text section.
|
|
91
|
+
*/
|
|
41
92
|
|
|
42
|
-
var baseDomain = function baseDomain(url) {
|
|
43
|
-
return url.replace(/^[^/]+[/]*(www\.)?/, '') // Strip leading protocol and "www.".
|
|
44
|
-
.replace(/\/.*$/, '');
|
|
45
|
-
}; // Strip everything after the domain.
|
|
46
93
|
|
|
94
|
+
renderText(text) {
|
|
95
|
+
let urls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
96
|
+
let card = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
97
|
+
// If the text ends with the card URL, remove it.
|
|
98
|
+
const cardUrl = card.url || '';
|
|
99
|
+
const deCardedText = text.endsWith(cardUrl) ? text.substr(0, text.lastIndexOf(cardUrl)) : text;
|
|
47
100
|
|
|
48
|
-
|
|
101
|
+
const __html = urls.reduce((html, url) => html.replace(new RegExp('\\(' + url + '\\)', 'g'), `(<a href="${url}">${url}</a>)`), (0, _helpers.stripHtmlTags)(deCardedText).replace(new RegExp('\\n', 'g'), '<br/>')); // We can enable dangerouslySetInnerHTML here, since the text we're using is stripped
|
|
102
|
+
// of all HTML tags, then only has safe tags added in createTweetMarkup().
|
|
49
103
|
|
|
50
|
-
|
|
51
|
-
(0, _inherits2.default)(Tweet, _PureComponent);
|
|
104
|
+
/* eslint-disable react/no-danger */
|
|
52
105
|
|
|
53
|
-
var _super = (0, _createSuper2.default)(Tweet);
|
|
54
106
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
107
|
+
return (0, _jsxRuntime.jsx)("div", {
|
|
108
|
+
className: "twitter-preview__text",
|
|
109
|
+
dangerouslySetInnerHTML: {
|
|
110
|
+
__html
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
/* eslint-enabled react/no-danger */
|
|
58
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Renders the media section of the tweet. It will render up to four individual images, or a single
|
|
117
|
+
* GIF, or a single video. Any media beyond these limits will be discarded.
|
|
118
|
+
*
|
|
119
|
+
* @param {Array} media The media to include in this tweet.
|
|
120
|
+
* @returns {import('react').Element} The media section.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
renderMedia(media) {
|
|
125
|
+
if (!media) {
|
|
126
|
+
return;
|
|
127
|
+
} // Ensure we're only trying to show valid media, and the correct quantity.
|
|
59
128
|
|
|
60
|
-
(0, _createClass2.default)(Tweet, [{
|
|
61
|
-
key: "renderSidebar",
|
|
62
|
-
value:
|
|
63
|
-
/**
|
|
64
|
-
* Renders the sidebar beside the tweet.
|
|
65
|
-
*
|
|
66
|
-
* @param {string} profileImage URL of the Twitter profile image.
|
|
67
|
-
* @param {boolean} isLast Whether or not this is the last tweet in the in a thread.
|
|
68
|
-
*
|
|
69
|
-
* @returns {React.Element} The sidebar.
|
|
70
|
-
*/
|
|
71
|
-
function renderSidebar(profileImage, isLast) {
|
|
72
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
73
|
-
className: "twitter-preview__sidebar"
|
|
74
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
75
|
-
className: "twitter-preview__profile-image"
|
|
76
|
-
}, /*#__PURE__*/_react.default.createElement("img", {
|
|
77
|
-
alt: __('Twitter profile image'),
|
|
78
|
-
src: profileImage
|
|
79
|
-
})), !isLast && /*#__PURE__*/_react.default.createElement("div", {
|
|
80
|
-
className: "twitter-preview__connector"
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Renders the header section of a single tweet.
|
|
85
|
-
*
|
|
86
|
-
* @param {string} name The display name of the Twitter account.
|
|
87
|
-
* @param {string} screenName The at-name of the Twitter account.
|
|
88
|
-
* @param {Date} date The date to be shown for this preview.
|
|
89
|
-
*
|
|
90
|
-
* @returns {React.Element} The header.
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
}, {
|
|
94
|
-
key: "renderHeader",
|
|
95
|
-
value: function renderHeader(name, screenName, date) {
|
|
96
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
97
|
-
className: "twitter-preview__header"
|
|
98
|
-
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
99
|
-
className: "twitter-preview__name"
|
|
100
|
-
}, name), /*#__PURE__*/_react.default.createElement("span", {
|
|
101
|
-
className: "twitter-preview__screen-name"
|
|
102
|
-
}, screenName), /*#__PURE__*/_react.default.createElement("span", {
|
|
103
|
-
className: "twitter-preview__date"
|
|
104
|
-
}, (0, _moment.default)(date).format('MMM D')));
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Renders the text section of the tweet.
|
|
108
|
-
*
|
|
109
|
-
* @param {string} text The text of the tweet.
|
|
110
|
-
* @param {Array} urls Optional. An array of URLs that are in the text.
|
|
111
|
-
* @param {object} card Optional. The card data for this tweet.
|
|
112
|
-
*
|
|
113
|
-
* @returns {React.Element} The text section.
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
}, {
|
|
117
|
-
key: "renderText",
|
|
118
|
-
value: function renderText(text) {
|
|
119
|
-
var urls = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
120
|
-
var card = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
121
|
-
// If the text ends with the card URL, remove it.
|
|
122
|
-
var cardUrl = card.url || '';
|
|
123
|
-
var deCardedText = text.endsWith(cardUrl) ? text.substr(0, text.lastIndexOf(cardUrl)) : text;
|
|
124
|
-
|
|
125
|
-
var __html = urls.reduce(function (html, url) {
|
|
126
|
-
return html.replace(new RegExp('\\(' + url + '\\)', 'g'), "(<a href=\"".concat(url, "\">").concat(url, "</a>)"));
|
|
127
|
-
}, (0, _helpers.stripHtmlTags)(deCardedText).replace(new RegExp('\\n', 'g'), '<br/>')); // We can enable dangerouslySetInnerHTML here, since the text we're using is stripped
|
|
128
|
-
// of all HTML tags, then only has safe tags added in createTweetMarkup().
|
|
129
|
-
|
|
130
|
-
/* eslint-disable react/no-danger */
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
134
|
-
className: "twitter-preview__text",
|
|
135
|
-
dangerouslySetInnerHTML: {
|
|
136
|
-
__html: __html
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
/* eslint-enabled react/no-danger */
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Renders the media section of the tweet. It will render up to four individual images, or a single
|
|
143
|
-
* GIF, or a single video. Any media beyond these limits will be discarded.
|
|
144
|
-
*
|
|
145
|
-
* @param {Array} media The media to include in this tweet.
|
|
146
|
-
*
|
|
147
|
-
* @returns {React.Element} The media section.
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
}, {
|
|
151
|
-
key: "renderMedia",
|
|
152
|
-
value: function renderMedia(media) {
|
|
153
|
-
if (!media) {
|
|
154
|
-
return;
|
|
155
|
-
} // Ensure we're only trying to show valid media, and the correct quantity.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
var filteredMedia = media // Only image/ and video/ mime types are supported.
|
|
159
|
-
.filter(function (mediaItem) {
|
|
160
|
-
return mediaItem.type.startsWith('image/') || mediaItem.type.startsWith('video/');
|
|
161
|
-
}).filter(function (mediaItem, idx, array) {
|
|
162
|
-
// We'll always keep the first item.
|
|
163
|
-
if (0 === idx) {
|
|
164
|
-
return true;
|
|
165
|
-
} // If the first item was a video or GIF, discard all subsequent items.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (array[0].type.startsWith('video/') || 'image/gif' === array[0].type) {
|
|
169
|
-
return false;
|
|
170
|
-
} // The first item wasn't a video or GIF, so discard all subsequent videos and GIFs.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (mediaItem.type.startsWith('video/') || 'image/gif' === mediaItem.type) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
129
|
|
|
130
|
+
const filteredMedia = media // Only image/ and video/ mime types are supported.
|
|
131
|
+
.filter(mediaItem => mediaItem.type.startsWith('image/') || mediaItem.type.startsWith('video/')).filter((mediaItem, idx, array) => {
|
|
132
|
+
// We'll always keep the first item.
|
|
133
|
+
if (0 === idx) {
|
|
177
134
|
return true;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
135
|
+
} // If the first item was a video or GIF, discard all subsequent items.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if (array[0].type.startsWith('video/') || 'image/gif' === array[0].type) {
|
|
139
|
+
return false;
|
|
140
|
+
} // The first item wasn't a video or GIF, so discard all subsequent videos and GIFs.
|
|
182
141
|
|
|
183
|
-
|
|
184
|
-
|
|
142
|
+
|
|
143
|
+
if (mediaItem.type.startsWith('video/') || 'image/gif' === mediaItem.type) {
|
|
144
|
+
return false;
|
|
185
145
|
}
|
|
186
146
|
|
|
187
|
-
return
|
|
188
|
-
|
|
189
|
-
|
|
147
|
+
return true;
|
|
148
|
+
}) // We only want the first four items of the array, at most.
|
|
149
|
+
.slice(0, 4);
|
|
150
|
+
const isVideo = filteredMedia.length > 0 && filteredMedia[0].type.startsWith('video/');
|
|
151
|
+
const mediaClasses = (0, _classnames.default)(['twitter-preview__media', 'twitter-preview__media-children-' + filteredMedia.length]);
|
|
152
|
+
|
|
153
|
+
if (0 === filteredMedia.length) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
158
|
+
className: mediaClasses,
|
|
159
|
+
children: [
|
|
190
160
|
/* eslint-disable jsx-a11y/media-has-caption */
|
|
191
|
-
isVideo && filteredMedia.map(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
controls: true
|
|
195
|
-
}, /*#__PURE__*/_react.default.createElement("source", {
|
|
161
|
+
isVideo && filteredMedia.map((mediaItem, index) => (0, _jsxRuntime.jsxs)("video", {
|
|
162
|
+
controls: true,
|
|
163
|
+
children: [(0, _jsxRuntime.jsx)("source", {
|
|
196
164
|
src: mediaItem.url,
|
|
197
165
|
type: mediaItem.type
|
|
198
|
-
}), ' '
|
|
199
|
-
})
|
|
166
|
+
}), ' ']
|
|
167
|
+
}, `twitter-preview__media-item-${index}`))
|
|
200
168
|
/* eslint-disable jsx-a11y/media-has-caption */
|
|
201
|
-
, !isVideo && filteredMedia.map(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
169
|
+
, !isVideo && filteredMedia.map((mediaItem, index) => (0, _jsxRuntime.jsx)("img", {
|
|
170
|
+
alt: mediaItem.alt,
|
|
171
|
+
src: mediaItem.url
|
|
172
|
+
}, `twitter-preview__media-item-${index}`))]
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Given a tweet URL, renders it as a quoted tweet.
|
|
177
|
+
*
|
|
178
|
+
* @param {string} tweet The tweet URL.
|
|
179
|
+
* @returns {import('react').Element} The quoted tweet.
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
renderQuoteTweet(tweet) {
|
|
184
|
+
if (!tweet) {
|
|
185
|
+
return;
|
|
208
186
|
}
|
|
209
|
-
/**
|
|
210
|
-
* Given a tweet URL, renders it as a quoted tweet.
|
|
211
|
-
*
|
|
212
|
-
* @param {string} tweet The tweet URL.
|
|
213
|
-
*
|
|
214
|
-
* @returns {React.Element} The quoted tweet.
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
|
-
}, {
|
|
218
|
-
key: "renderQuoteTweet",
|
|
219
|
-
value: function renderQuoteTweet(tweet) {
|
|
220
|
-
if (!tweet) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
187
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
html:
|
|
188
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
189
|
+
className: "twitter-preview__quote-tweet",
|
|
190
|
+
children: [(0, _jsxRuntime.jsx)(_components.SandBox, {
|
|
191
|
+
html: `<blockquote class="twitter-tweet" data-conversation="none" data-dnt="true"><a href="${tweet}"></a></blockquote>`,
|
|
228
192
|
scripts: ['https://platform.twitter.com/widgets.js'],
|
|
229
193
|
title: "Embedded tweet",
|
|
230
194
|
onFocus: this.hideOverlay
|
|
231
|
-
}),
|
|
195
|
+
}), (0, _jsxRuntime.jsx)("div", {
|
|
232
196
|
className: "twitter-preview__quote-tweet-overlay"
|
|
233
|
-
})
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}, {
|
|
244
|
-
key: "renderCard",
|
|
245
|
-
value: function renderCard(card) {
|
|
246
|
-
if (!card) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
197
|
+
})]
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Given card data, renders the Twitter-style card.
|
|
202
|
+
*
|
|
203
|
+
* @param {object} card The card data.
|
|
204
|
+
* @returns {import('react').Element} The card tweet.
|
|
205
|
+
*/
|
|
249
206
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
url = card.url;
|
|
255
|
-
var cardClassNames = (0, _classnames.default)("twitter-preview__card-".concat(type), {
|
|
256
|
-
'twitter-preview__card-has-image': !!image
|
|
257
|
-
});
|
|
258
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
259
|
-
className: "twitter-preview__card"
|
|
260
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
261
|
-
className: cardClassNames
|
|
262
|
-
}, image && /*#__PURE__*/_react.default.createElement("img", {
|
|
263
|
-
className: "twitter-preview__card-image",
|
|
264
|
-
src: image,
|
|
265
|
-
alt: ""
|
|
266
|
-
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
267
|
-
className: "twitter-preview__card-body"
|
|
268
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
269
|
-
className: "twitter-preview__card-title"
|
|
270
|
-
}, title), /*#__PURE__*/_react.default.createElement("div", {
|
|
271
|
-
className: "twitter-preview__card-description"
|
|
272
|
-
}, twitterDescription((0, _helpers.stripHtmlTags)(description))), /*#__PURE__*/_react.default.createElement("div", {
|
|
273
|
-
className: "twitter-preview__card-url"
|
|
274
|
-
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
275
|
-
viewBox: "0 0 24 24"
|
|
276
|
-
}, /*#__PURE__*/_react.default.createElement("g", null, /*#__PURE__*/_react.default.createElement("path", {
|
|
277
|
-
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"
|
|
278
|
-
}), /*#__PURE__*/_react.default.createElement("path", {
|
|
279
|
-
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"
|
|
280
|
-
}))), baseDomain(url || '')))));
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Renders the footer section of a single tweet, showing (non-functioning) reply, retweet, etc buttons.
|
|
284
|
-
*
|
|
285
|
-
* @returns {React.Element} The footer.
|
|
286
|
-
*/
|
|
287
|
-
|
|
288
|
-
}, {
|
|
289
|
-
key: "renderFooter",
|
|
290
|
-
value: function renderFooter() {
|
|
291
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
292
|
-
className: "twitter-preview__footer"
|
|
293
|
-
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
294
|
-
className: "twitter-preview__icon-replies"
|
|
295
|
-
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
296
|
-
viewBox: "0 0 24 24"
|
|
297
|
-
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
298
|
-
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"
|
|
299
|
-
}))), /*#__PURE__*/_react.default.createElement("span", {
|
|
300
|
-
className: "twitter-preview__icon-retweets"
|
|
301
|
-
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
302
|
-
viewBox: "0 0 24 24"
|
|
303
|
-
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
304
|
-
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"
|
|
305
|
-
}))), /*#__PURE__*/_react.default.createElement("span", {
|
|
306
|
-
className: "twitter-preview__icon-likes"
|
|
307
|
-
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
308
|
-
viewBox: "0 0 24 24"
|
|
309
|
-
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
310
|
-
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"
|
|
311
|
-
}))), /*#__PURE__*/_react.default.createElement("span", {
|
|
312
|
-
className: "twitter-preview__icon-share"
|
|
313
|
-
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
314
|
-
viewBox: "0 0 24 24"
|
|
315
|
-
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
316
|
-
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"
|
|
317
|
-
}), /*#__PURE__*/_react.default.createElement("path", {
|
|
318
|
-
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"
|
|
319
|
-
}))));
|
|
320
|
-
}
|
|
321
|
-
}, {
|
|
322
|
-
key: "render",
|
|
323
|
-
value: function render() {
|
|
324
|
-
var _this$props = this.props,
|
|
325
|
-
isLast = _this$props.isLast,
|
|
326
|
-
profileImage = _this$props.profileImage,
|
|
327
|
-
name = _this$props.name,
|
|
328
|
-
screenName = _this$props.screenName,
|
|
329
|
-
date = _this$props.date,
|
|
330
|
-
text = _this$props.text,
|
|
331
|
-
media = _this$props.media,
|
|
332
|
-
tweet = _this$props.tweet,
|
|
333
|
-
urls = _this$props.urls,
|
|
334
|
-
card = _this$props.card;
|
|
335
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
336
|
-
className: "twitter-preview__container"
|
|
337
|
-
}, this.renderSidebar(profileImage, isLast), /*#__PURE__*/_react.default.createElement("div", {
|
|
338
|
-
className: "twitter-preview__main"
|
|
339
|
-
}, this.renderHeader(name, screenName, date), /*#__PURE__*/_react.default.createElement("div", {
|
|
340
|
-
className: "twitter-preview__content"
|
|
341
|
-
}, this.renderText(text, urls, card), this.renderMedia(media), this.renderQuoteTweet(tweet), this.renderCard(card)), this.renderFooter()));
|
|
207
|
+
|
|
208
|
+
renderCard(card) {
|
|
209
|
+
if (!card) {
|
|
210
|
+
return;
|
|
342
211
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
212
|
+
|
|
213
|
+
const {
|
|
214
|
+
description,
|
|
215
|
+
image,
|
|
216
|
+
title,
|
|
217
|
+
type,
|
|
218
|
+
url
|
|
219
|
+
} = card;
|
|
220
|
+
const cardClassNames = (0, _classnames.default)(`twitter-preview__card-${type}`, {
|
|
221
|
+
'twitter-preview__card-has-image': !!image
|
|
222
|
+
});
|
|
223
|
+
return (0, _jsxRuntime.jsx)("div", {
|
|
224
|
+
className: "twitter-preview__card",
|
|
225
|
+
children: (0, _jsxRuntime.jsxs)("div", {
|
|
226
|
+
className: cardClassNames,
|
|
227
|
+
children: [image && (0, _jsxRuntime.jsx)("img", {
|
|
228
|
+
className: "twitter-preview__card-image",
|
|
229
|
+
src: image,
|
|
230
|
+
alt: ""
|
|
231
|
+
}), (0, _jsxRuntime.jsxs)("div", {
|
|
232
|
+
className: "twitter-preview__card-body",
|
|
233
|
+
children: [(0, _jsxRuntime.jsx)("div", {
|
|
234
|
+
className: "twitter-preview__card-title",
|
|
235
|
+
children: title
|
|
236
|
+
}), (0, _jsxRuntime.jsx)("div", {
|
|
237
|
+
className: "twitter-preview__card-description",
|
|
238
|
+
children: twitterDescription((0, _helpers.stripHtmlTags)(description))
|
|
239
|
+
}), (0, _jsxRuntime.jsxs)("div", {
|
|
240
|
+
className: "twitter-preview__card-url",
|
|
241
|
+
children: [(0, _jsxRuntime.jsx)("svg", {
|
|
242
|
+
viewBox: "0 0 24 24",
|
|
243
|
+
children: (0, _jsxRuntime.jsxs)("g", {
|
|
244
|
+
children: [(0, _jsxRuntime.jsx)("path", {
|
|
245
|
+
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"
|
|
246
|
+
}), (0, _jsxRuntime.jsx)("path", {
|
|
247
|
+
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"
|
|
248
|
+
})]
|
|
249
|
+
})
|
|
250
|
+
}), baseDomain(url || '')]
|
|
251
|
+
})]
|
|
252
|
+
})]
|
|
253
|
+
})
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Renders the footer section of a single tweet, showing (non-functioning) reply, retweet, etc buttons.
|
|
258
|
+
*
|
|
259
|
+
* @returns {import('react').Element} The footer.
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
renderFooter() {
|
|
264
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
265
|
+
className: "twitter-preview__footer",
|
|
266
|
+
children: [(0, _jsxRuntime.jsx)("span", {
|
|
267
|
+
className: "twitter-preview__icon-replies",
|
|
268
|
+
children: (0, _jsxRuntime.jsx)("svg", {
|
|
269
|
+
viewBox: "0 0 24 24",
|
|
270
|
+
children: (0, _jsxRuntime.jsx)("path", {
|
|
271
|
+
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"
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
}), (0, _jsxRuntime.jsx)("span", {
|
|
275
|
+
className: "twitter-preview__icon-retweets",
|
|
276
|
+
children: (0, _jsxRuntime.jsx)("svg", {
|
|
277
|
+
viewBox: "0 0 24 24",
|
|
278
|
+
children: (0, _jsxRuntime.jsx)("path", {
|
|
279
|
+
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"
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
}), (0, _jsxRuntime.jsx)("span", {
|
|
283
|
+
className: "twitter-preview__icon-likes",
|
|
284
|
+
children: (0, _jsxRuntime.jsx)("svg", {
|
|
285
|
+
viewBox: "0 0 24 24",
|
|
286
|
+
children: (0, _jsxRuntime.jsx)("path", {
|
|
287
|
+
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"
|
|
288
|
+
})
|
|
289
|
+
})
|
|
290
|
+
}), (0, _jsxRuntime.jsx)("span", {
|
|
291
|
+
className: "twitter-preview__icon-share",
|
|
292
|
+
children: (0, _jsxRuntime.jsxs)("svg", {
|
|
293
|
+
viewBox: "0 0 24 24",
|
|
294
|
+
children: [(0, _jsxRuntime.jsx)("path", {
|
|
295
|
+
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"
|
|
296
|
+
}), (0, _jsxRuntime.jsx)("path", {
|
|
297
|
+
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"
|
|
298
|
+
})]
|
|
299
|
+
})
|
|
300
|
+
})]
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
render() {
|
|
305
|
+
const {
|
|
306
|
+
isLast,
|
|
307
|
+
profileImage,
|
|
308
|
+
name,
|
|
309
|
+
screenName,
|
|
310
|
+
date,
|
|
311
|
+
text,
|
|
312
|
+
media,
|
|
313
|
+
tweet,
|
|
314
|
+
urls,
|
|
315
|
+
card
|
|
316
|
+
} = this.props;
|
|
317
|
+
return (0, _jsxRuntime.jsxs)("div", {
|
|
318
|
+
className: "twitter-preview__container",
|
|
319
|
+
children: [this.renderSidebar(profileImage, isLast), (0, _jsxRuntime.jsxs)("div", {
|
|
320
|
+
className: "twitter-preview__main",
|
|
321
|
+
children: [this.renderHeader(name, screenName, date), (0, _jsxRuntime.jsxs)("div", {
|
|
322
|
+
className: "twitter-preview__content",
|
|
323
|
+
children: [this.renderText(text, urls, card), this.renderMedia(media), this.renderQuoteTweet(tweet), this.renderCard(card)]
|
|
324
|
+
}), this.renderFooter()]
|
|
325
|
+
})]
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
}
|
|
346
330
|
|
|
347
331
|
exports.Tweet = Tweet;
|
|
348
332
|
Tweet.propTypes = {
|