social-embeds 0.8.0 → 0.9.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/README.md +91 -48
- package/dist/components/hooks.js +3 -1
- package/dist/components/platforms.d.ts +32 -0
- package/dist/components/platforms.js +384 -0
- package/dist/components/script-embed.js +8 -7
- package/dist/components/social-embed.d.ts +31 -4
- package/dist/components/social-embed.js +48 -211
- package/dist/core/drivers.js +8 -1
- package/dist/core/plans/youtube.js +15 -3
- package/dist/element.d.ts +1 -1
- package/dist/element.js +1 -1
- package/dist/index.d.ts +21 -20
- package/dist/index.js +3 -2
- package/dist/loader/load-script.js +2 -0
- package/dist/parser/frames.js +70 -0
- package/dist/parser/html.d.ts +19 -0
- package/dist/parser/iframe.js +2 -2
- package/dist/parser/match-url.js +6 -2
- package/dist/parser/parse-embed.js +14 -10
- package/dist/parser/platform.d.ts +26 -0
- package/dist/parser/platforms/applemusic.js +3 -3
- package/dist/parser/platforms/applepodcasts.js +3 -3
- package/dist/parser/platforms/dailymotion.js +6 -8
- package/dist/parser/platforms/facebook.js +5 -9
- package/dist/parser/platforms/giphy.js +6 -6
- package/dist/parser/platforms/kick.js +4 -4
- package/dist/parser/platforms/linkedin.js +4 -4
- package/dist/parser/platforms/pinterest.js +3 -3
- package/dist/parser/platforms/reddit.js +3 -2
- package/dist/parser/platforms/rumble.js +3 -2
- package/dist/parser/platforms/soundcloud.js +3 -3
- package/dist/parser/platforms/spotify.js +4 -4
- package/dist/parser/platforms/streamable.js +3 -2
- package/dist/parser/platforms/tenor.js +3 -2
- package/dist/parser/platforms/tiktok.js +6 -6
- package/dist/parser/platforms/truthsocial.js +2 -1
- package/dist/parser/platforms/tumblr.js +4 -2
- package/dist/parser/platforms/twitch.js +6 -7
- package/dist/parser/platforms/vimeo.js +31 -12
- package/dist/parser/platforms/x.js +1 -1
- package/dist/parser/platforms/youtube.js +73 -23
- package/dist/parser/url.d.ts +6 -0
- package/dist/parser/url.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { parseIframe } from "../parser/iframe.js";
|
|
2
|
+
import { applemusic as applemusic$1 } from "../parser/platforms/applemusic.js";
|
|
3
|
+
import { applepodcasts as applepodcasts$1 } from "../parser/platforms/applepodcasts.js";
|
|
4
|
+
import { bluesky as bluesky$1 } from "../parser/platforms/bluesky.js";
|
|
5
|
+
import { dailymotion as dailymotion$1 } from "../parser/platforms/dailymotion.js";
|
|
6
|
+
import { facebook as facebook$1 } from "../parser/platforms/facebook.js";
|
|
7
|
+
import { flickr as flickr$1 } from "../parser/platforms/flickr.js";
|
|
8
|
+
import { giphy as giphy$1 } from "../parser/platforms/giphy.js";
|
|
9
|
+
import { imgur as imgur$1 } from "../parser/platforms/imgur.js";
|
|
10
|
+
import { instagram as instagram$1 } from "../parser/platforms/instagram.js";
|
|
11
|
+
import { kick as kick$1 } from "../parser/platforms/kick.js";
|
|
12
|
+
import { linkedin as linkedin$1 } from "../parser/platforms/linkedin.js";
|
|
13
|
+
import { pinterest as pinterest$1 } from "../parser/platforms/pinterest.js";
|
|
14
|
+
import { reddit as reddit$1 } from "../parser/platforms/reddit.js";
|
|
15
|
+
import { rumble as rumble$1 } from "../parser/platforms/rumble.js";
|
|
16
|
+
import { snapchat as snapchat$1 } from "../parser/platforms/snapchat.js";
|
|
17
|
+
import { soundcloud as soundcloud$1 } from "../parser/platforms/soundcloud.js";
|
|
18
|
+
import { spotify as spotify$1 } from "../parser/platforms/spotify.js";
|
|
19
|
+
import { strava as strava$1 } from "../parser/platforms/strava.js";
|
|
20
|
+
import { streamable as streamable$1 } from "../parser/platforms/streamable.js";
|
|
21
|
+
import { telegram as telegram$1 } from "../parser/platforms/telegram.js";
|
|
22
|
+
import { tenor as tenor$1 } from "../parser/platforms/tenor.js";
|
|
23
|
+
import { threads as threads$1 } from "../parser/platforms/threads.js";
|
|
24
|
+
import { tiktok as tiktok$1 } from "../parser/platforms/tiktok.js";
|
|
25
|
+
import { truthsocial as truthsocial$1 } from "../parser/platforms/truthsocial.js";
|
|
26
|
+
import { tumblr as tumblr$1 } from "../parser/platforms/tumblr.js";
|
|
27
|
+
import { twitch as twitch$1 } from "../parser/platforms/twitch.js";
|
|
28
|
+
import { vimeo as vimeo$1 } from "../parser/platforms/vimeo.js";
|
|
29
|
+
import { x as x$1 } from "../parser/platforms/x.js";
|
|
30
|
+
import { youtube as youtube$1 } from "../parser/platforms/youtube.js";
|
|
31
|
+
import { AppleMusicEmbed, ApplePodcastsEmbed } from "./apple-embed.js";
|
|
32
|
+
import { BlueskyEmbed } from "./bluesky-embed.js";
|
|
33
|
+
import { DailymotionEmbed } from "./dailymotion-embed.js";
|
|
34
|
+
import { FacebookEmbed } from "./facebook-embed.js";
|
|
35
|
+
import { FlickrEmbed } from "./flickr-embed.js";
|
|
36
|
+
import { GiphyEmbed } from "./giphy-embed.js";
|
|
37
|
+
import { ImgurEmbed } from "./imgur-embed.js";
|
|
38
|
+
import { InstagramEmbed } from "./instagram-embed.js";
|
|
39
|
+
import { KickEmbed } from "./kick-embed.js";
|
|
40
|
+
import { LinkedInEmbed } from "./linkedin-embed.js";
|
|
41
|
+
import { PinterestEmbed } from "./pinterest-embed.js";
|
|
42
|
+
import { RedditEmbed } from "./reddit-embed.js";
|
|
43
|
+
import { RumbleEmbed } from "./rumble-embed.js";
|
|
44
|
+
import { SnapchatEmbed } from "./snapchat-embed.js";
|
|
45
|
+
import { SoundCloudEmbed } from "./soundcloud-embed.js";
|
|
46
|
+
import { SpotifyEmbed } from "./spotify-embed.js";
|
|
47
|
+
import { StravaEmbed } from "./strava-embed.js";
|
|
48
|
+
import { StreamableEmbed } from "./streamable-embed.js";
|
|
49
|
+
import { TelegramEmbed } from "./telegram-embed.js";
|
|
50
|
+
import { TenorEmbed } from "./tenor-embed.js";
|
|
51
|
+
import { ThreadsEmbed } from "./threads-embed.js";
|
|
52
|
+
import { TikTokEmbed } from "./tiktok-embed.js";
|
|
53
|
+
import { TruthSocialEmbed } from "./truthsocial-embed.js";
|
|
54
|
+
import { TumblrEmbed } from "./tumblr-embed.js";
|
|
55
|
+
import { TwitchEmbed } from "./twitch-embed.js";
|
|
56
|
+
import { VimeoEmbed } from "./vimeo-embed.js";
|
|
57
|
+
import { XEmbed } from "./x-embed.js";
|
|
58
|
+
import { YouTubeEmbed } from "./youtube-embed.js";
|
|
59
|
+
import { GenericIframeEmbed } from "./generic-iframe-embed.js";
|
|
60
|
+
import { jsx } from "react/jsx-runtime";
|
|
61
|
+
// src/components/platforms.tsx
|
|
62
|
+
const x = {
|
|
63
|
+
kind: "platform",
|
|
64
|
+
parser: x$1,
|
|
65
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(XEmbed, {
|
|
66
|
+
...shared,
|
|
67
|
+
onError,
|
|
68
|
+
embed
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
const instagram = {
|
|
72
|
+
kind: "platform",
|
|
73
|
+
parser: instagram$1,
|
|
74
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(InstagramEmbed, {
|
|
75
|
+
...shared,
|
|
76
|
+
onError,
|
|
77
|
+
embed
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
const facebook = {
|
|
81
|
+
kind: "platform",
|
|
82
|
+
parser: facebook$1,
|
|
83
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(FacebookEmbed, {
|
|
84
|
+
...shared,
|
|
85
|
+
...frame,
|
|
86
|
+
onError,
|
|
87
|
+
embed
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
const threads = {
|
|
91
|
+
kind: "platform",
|
|
92
|
+
parser: threads$1,
|
|
93
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(ThreadsEmbed, {
|
|
94
|
+
...shared,
|
|
95
|
+
onError,
|
|
96
|
+
embed
|
|
97
|
+
})
|
|
98
|
+
};
|
|
99
|
+
const tiktok = {
|
|
100
|
+
kind: "platform",
|
|
101
|
+
parser: tiktok$1,
|
|
102
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(TikTokEmbed, {
|
|
103
|
+
...shared,
|
|
104
|
+
...frame,
|
|
105
|
+
onError,
|
|
106
|
+
embed
|
|
107
|
+
})
|
|
108
|
+
};
|
|
109
|
+
const youtube = {
|
|
110
|
+
kind: "platform",
|
|
111
|
+
parser: youtube$1,
|
|
112
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(YouTubeEmbed, {
|
|
113
|
+
...shared,
|
|
114
|
+
...frame,
|
|
115
|
+
onError,
|
|
116
|
+
embed
|
|
117
|
+
})
|
|
118
|
+
};
|
|
119
|
+
const telegram = {
|
|
120
|
+
kind: "platform",
|
|
121
|
+
parser: telegram$1,
|
|
122
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(TelegramEmbed, {
|
|
123
|
+
...shared,
|
|
124
|
+
onError,
|
|
125
|
+
embed
|
|
126
|
+
})
|
|
127
|
+
};
|
|
128
|
+
const snapchat = {
|
|
129
|
+
kind: "platform",
|
|
130
|
+
parser: snapchat$1,
|
|
131
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(SnapchatEmbed, {
|
|
132
|
+
...shared,
|
|
133
|
+
...frame,
|
|
134
|
+
onError,
|
|
135
|
+
embed
|
|
136
|
+
})
|
|
137
|
+
};
|
|
138
|
+
const linkedin = {
|
|
139
|
+
kind: "platform",
|
|
140
|
+
parser: linkedin$1,
|
|
141
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(LinkedInEmbed, {
|
|
142
|
+
...shared,
|
|
143
|
+
...frame,
|
|
144
|
+
onError,
|
|
145
|
+
embed
|
|
146
|
+
})
|
|
147
|
+
};
|
|
148
|
+
const reddit = {
|
|
149
|
+
kind: "platform",
|
|
150
|
+
parser: reddit$1,
|
|
151
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(RedditEmbed, {
|
|
152
|
+
...shared,
|
|
153
|
+
onError,
|
|
154
|
+
embed
|
|
155
|
+
})
|
|
156
|
+
};
|
|
157
|
+
const pinterest = {
|
|
158
|
+
kind: "platform",
|
|
159
|
+
parser: pinterest$1,
|
|
160
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(PinterestEmbed, {
|
|
161
|
+
...shared,
|
|
162
|
+
onError,
|
|
163
|
+
embed
|
|
164
|
+
})
|
|
165
|
+
};
|
|
166
|
+
const spotify = {
|
|
167
|
+
kind: "platform",
|
|
168
|
+
parser: spotify$1,
|
|
169
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(SpotifyEmbed, {
|
|
170
|
+
...shared,
|
|
171
|
+
...frame,
|
|
172
|
+
onError,
|
|
173
|
+
embed
|
|
174
|
+
})
|
|
175
|
+
};
|
|
176
|
+
const vimeo = {
|
|
177
|
+
kind: "platform",
|
|
178
|
+
parser: vimeo$1,
|
|
179
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(VimeoEmbed, {
|
|
180
|
+
...shared,
|
|
181
|
+
...frame,
|
|
182
|
+
onError,
|
|
183
|
+
embed
|
|
184
|
+
})
|
|
185
|
+
};
|
|
186
|
+
const twitch = {
|
|
187
|
+
kind: "platform",
|
|
188
|
+
parser: twitch$1,
|
|
189
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(TwitchEmbed, {
|
|
190
|
+
...shared,
|
|
191
|
+
...frame,
|
|
192
|
+
onError,
|
|
193
|
+
embed
|
|
194
|
+
})
|
|
195
|
+
};
|
|
196
|
+
const dailymotion = {
|
|
197
|
+
kind: "platform",
|
|
198
|
+
parser: dailymotion$1,
|
|
199
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(DailymotionEmbed, {
|
|
200
|
+
...shared,
|
|
201
|
+
...frame,
|
|
202
|
+
onError,
|
|
203
|
+
embed
|
|
204
|
+
})
|
|
205
|
+
};
|
|
206
|
+
const soundcloud = {
|
|
207
|
+
kind: "platform",
|
|
208
|
+
parser: soundcloud$1,
|
|
209
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(SoundCloudEmbed, {
|
|
210
|
+
...shared,
|
|
211
|
+
...frame,
|
|
212
|
+
onError,
|
|
213
|
+
embed
|
|
214
|
+
})
|
|
215
|
+
};
|
|
216
|
+
const applemusic = {
|
|
217
|
+
kind: "platform",
|
|
218
|
+
parser: applemusic$1,
|
|
219
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(AppleMusicEmbed, {
|
|
220
|
+
...shared,
|
|
221
|
+
...frame,
|
|
222
|
+
onError,
|
|
223
|
+
embed
|
|
224
|
+
})
|
|
225
|
+
};
|
|
226
|
+
const applepodcasts = {
|
|
227
|
+
kind: "platform",
|
|
228
|
+
parser: applepodcasts$1,
|
|
229
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(ApplePodcastsEmbed, {
|
|
230
|
+
...shared,
|
|
231
|
+
...frame,
|
|
232
|
+
onError,
|
|
233
|
+
embed
|
|
234
|
+
})
|
|
235
|
+
};
|
|
236
|
+
const kick = {
|
|
237
|
+
kind: "platform",
|
|
238
|
+
parser: kick$1,
|
|
239
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(KickEmbed, {
|
|
240
|
+
...shared,
|
|
241
|
+
...frame,
|
|
242
|
+
onError,
|
|
243
|
+
embed
|
|
244
|
+
})
|
|
245
|
+
};
|
|
246
|
+
const giphy = {
|
|
247
|
+
kind: "platform",
|
|
248
|
+
parser: giphy$1,
|
|
249
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(GiphyEmbed, {
|
|
250
|
+
...shared,
|
|
251
|
+
...frame,
|
|
252
|
+
onError,
|
|
253
|
+
embed
|
|
254
|
+
})
|
|
255
|
+
};
|
|
256
|
+
const tenor = {
|
|
257
|
+
kind: "platform",
|
|
258
|
+
parser: tenor$1,
|
|
259
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(TenorEmbed, {
|
|
260
|
+
...shared,
|
|
261
|
+
...frame,
|
|
262
|
+
onError,
|
|
263
|
+
embed
|
|
264
|
+
})
|
|
265
|
+
};
|
|
266
|
+
const streamable = {
|
|
267
|
+
kind: "platform",
|
|
268
|
+
parser: streamable$1,
|
|
269
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(StreamableEmbed, {
|
|
270
|
+
...shared,
|
|
271
|
+
...frame,
|
|
272
|
+
onError,
|
|
273
|
+
embed
|
|
274
|
+
})
|
|
275
|
+
};
|
|
276
|
+
const rumble = {
|
|
277
|
+
kind: "platform",
|
|
278
|
+
parser: rumble$1,
|
|
279
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(RumbleEmbed, {
|
|
280
|
+
...shared,
|
|
281
|
+
...frame,
|
|
282
|
+
onError,
|
|
283
|
+
embed
|
|
284
|
+
})
|
|
285
|
+
};
|
|
286
|
+
const truthsocial = {
|
|
287
|
+
kind: "platform",
|
|
288
|
+
parser: truthsocial$1,
|
|
289
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(TruthSocialEmbed, {
|
|
290
|
+
...shared,
|
|
291
|
+
onError,
|
|
292
|
+
embed
|
|
293
|
+
})
|
|
294
|
+
};
|
|
295
|
+
const imgur = {
|
|
296
|
+
kind: "platform",
|
|
297
|
+
parser: imgur$1,
|
|
298
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(ImgurEmbed, {
|
|
299
|
+
...shared,
|
|
300
|
+
onError,
|
|
301
|
+
embed
|
|
302
|
+
})
|
|
303
|
+
};
|
|
304
|
+
const strava = {
|
|
305
|
+
kind: "platform",
|
|
306
|
+
parser: strava$1,
|
|
307
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(StravaEmbed, {
|
|
308
|
+
...shared,
|
|
309
|
+
onError,
|
|
310
|
+
embed
|
|
311
|
+
})
|
|
312
|
+
};
|
|
313
|
+
const flickr = {
|
|
314
|
+
kind: "platform",
|
|
315
|
+
parser: flickr$1,
|
|
316
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(FlickrEmbed, {
|
|
317
|
+
...shared,
|
|
318
|
+
...frame,
|
|
319
|
+
onError,
|
|
320
|
+
embed
|
|
321
|
+
})
|
|
322
|
+
};
|
|
323
|
+
const bluesky = {
|
|
324
|
+
kind: "platform",
|
|
325
|
+
parser: bluesky$1,
|
|
326
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(BlueskyEmbed, {
|
|
327
|
+
...shared,
|
|
328
|
+
onError,
|
|
329
|
+
embed
|
|
330
|
+
})
|
|
331
|
+
};
|
|
332
|
+
const tumblr = {
|
|
333
|
+
kind: "platform",
|
|
334
|
+
parser: tumblr$1,
|
|
335
|
+
render: (embed, { shared, onError }) => /* @__PURE__ */ jsx(TumblrEmbed, {
|
|
336
|
+
...shared,
|
|
337
|
+
onError,
|
|
338
|
+
embed
|
|
339
|
+
})
|
|
340
|
+
};
|
|
341
|
+
/** Iframe embed code that no listed platform recognises, checked as `GenericIframeEmbed` does. */
|
|
342
|
+
const genericIframe = {
|
|
343
|
+
kind: "iframe",
|
|
344
|
+
parse: parseIframe,
|
|
345
|
+
render: (embed, { shared, frame, onError }) => /* @__PURE__ */ jsx(GenericIframeEmbed, {
|
|
346
|
+
...shared,
|
|
347
|
+
...frame,
|
|
348
|
+
onError,
|
|
349
|
+
embed
|
|
350
|
+
})
|
|
351
|
+
};
|
|
352
|
+
const EVERY_PLATFORM = [
|
|
353
|
+
genericIframe,
|
|
354
|
+
x,
|
|
355
|
+
instagram,
|
|
356
|
+
facebook,
|
|
357
|
+
threads,
|
|
358
|
+
tiktok,
|
|
359
|
+
youtube,
|
|
360
|
+
telegram,
|
|
361
|
+
snapchat,
|
|
362
|
+
linkedin,
|
|
363
|
+
reddit,
|
|
364
|
+
pinterest,
|
|
365
|
+
spotify,
|
|
366
|
+
vimeo,
|
|
367
|
+
twitch,
|
|
368
|
+
dailymotion,
|
|
369
|
+
soundcloud,
|
|
370
|
+
applemusic,
|
|
371
|
+
applepodcasts,
|
|
372
|
+
kick,
|
|
373
|
+
giphy,
|
|
374
|
+
tenor,
|
|
375
|
+
streamable,
|
|
376
|
+
rumble,
|
|
377
|
+
truthsocial,
|
|
378
|
+
imgur,
|
|
379
|
+
strava,
|
|
380
|
+
flickr,
|
|
381
|
+
bluesky,
|
|
382
|
+
tumblr
|
|
383
|
+
];
|
|
384
|
+
export { EVERY_PLATFORM, applemusic, applepodcasts, bluesky, dailymotion, facebook, flickr, genericIframe, giphy, imgur, instagram, kick, linkedin, pinterest, reddit, rumble, snapchat, soundcloud, spotify, strava, streamable, telegram, tenor, threads, tiktok, truthsocial, tumblr, twitch, vimeo, x, youtube };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FinalError } from "../core/drivers.js";
|
|
1
2
|
import { postLinkText, postUrl } from "../core/post-link.js";
|
|
2
3
|
import { RENDER_TIMEOUT_MS, RETRY_DELAY_MS } from "../core/timing.js";
|
|
3
4
|
import { useNearViewport } from "./hooks.js";
|
|
@@ -14,6 +15,7 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
|
|
|
14
15
|
const near = useNearViewport(container, lazy);
|
|
15
16
|
const [rendered, setRendered] = useState(false);
|
|
16
17
|
const [failure, setFailure] = useState();
|
|
18
|
+
const done = useRef(false);
|
|
17
19
|
const callbacks = useRef({
|
|
18
20
|
onLoad,
|
|
19
21
|
onError
|
|
@@ -26,15 +28,14 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
|
|
|
26
28
|
});
|
|
27
29
|
useEffect(() => {
|
|
28
30
|
const element = container.current;
|
|
29
|
-
if (!near || !element) return;
|
|
31
|
+
if (!near || !element || done.current) return;
|
|
30
32
|
let cancelled = false;
|
|
31
|
-
let done = false;
|
|
32
33
|
let timer;
|
|
33
34
|
let stop = () => {};
|
|
34
35
|
const href = postUrl(element);
|
|
35
36
|
const finish = () => {
|
|
36
|
-
if (cancelled || done) return;
|
|
37
|
-
done = true;
|
|
37
|
+
if (cancelled || done.current) return;
|
|
38
|
+
done.current = true;
|
|
38
39
|
clearTimeout(timer);
|
|
39
40
|
stop();
|
|
40
41
|
setRendered(true);
|
|
@@ -45,10 +46,10 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
|
|
|
45
46
|
callbacks.current.onError?.(error);
|
|
46
47
|
};
|
|
47
48
|
const retryOrFail = (number, error) => {
|
|
48
|
-
if (cancelled || done) return;
|
|
49
|
+
if (cancelled || done.current) return;
|
|
49
50
|
stop();
|
|
50
51
|
stop = () => {};
|
|
51
|
-
if (number >= 3) {
|
|
52
|
+
if (number >= 3 || error instanceof FinalError) {
|
|
52
53
|
fail(error);
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
@@ -57,7 +58,7 @@ function ScriptEmbed({ driver, markup, hasFallback, minHeight, label, width = "1
|
|
|
57
58
|
}, RETRY_DELAY_MS * 2 ** (number - 1));
|
|
58
59
|
};
|
|
59
60
|
const attempt = (number) => {
|
|
60
|
-
if (cancelled || done) return;
|
|
61
|
+
if (cancelled || done.current) return;
|
|
61
62
|
try {
|
|
62
63
|
stop = driver.render(element, finish);
|
|
63
64
|
} catch (error) {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { PlatformParser } from "../parser/platform.js";
|
|
2
|
+
import { ParsedEmbed } from "../parser/types.js";
|
|
1
3
|
import "./bluesky-embed.js";
|
|
2
|
-
import { BlueskyOptions } from "../core/plans/bluesky.js";
|
|
3
4
|
import "./dailymotion-embed.js";
|
|
4
|
-
import {
|
|
5
|
+
import { BlueskyOptions } from "../core/plans/bluesky.js";
|
|
5
6
|
import "./facebook-embed.js";
|
|
6
|
-
import {
|
|
7
|
+
import { DailymotionOptions } from "../core/plans/dailymotion.js";
|
|
7
8
|
import "./flickr-embed.js";
|
|
9
|
+
import { FacebookOptions } from "../core/plans/facebook.js";
|
|
10
|
+
import { ParsedIframe } from "../parser/iframe.js";
|
|
8
11
|
import { FlickrOptions } from "../core/plans/flickr.js";
|
|
9
12
|
import "./imgur-embed.js";
|
|
10
13
|
import { ImgurOptions } from "../core/plans/imgur.js";
|
|
@@ -55,6 +58,30 @@ export type SocialEmbedProps = SocialEmbedSource & Omit<FrameProps, PlatformOpti
|
|
|
55
58
|
*/
|
|
56
59
|
fallback?: (html: string) => ReactNode;
|
|
57
60
|
};
|
|
61
|
+
/** What `<SocialEmbed>` passes on to the platform it renders. */
|
|
62
|
+
export type RouteProps = {
|
|
63
|
+
shared: Omit<SocialEmbedProps, 'html' | 'url' | 'fallback' | 'height' | 'maxHeight' | 'onError'>;
|
|
64
|
+
frame: Pick<FrameProps, 'height' | 'maxHeight'>;
|
|
65
|
+
onError: FrameProps['onError'];
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* A platform for `createSocialEmbed`, such as `youtube` or `genericIframe`. Opaque: import the
|
|
69
|
+
* ones a page needs and pass them on.
|
|
70
|
+
*/
|
|
71
|
+
export type EmbedPlatform = {
|
|
72
|
+
readonly kind: 'platform';
|
|
73
|
+
readonly parser: PlatformParser;
|
|
74
|
+
readonly render: (embed: ParsedEmbed, props: RouteProps) => ReactNode;
|
|
75
|
+
} | {
|
|
76
|
+
readonly kind: 'iframe';
|
|
77
|
+
readonly parse: (html: string) => ParsedIframe | null;
|
|
78
|
+
readonly render: (embed: ParsedIframe, props: RouteProps) => ReactNode;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* A `<SocialEmbed>` that recognises only the listed platforms, so a bundler leaves the others
|
|
82
|
+
* out. Call it in a client module: `createSocialEmbed([youtube, x, genericIframe])`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function createSocialEmbed(list: readonly EmbedPlatform[]): (props: SocialEmbedProps) => ReactNode;
|
|
58
85
|
/** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
|
|
59
|
-
export declare function SocialEmbed(props: SocialEmbedProps):
|
|
86
|
+
export declare function SocialEmbed(props: SocialEmbedProps): ReactNode;
|
|
60
87
|
export {};
|