File tree Expand file tree Collapse file tree 5 files changed +85
-7
lines changed
frontends/ol-components/src/components/TiptapEditor Expand file tree Collapse file tree 5 files changed +85
-7
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ const StyledEditorContent = styled(EditorContent)<{ readOnly: boolean }>(
4848 backgroundColor : theme . custom . colors . white ,
4949 borderRadius : "10px" ,
5050 margin : "20px auto" ,
51+ ".tiptap.ProseMirror.simple-editor" : {
52+ padding : "3rem 3rem 5vh" ,
53+ } ,
5154 ...( readOnly
5255 ? {
5356 maxWidth : "1000px" ,
Original file line number Diff line number Diff line change 8989.media-container {
9090 position : relative ;
9191 width : 100% ;
92- height : 100 vh ; // ✅ add height here
92+ aspect-ratio : 16 / 9 ;
9393 overflow : hidden ;
9494}
9595
Original file line number Diff line number Diff line change 1+ import React , { useState , useCallback } from "react"
2+ import NiceModal , { muiDialogV5 } from "@ebay/nice-modal-react"
3+ import { TextField , Alert } from "@mitodl/smoot-design"
4+ import { FormDialog } from "ol-components"
5+
6+ const MediaUrlInputDialog = NiceModal . create ( ( ) => {
7+ const modal = NiceModal . useModal ( )
8+ const [ url , setUrl ] = useState ( "" )
9+ const [ error , setError ] = useState < string | null > ( null )
10+
11+ const handleSubmit = ( e ?: any ) => {
12+ e ?. preventDefault ( )
13+
14+ if ( ! url . trim ( ) ) {
15+ setError ( "URL is required" )
16+ return
17+ }
18+ modal . resolve ( url )
19+ modal . hide ( )
20+ }
21+
22+ const handleReset = useCallback ( ( ) => {
23+ setUrl ( "" )
24+ setError ( null )
25+ } , [ setUrl , setError ] )
26+
27+ return (
28+ < FormDialog
29+ { ...muiDialogV5 ( modal ) }
30+ title = "Embed Media"
31+ confirmText = "Insert"
32+ onSubmit = { handleSubmit }
33+ onReset = { handleReset }
34+ noValidate
35+ fullWidth
36+ >
37+ < TextField
38+ name = "mediaUrl"
39+ label = "Media URL"
40+ placeholder = "https://youtube.com/..."
41+ value = { url }
42+ error = { ! ! error }
43+ errorText = { error ?? "" }
44+ onChange = { ( e : any ) => {
45+ setError ( null )
46+ setUrl ( e . target . value )
47+ } }
48+ fullWidth
49+ />
50+
51+ { error && < Alert severity = "error" > { error } </ Alert > }
52+ </ FormDialog >
53+ )
54+ } )
55+
56+ export default MediaUrlInputDialog
Original file line number Diff line number Diff line change @@ -15,13 +15,25 @@ export function convertToEmbedUrl(url: string): string {
1515 return videoId ? `https://www.youtube.com/embed/${ videoId } ` : url
1616 }
1717
18- // --- YOUTUBE SHORT ---
18+ // --- YOUTUBE SHORTS ---
19+ if ( hostname === "youtube.com" && parsed . pathname . startsWith ( "/shorts/" ) ) {
20+ const id = parsed . pathname . split ( "/shorts/" ) [ 1 ]
21+ return id ? `https://www.youtube.com/embed/${ id } ` : url
22+ }
23+
24+ // --- YOUTUBE SHORT youtu.be/shorts/??? (rare but possible) ---
25+ if ( hostname === "youtu.be" && parsed . pathname . startsWith ( "/shorts/" ) ) {
26+ const id = parsed . pathname . split ( "/shorts/" ) [ 1 ]
27+ return id ? `https://www.youtube.com/embed/${ id } ` : url
28+ }
29+
30+ // --- YOUTUBE SHORT youtu.be/VIDEO_ID ---
1931 if ( hostname === "youtu.be" ) {
2032 const id = parsed . pathname . slice ( 1 )
2133 return id ? `https://www.youtube.com/embed/${ id } ` : url
2234 }
2335
24- // --- YOUTUBE /embed or other formats keep as is ---
36+ // --- YOUTUBE EMBED (leave as-is) ---
2537 if ( hostname === "youtube.com" && parsed . pathname . startsWith ( "/embed/" ) ) {
2638 return url
2739 }
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import { useCallback, useMemo } from "react"
22import type { Editor } from "@tiptap/react"
33import { useTiptapEditor } from "../../../hooks/use-tiptap-editor"
44import { convertToEmbedUrl } from "./lib"
5+ import NiceModal from "@ebay/nice-modal-react"
6+ import MediaUrlInputDialog from "./MediaUrlInputDialog"
57import { Icon } from "./Icon"
68
79export const MEDIA_EMBED_SHORTCUT_KEY = "Mod+Shift+E"
@@ -14,11 +16,16 @@ export function useMediaEmbed(editor?: Editor | null) {
1416
1517 const label = "Embed Media"
1618
17- const handleEmbed = useCallback ( ( ) => {
18- const url = prompt ( "Enter a media URL (YouTube, Vimeo, etc)" )
19- if ( ! url ) return
19+ const handleEmbed = useCallback ( async ( ) => {
20+ try {
21+ const url : string = await NiceModal . show ( MediaUrlInputDialog )
22+ console . log ( "URL received from modal:" , url )
23+ if ( ! url ) return
2024
21- resolved ?. commands . insertMedia ( convertToEmbedUrl ( url ) )
25+ resolved ?. commands . insertMedia ( convertToEmbedUrl ( url ) )
26+ } catch {
27+ // modal was closed / cancelled
28+ }
2229 } , [ resolved ] )
2330
2431 return {
You can’t perform that action at this time.
0 commit comments