Skip to content

Commit 427f8d4

Browse files
committed
refactor(media-embed): tighten comments and drop a redundant guard
- Drop the redundant paragraph type-check in getStandaloneLinkHref (the caller already filters to paragraphs) and rename the param for clarity - Remove an inline comment and a TSDoc sentence that restated logic documented elsewhere
1 parent 4aa6e9d commit 427f8d4

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/embed
  • packages/utils/src

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/embed/link-embed.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const LINK_EMBED_PLUGIN_KEY = new PluginKey('linkEmbed')
1313
* standalone links become media embeds — a link inline within a sentence stays a plain link,
1414
* matching how Notion and Linear auto-embed.
1515
*/
16-
function getStandaloneLinkHref(node: ProseMirrorNode): string | null {
17-
if (node.type.name !== 'paragraph' || node.childCount === 0) return null
16+
function getStandaloneLinkHref(paragraph: ProseMirrorNode): string | null {
17+
if (paragraph.childCount === 0) return null
1818
let href: string | null = null
1919
let isStandalone = true
20-
node.forEach((child) => {
20+
paragraph.forEach((child) => {
2121
if (!isStandalone) return
2222
const linkMark = child.isText
2323
? child.marks.find((mark) => mark.type.name === 'link')
@@ -43,9 +43,6 @@ function buildDecorations(doc: ProseMirrorNode): DecorationSet {
4343
if (href) {
4444
const embedInfo = getEmbedInfo(href)
4545
if (embedInfo) {
46-
// Key by source + occurrence index so the iframe/video DOM is reused across unrelated
47-
// edits (no reload on keystroke) while two links to the same URL still render as two
48-
// distinct widgets rather than collapsing into one.
4946
const source = `embed:${embedInfo.type}:${embedInfo.url}`
5047
const index = sourceCounts.get(source) ?? 0
5148
sourceCounts.set(source, index + 1)
@@ -57,7 +54,7 @@ function buildDecorations(doc: ProseMirrorNode): DecorationSet {
5754
)
5855
}
5956
}
60-
// Paragraphs hold only inline content — never another embeddable paragraph.
57+
// Paragraphs hold only inline content, so there is nothing more to descend into.
6158
return false
6259
})
6360
return DecorationSet.create(doc, decorations)

packages/utils/src/media-embed.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ function toDropboxDirectVideoUrl(parsed: URL): string | null {
5757
* generic video/audio file extensions. Returns null when the URL is not a
5858
* recognized embeddable source.
5959
*
60-
* Each platform is gated on its parsed hostname via {@link hostMatches} before the
61-
* id-extracting regex runs, so a look-alike host can never produce a trusted-looking
62-
* embed. The generic file-extension fallbacks are intentionally host-agnostic — any
63-
* direct media file URL is embeddable.
60+
* Each platform is gated on its parsed hostname via {@link hostMatches} before its
61+
* id-extracting regex runs. The generic file-extension fallbacks are intentionally
62+
* host-agnostic — any direct media file URL is embeddable.
6463
*/
6564
export function getEmbedInfo(url: string): EmbedInfo | null {
6665
const parsed = parseUrl(url)

0 commit comments

Comments
 (0)