import { XMarkIcon } from "@heroicons/react/16/solid"; import { setStudioDragData, type AddElementLibraryToStudioErrorCode, type InstallInStudioErrorCode, } from "@remotion/studio-protocol"; import { useEffect, useId, useRef, useState, type RefObject } from "react"; import { createPortal } from "react-dom"; import type { CatalogEntry } from "../../lib/element-payload"; export type StudioFailure = { code: AddElementLibraryToStudioErrorCode | InstallInStudioErrorCode | null; message: string; }; export const StudioInstallFallback = ({ entry, failure, failureCount, isPending, onRetry, onClose, triggerRef, }: { entry: CatalogEntry | null; failure: StudioFailure | null; failureCount: number; isPending: boolean; onRetry: () => void; onClose: () => void; triggerRef: RefObject; }) => { const dialogRef = useRef(null); const titleId = useId(); const [copyStatus, setCopyStatus] = useState(""); const libraryUrl = new URL("/", window.location.origin).href; useEffect(() => { const dialog = dialogRef.current; const trigger = triggerRef.current; if (!dialog) return; dialog.showModal(); return () => { dialog.close(); window.requestAnimationFrame(() => { if (trigger?.isConnected && !dialog.open) trigger.focus(); }); }; }, [triggerRef]); useEffect(() => { if (copyStatus !== "Copied.") return; const timeout = window.setTimeout(() => setCopyStatus(""), 2000); return () => window.clearTimeout(timeout); }, [copyStatus]); return createPortal( { event.preventDefault(); onClose(); }} onClick={(event) => { if (event.target !== event.currentTarget) return; const bounds = event.currentTarget.getBoundingClientRect(); if ( event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom ) onClose(); }} >

{entry ? "Use this Element" : "Add Studio Supply to Studio"}

{isPending ? (

Finding a compatible Remotion Studio…

) : failure?.code === "no-compatible-studio" ? (

Remotion Studio is the video editor for your Remotion project. Open an existing project or{" "} create your first Remotion project , and{" "} install and open Remotion Studio . Once Studio is running, return here and try again.

) : failure?.code === "no-installable-target" ? (

Focus the{" "} Remotion Studio {" "} tab you want to install into, then try again.{" "} Learn how to add Elements to your video.

) : failure?.code === "no-configurable-target" ? (

Open Remotion Studio {" "} for your local project and switch to its browser tab, then try again.

) : failure?.code === "studio-upgrade-required" ? (

{failure.message}{" "} How to upgrade Remotion.

) : (

{failure?.message}

)}
{entry ? ( <>

{failureCount > 1 ? "Still not connecting? Drag the button above into your Studio instead." : "You can also drag the button above into your Studio."}

Or copy the source code and create a new TSX file in your project.

) : (

Add manually

In your local Studio, open{" "} Settings, select{" "} Elements, then choose Add by URL{" "} and paste this URL:

event.currentTarget.select()} className="w-full min-w-0 rounded-md border border-neutral-950/15 px-3 py-2 font-mono focus-visible:-outline-offset-1 sm:flex-1" />

Then click{" "} + Add Element Library {" "} in Studio.

You can also add this URL to remotion.config.ts using{" "} Config.addElementLibrary() . To include caption styles, also set captionStylesUrl{" "} to{" "} {new URL("/captions", window.location.origin).href} .

)}

{copyStatus}

, document.body, ); };