social-embeds 0.8.1 → 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 +36 -0
- package/dist/components/platforms.d.ts +32 -0
- package/dist/components/platforms.js +384 -0
- package/dist/components/social-embed.d.ts +31 -4
- package/dist/components/social-embed.js +48 -211
- package/dist/element.js +1 -1
- package/dist/index.d.ts +21 -20
- package/dist/index.js +3 -2
- package/dist/parser/html.d.ts +19 -0
- package/dist/parser/match-url.js +6 -2
- package/dist/parser/parse-embed.js +12 -8
- package/dist/parser/platform.d.ts +26 -0
- package/dist/parser/url.d.ts +6 -0
- package/package.json +1 -1
|
@@ -1,221 +1,58 @@
|
|
|
1
|
-
import { matchUrl } from "../parser/match-url.js";
|
|
2
|
-
import { parseEmbed } from "../parser/parse-embed.js";
|
|
3
|
-
import { parseIframe } from "../parser/iframe.js";
|
|
4
1
|
import { sourceError } from "../core/resolve.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { DailymotionEmbed } from "./dailymotion-embed.js";
|
|
8
|
-
import { FacebookEmbed } from "./facebook-embed.js";
|
|
9
|
-
import { FlickrEmbed } from "./flickr-embed.js";
|
|
10
|
-
import { GenericIframeEmbed } from "./generic-iframe-embed.js";
|
|
11
|
-
import { GiphyEmbed } from "./giphy-embed.js";
|
|
2
|
+
import { matchUrlWith } from "../parser/match-url.js";
|
|
3
|
+
import { parseEmbedWith } from "../parser/parse-embed.js";
|
|
12
4
|
import { useReportError } from "./hooks.js";
|
|
13
|
-
import {
|
|
14
|
-
import { InstagramEmbed } from "./instagram-embed.js";
|
|
15
|
-
import { KickEmbed } from "./kick-embed.js";
|
|
16
|
-
import { LinkedInEmbed } from "./linkedin-embed.js";
|
|
17
|
-
import { PinterestEmbed } from "./pinterest-embed.js";
|
|
18
|
-
import { RedditEmbed } from "./reddit-embed.js";
|
|
19
|
-
import { SnapchatEmbed } from "./snapchat-embed.js";
|
|
20
|
-
import { SoundCloudEmbed } from "./soundcloud-embed.js";
|
|
21
|
-
import { SpotifyEmbed } from "./spotify-embed.js";
|
|
22
|
-
import { StravaEmbed } from "./strava-embed.js";
|
|
23
|
-
import { StreamableEmbed } from "./streamable-embed.js";
|
|
24
|
-
import { RumbleEmbed } from "./rumble-embed.js";
|
|
25
|
-
import { TenorEmbed } from "./tenor-embed.js";
|
|
26
|
-
import { TelegramEmbed } from "./telegram-embed.js";
|
|
27
|
-
import { ThreadsEmbed } from "./threads-embed.js";
|
|
28
|
-
import { TikTokEmbed } from "./tiktok-embed.js";
|
|
29
|
-
import { TruthSocialEmbed } from "./truthsocial-embed.js";
|
|
30
|
-
import { TumblrEmbed } from "./tumblr-embed.js";
|
|
31
|
-
import { TwitchEmbed } from "./twitch-embed.js";
|
|
32
|
-
import { VimeoEmbed } from "./vimeo-embed.js";
|
|
33
|
-
import { XEmbed } from "./x-embed.js";
|
|
34
|
-
import { YouTubeEmbed } from "./youtube-embed.js";
|
|
5
|
+
import { EVERY_PLATFORM } from "./platforms.js";
|
|
35
6
|
import { useMemo } from "react";
|
|
36
|
-
import { jsx } from "react/jsx-runtime";
|
|
37
7
|
// src/components/social-embed.tsx
|
|
38
|
-
|
|
39
|
-
|
|
8
|
+
function tableOf(list) {
|
|
9
|
+
const named = list.flatMap((entry) => entry.kind === "platform" ? [entry] : []);
|
|
10
|
+
return {
|
|
11
|
+
parsers: named.map((entry) => entry.parser),
|
|
12
|
+
renders: new Map(named.map((entry) => [entry.parser.platform, entry.render])),
|
|
13
|
+
iframe: list.find((entry) => entry.kind === "iframe")
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function useSocialEmbed(props, table) {
|
|
40
17
|
const { html, url, fallback, height, maxHeight, onError, ...shared } = props;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
const route = {
|
|
19
|
+
shared,
|
|
20
|
+
frame: {
|
|
21
|
+
height,
|
|
22
|
+
maxHeight
|
|
23
|
+
},
|
|
24
|
+
onError
|
|
44
25
|
};
|
|
45
|
-
const embed = useMemo(() => html !== void 0 ?
|
|
46
|
-
|
|
26
|
+
const embed = useMemo(() => html !== void 0 ? parseEmbedWith(table.parsers, html) : matchUrlWith(table.parsers, url), [
|
|
27
|
+
html,
|
|
28
|
+
url,
|
|
29
|
+
table
|
|
30
|
+
]);
|
|
31
|
+
const iframe = useMemo(() => embed === null && html !== void 0 ? table.iframe?.parse(html) ?? null : null, [
|
|
32
|
+
embed,
|
|
33
|
+
html,
|
|
34
|
+
table
|
|
35
|
+
]);
|
|
47
36
|
useReportError(embed === null && iframe === null && !(html !== void 0 && fallback) ? sourceError(html !== void 0 ? { html } : { url }) : void 0, onError);
|
|
48
|
-
if (iframe) return
|
|
49
|
-
...shared,
|
|
50
|
-
...frame,
|
|
51
|
-
onError,
|
|
52
|
-
embed: iframe
|
|
53
|
-
});
|
|
37
|
+
if (iframe && table.iframe) return table.iframe.render(iframe, route);
|
|
54
38
|
if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
case "threads": return /* @__PURE__ */ jsx(ThreadsEmbed, {
|
|
67
|
-
...shared,
|
|
68
|
-
onError,
|
|
69
|
-
embed
|
|
70
|
-
});
|
|
71
|
-
case "facebook": return /* @__PURE__ */ jsx(FacebookEmbed, {
|
|
72
|
-
...shared,
|
|
73
|
-
...frame,
|
|
74
|
-
onError,
|
|
75
|
-
embed
|
|
76
|
-
});
|
|
77
|
-
case "tiktok": return /* @__PURE__ */ jsx(TikTokEmbed, {
|
|
78
|
-
...shared,
|
|
79
|
-
...frame,
|
|
80
|
-
onError,
|
|
81
|
-
embed
|
|
82
|
-
});
|
|
83
|
-
case "youtube": return /* @__PURE__ */ jsx(YouTubeEmbed, {
|
|
84
|
-
...shared,
|
|
85
|
-
...frame,
|
|
86
|
-
onError,
|
|
87
|
-
embed
|
|
88
|
-
});
|
|
89
|
-
case "telegram": return /* @__PURE__ */ jsx(TelegramEmbed, {
|
|
90
|
-
...shared,
|
|
91
|
-
onError,
|
|
92
|
-
embed
|
|
93
|
-
});
|
|
94
|
-
case "snapchat": return /* @__PURE__ */ jsx(SnapchatEmbed, {
|
|
95
|
-
...shared,
|
|
96
|
-
...frame,
|
|
97
|
-
onError,
|
|
98
|
-
embed
|
|
99
|
-
});
|
|
100
|
-
case "linkedin": return /* @__PURE__ */ jsx(LinkedInEmbed, {
|
|
101
|
-
...shared,
|
|
102
|
-
...frame,
|
|
103
|
-
onError,
|
|
104
|
-
embed
|
|
105
|
-
});
|
|
106
|
-
case "reddit": return /* @__PURE__ */ jsx(RedditEmbed, {
|
|
107
|
-
...shared,
|
|
108
|
-
onError,
|
|
109
|
-
embed
|
|
110
|
-
});
|
|
111
|
-
case "pinterest": return /* @__PURE__ */ jsx(PinterestEmbed, {
|
|
112
|
-
...shared,
|
|
113
|
-
onError,
|
|
114
|
-
embed
|
|
115
|
-
});
|
|
116
|
-
case "spotify": return /* @__PURE__ */ jsx(SpotifyEmbed, {
|
|
117
|
-
...shared,
|
|
118
|
-
...frame,
|
|
119
|
-
onError,
|
|
120
|
-
embed
|
|
121
|
-
});
|
|
122
|
-
case "vimeo": return /* @__PURE__ */ jsx(VimeoEmbed, {
|
|
123
|
-
...shared,
|
|
124
|
-
...frame,
|
|
125
|
-
onError,
|
|
126
|
-
embed
|
|
127
|
-
});
|
|
128
|
-
case "twitch": return /* @__PURE__ */ jsx(TwitchEmbed, {
|
|
129
|
-
...shared,
|
|
130
|
-
...frame,
|
|
131
|
-
onError,
|
|
132
|
-
embed
|
|
133
|
-
});
|
|
134
|
-
case "dailymotion": return /* @__PURE__ */ jsx(DailymotionEmbed, {
|
|
135
|
-
...shared,
|
|
136
|
-
...frame,
|
|
137
|
-
onError,
|
|
138
|
-
embed
|
|
139
|
-
});
|
|
140
|
-
case "bluesky": return /* @__PURE__ */ jsx(BlueskyEmbed, {
|
|
141
|
-
...shared,
|
|
142
|
-
onError,
|
|
143
|
-
embed
|
|
144
|
-
});
|
|
145
|
-
case "soundcloud": return /* @__PURE__ */ jsx(SoundCloudEmbed, {
|
|
146
|
-
...shared,
|
|
147
|
-
...frame,
|
|
148
|
-
onError,
|
|
149
|
-
embed
|
|
150
|
-
});
|
|
151
|
-
case "applemusic": return /* @__PURE__ */ jsx(AppleMusicEmbed, {
|
|
152
|
-
...shared,
|
|
153
|
-
...frame,
|
|
154
|
-
onError,
|
|
155
|
-
embed
|
|
156
|
-
});
|
|
157
|
-
case "applepodcasts": return /* @__PURE__ */ jsx(ApplePodcastsEmbed, {
|
|
158
|
-
...shared,
|
|
159
|
-
...frame,
|
|
160
|
-
onError,
|
|
161
|
-
embed
|
|
162
|
-
});
|
|
163
|
-
case "tumblr": return /* @__PURE__ */ jsx(TumblrEmbed, {
|
|
164
|
-
...shared,
|
|
165
|
-
onError,
|
|
166
|
-
embed
|
|
167
|
-
});
|
|
168
|
-
case "kick": return /* @__PURE__ */ jsx(KickEmbed, {
|
|
169
|
-
...shared,
|
|
170
|
-
...frame,
|
|
171
|
-
onError,
|
|
172
|
-
embed
|
|
173
|
-
});
|
|
174
|
-
case "giphy": return /* @__PURE__ */ jsx(GiphyEmbed, {
|
|
175
|
-
...shared,
|
|
176
|
-
...frame,
|
|
177
|
-
onError,
|
|
178
|
-
embed
|
|
179
|
-
});
|
|
180
|
-
case "tenor": return /* @__PURE__ */ jsx(TenorEmbed, {
|
|
181
|
-
...shared,
|
|
182
|
-
...frame,
|
|
183
|
-
onError,
|
|
184
|
-
embed
|
|
185
|
-
});
|
|
186
|
-
case "streamable": return /* @__PURE__ */ jsx(StreamableEmbed, {
|
|
187
|
-
...shared,
|
|
188
|
-
...frame,
|
|
189
|
-
onError,
|
|
190
|
-
embed
|
|
191
|
-
});
|
|
192
|
-
case "rumble": return /* @__PURE__ */ jsx(RumbleEmbed, {
|
|
193
|
-
...shared,
|
|
194
|
-
...frame,
|
|
195
|
-
onError,
|
|
196
|
-
embed
|
|
197
|
-
});
|
|
198
|
-
case "truthsocial": return /* @__PURE__ */ jsx(TruthSocialEmbed, {
|
|
199
|
-
...shared,
|
|
200
|
-
onError,
|
|
201
|
-
embed
|
|
202
|
-
});
|
|
203
|
-
case "imgur": return /* @__PURE__ */ jsx(ImgurEmbed, {
|
|
204
|
-
...shared,
|
|
205
|
-
onError,
|
|
206
|
-
embed
|
|
207
|
-
});
|
|
208
|
-
case "strava": return /* @__PURE__ */ jsx(StravaEmbed, {
|
|
209
|
-
...shared,
|
|
210
|
-
onError,
|
|
211
|
-
embed
|
|
212
|
-
});
|
|
213
|
-
case "flickr": return /* @__PURE__ */ jsx(FlickrEmbed, {
|
|
214
|
-
...shared,
|
|
215
|
-
...frame,
|
|
216
|
-
onError,
|
|
217
|
-
embed
|
|
218
|
-
});
|
|
39
|
+
return table.renders.get(embed.platform)?.(embed, route) ?? null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A `<SocialEmbed>` that recognises only the listed platforms, so a bundler leaves the others
|
|
43
|
+
* out. Call it in a client module: `createSocialEmbed([youtube, x, genericIframe])`.
|
|
44
|
+
*/
|
|
45
|
+
function createSocialEmbed(list) {
|
|
46
|
+
const table = tableOf(list);
|
|
47
|
+
function SocialEmbed(props) {
|
|
48
|
+
return useSocialEmbed(props, table);
|
|
219
49
|
}
|
|
50
|
+
return SocialEmbed;
|
|
51
|
+
}
|
|
52
|
+
let every;
|
|
53
|
+
/** `height` and `maxHeight` reach only the iframe-based embeds: the others size themselves. */
|
|
54
|
+
function SocialEmbed(props) {
|
|
55
|
+
every ??= tableOf(EVERY_PLATFORM);
|
|
56
|
+
return useSocialEmbed(props, every);
|
|
220
57
|
}
|
|
221
|
-
export { SocialEmbed };
|
|
58
|
+
export { SocialEmbed, createSocialEmbed };
|