🎥 Make videos programmatically with React
Elements: Add external libraries to Studio (#10770)
Igor Samokhovets815bd06cfe6c
diff --git a/packages/cli/src/config/element-libraries.ts b/packages/cli/src/config/element-libraries.tsnew file mode 100644index 0000000000..d5ba326cf5--- /dev/null+++ b/packages/cli/src/config/element-libraries.ts@@ -0,0 +1,51 @@+import type {StudioElementLibrary} from '@remotion/studio-shared';++let elementLibraries: StudioElementLibrary[] = [];++export const addElementLibrary = (url: string, displayName: string | null) => {+ if (typeof url !== 'string') {+ throw new Error(+ `Config.addElementLibrary() expects a string, got ${typeof url}`,+ );+ }++ let parsedUrl: URL;+ try {+ parsedUrl = new URL(url);+ } catch {+ throw new Error(+ `Config.addElementLibrary() expects an absolute URL, got ${JSON.stringify(url)}`,+ );+ }++ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {+ throw new Error(+ `Config.addElementLibrary() only supports HTTP and HTTPS URLs, got ${JSON.stringify(url)}`,+ );+ }++ if (displayName !== null && typeof displayName !== 'string') {+ throw new Error(+ `Config.addElementLibrary() expects the display name to be a string, got ${typeof displayName}`,+ );+ }++ const trimmedDisplayName = displayName?.trim() ?? null;+ if (trimmedDisplayName === '') {+ throw new Error(+ 'Config.addElementLibrary() expects the display name to not be empty',+ );+ }++ elementLibraries.push({+ displayName: trimmedDisplayName,+ url: parsedUrl.href,+ });+};++export const getElementLibraries = (): readonly StudioElementLibrary[] =>+ elementLibraries;++export const resetElementLibraries = () => {+ elementLibraries = [];+};diff --git a/packages/cli/src/config/index.ts b/packages/cli/src/config/index.tsindex 71b6ae29bb..0308176fa8 100644--- a/packages/cli/src/config/index.ts+++ b/packages/cli/src/config/index.ts@@ -30,6 +30,11 @@ import {} from './buffer-state-delay-in-milliseconds';import type {Concurrency} from './concurrency';import {getConcurrency} from './concurrency';+import {+ addElementLibrary,+ getElementLibraries,+ resetElementLibraries,+} from './element-libraries';import {getEntryPoint, resetEntryPoint, setEntryPoint} from './entry-point';import {getDotEnvLocation} from './env-file';import {@@ -616,6 +621,10 @@ declare global {type FlatConfig = RemotionConfigObject &RemotionBundlingOptions & {+ /**+ * Add an Element library to the Remotion Studio.+ */+ addElementLibrary: (url: string, displayName?: string) => void;/*** Set the audio codec to use for the output video.* See the Encoding guide in the docs for defaults and available options.@@ -755,6 +764,9 @@ export const Config: FlatConfig = {'The config format has changed. Change `Config.Puppeteer.*()` calls to `Config.*()` in your config file.',);},+ addElementLibrary: (url, displayName) => {+ addElementLibrary(url, displayName ?? null);+ },setMaxTimelineTracks: StudioServerInternals.setMaxTimelineTracks,setKeyboardShortcutsEnabled: keyboardShortcutsOption.setConfig,setInteractivityEnabled: interactivityOption.setConfig,@@ -916,6 +928,7 @@ const resetConfigOptions = () => {resetBrowserSafeConfigOptions();StudioServerInternals.resetMaxTimelineTracks();resetBufferStateDelayInMilliseconds();+ resetElementLibraries();resetEntryPoint();resetFfmpegOverrideFunction();resetMetadata();@@ -949,6 +962,7 @@ export const ConfigInternals = {getEntryPoint,getWebpackPolling,getBufferStateDelayInMilliseconds,+ getElementLibraries,getOutputCodecOrUndefined: BrowserSafeApis.getOutputCodecOrUndefined,resetConfigOptions,};diff --git a/packages/cli/src/studio.ts b/packages/cli/src/studio.tsindex c4bcd1236d..b175e01889 100644--- a/packages/cli/src/studio.ts+++ b/packages/cli/src/studio.ts@@ -163,6 +163,7 @@ export const studioCommand = async (askAIEnabled: askAIOption.getValue({commandLine: parsedCli,}).value,+ elementLibraries: ConfigInternals.getElementLibraries(),interactivityEnabled: interactivityOption.getValue({commandLine: parsedCli,}).value,diff --git a/packages/cli/src/test/config-file-change.test.ts b/packages/cli/src/test/config-file-change.test.tsindex b731f6b22d..addcd6ba27 100644--- a/packages/cli/src/test/config-file-change.test.ts+++ b/packages/cli/src/test/config-file-change.test.ts@@ -40,6 +40,12 @@ test('classifies runtime config changes', () => {prepare('Config.setInteractivityEnabled(false);'),),).toBe('runtime');+ expect(+ classify(+ prepare('Config.addElementLibrary("https://one.example.com");'),+ prepare('Config.addElementLibrary("https://two.example.com");'),+ ),+ ).toBe('runtime');});test('classifies changes that require a page reload', () => {diff --git a/packages/cli/src/test/config-reload.test.ts b/packages/cli/src/test/config-reload.test.tsindex 712bed5362..a39c5d7513 100644--- a/packages/cli/src/test/config-reload.test.ts+++ b/packages/cli/src/test/config-reload.test.ts@@ -39,12 +39,19 @@ test('an invalid config reload keeps the previous configuration', async () => {require: createRequire(path.join(__dirname, '..', 'load-config.ts')),});temporaryDirectory = mkdtempSync(path.join(tmpdir(), 'remotion-config-'));+ const initialLibraries = [+ {+ displayName: 'Initial Elements',+ url: 'https://initial.example.com/elements',+ },+ ];writeConfig(- `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(4321); Config.setDefaultEditor('cursor'); Config.setDefaultCodingAgent('codex');`,+ `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(4321); Config.setDefaultEditor('cursor'); Config.setDefaultCodingAgent('codex'); Config.addElementLibrary('https://initial.example.com/elements', 'Initial Elements');`,);await loadConfig(temporaryDirectory);expect(ConfigInternals.getStudioPort()).toBe(4321);+ expect(ConfigInternals.getElementLibraries()).toEqual(initialLibraries);expect(BrowserSafeApis.options.defaultEditorOption.getValue({commandLine: {}}).value,@@ -55,10 +62,11 @@ test('an invalid config reload keeps the previous configuration', async () => {}).value,).toBe('codex');writeConfig(- `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(5678); Config.setDefaultEditor('windsurf'); Config.setDefaultCodingAgent('cursor'); throw new Error('Invalid config');`,+ `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(5678); Config.setDefaultEditor('windsurf'); Config.setDefaultCodingAgent('cursor'); Config.addElementLibrary('https://invalid.example.com/elements', 'Invalid Elements'); throw new Error('Invalid config');`,);expect((await reloadTestConfig()).type).toBe('error');expect(ConfigInternals.getStudioPort()).toBe(4321);+ expect(ConfigInternals.getElementLibraries()).toEqual(initialLibraries);expect(BrowserSafeApis.options.defaultEditorOption.getValue({commandLine: {}}).value,@@ -70,7 +78,7 @@ test('an invalid config reload keeps the previous configuration', async () => {).toBe('codex');writeConfig(- `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(5678); Config.setDefaultEditor('windsurf'); Config.setDefaultCodingAgent('cursor');`,+ `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(5678); Config.setDefaultEditor('windsurf'); Config.setDefaultCodingAgent('cursor'); Config.addElementLibrary('https://snapshot.example.com/elements', 'Snapshot Elements');`,);const snapshotErrorMessage = 'The derived config snapshot was rejected';expect(@@ -82,6 +90,7 @@ test('an invalid config reload keeps the previous configuration', async () => {}),).toEqual({type: 'error', errorMessage: snapshotErrorMessage});expect(ConfigInternals.getStudioPort()).toBe(4321);+ expect(ConfigInternals.getElementLibraries()).toEqual(initialLibraries);expect(BrowserSafeApis.options.defaultEditorOption.getValue({commandLine: {}}).value,@@ -95,12 +104,19 @@ test('an invalid config reload keeps the previous configuration', async () => {writeConfig('this is not valid JavaScript }');expect((await reloadTestConfig()).type).toBe('error');expect(ConfigInternals.getStudioPort()).toBe(4321);+ expect(ConfigInternals.getElementLibraries()).toEqual(initialLibraries);writeConfig(- `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(6789); Config.setDefaultEditor({type: 'custom', name: 'Acme Editor', executable: '/opt/acme/editor', arguments: ['--goto', '%TARGET_PATH%:%LINE_NUMBER%:%COLUMN_NUMBER%']}); Config.setDefaultCodingAgent('claude-code');`,+ `const {Config} = require('@remotion/cli/config'); Config.setStudioPort(6789); Config.setDefaultEditor({type: 'custom', name: 'Acme Editor', executable: '/opt/acme/editor', arguments: ['--goto', '%TARGET_PATH%:%LINE_NUMBER%:%COLUMN_NUMBER%']}); Config.setDefaultCodingAgent('claude-code'); Config.addElementLibrary('https://reloaded.example.com/library', 'Reloaded Elements');`,);expect((await reloadTestConfig()).type).toBe('success');expect(ConfigInternals.getStudioPort()).toBe(6789);+ expect(ConfigInternals.getElementLibraries()).toEqual([+ {+ displayName: 'Reloaded Elements',+ url: 'https://reloaded.example.com/library',+ },+ ]);expect(BrowserSafeApis.options.defaultEditorOption.getValue({commandLine: {}}).value,@@ -120,6 +136,7 @@ test('an invalid config reload keeps the previous configuration', async () => {`const {Config} = require('@remotion/cli/config'); Config.setStudioPort(7890);`,);expect((await reloadTestConfig()).type).toBe('success');+ expect(ConfigInternals.getElementLibraries()).toEqual([]);expect(BrowserSafeApis.options.defaultEditorOption.getValue({commandLine: {}}).value,diff --git a/packages/cli/src/test/config-reset.test.ts b/packages/cli/src/test/config-reset.test.tsindex 5754af8627..f45eb39742 100644--- a/packages/cli/src/test/config-reset.test.ts+++ b/packages/cli/src/test/config-reset.test.ts@@ -12,6 +12,33 @@ test('Studio render defaults keep the startup log level', () => {expect(getRenderDefaults('warn').logLevel).toBe('warn');});+test('Element library configuration must be valid', () => {+ ConfigInternals.resetConfigOptions();++ expect(() => Config.addElementLibrary('/elements')).toThrow(+ 'Config.addElementLibrary() expects an absolute URL',+ );+ expect(() => Config.addElementLibrary('file:///tmp/elements')).toThrow(+ 'Config.addElementLibrary() only supports HTTP and HTTPS URLs',+ );+ expect(() => Config.addElementLibrary(null as unknown as string)).toThrow(+ 'Config.addElementLibrary() expects a string',+ );+ expect(() =>+ Config.addElementLibrary(+ 'https://example.com/elements',+ 123 as unknown as string,+ ),+ ).toThrow(+ 'Config.addElementLibrary() expects the display name to be a string',+ );+ expect(() =>+ Config.addElementLibrary('https://example.com/elements', ' '),+ ).toThrow(+ 'Config.addElementLibrary() expects the display name to not be empty',+ );+});+test('Rspack can be configured using the current and deprecated APIs', () => {ConfigInternals.resetConfigOptions();@@ -35,6 +62,7 @@ test('reset config options restores defaults before reloading config', async ()Config.setStudioPort(4321);Config.setMaxTimelineTracks(123);+ Config.addElementLibrary('https://example.com/elements', 'Example Elements');Config.setChromiumOpenGlRenderer('angle');Config.setCrf(12);Config.setDefaultCodingAgent('codex');@@ -69,6 +97,12 @@ test('reset config options restores defaults before reloading config', async ()expect(ConfigInternals.getStudioPort()).toBe(4321);expect(StudioServerInternals.getMaxTimelineTracks()).toBe(123);+ expect(ConfigInternals.getElementLibraries()).toEqual([+ {+ displayName: 'Example Elements',+ url: 'https://example.com/elements',+ },+ ]);expect(BrowserSafeApis.options.glOption.getValue({commandLine: {}}).value,).toBe('angle');@@ -142,6 +176,7 @@ test('reset config options restores defaults before reloading config', async ()expect(ConfigInternals.getStudioPort()).toBeUndefined();expect(StudioServerInternals.getMaxTimelineTracks()).toBeNull();+ expect(ConfigInternals.getElementLibraries()).toEqual([]);expect(BrowserSafeApis.options.glOption.getValue({commandLine: {}}).value,).toBeNull();diff --git a/packages/docs/docs/config.mdx b/packages/docs/docs/config.mdxindex 8e80d6ed18..fd5f754f6a 100644--- a/packages/docs/docs/config.mdx+++ b/packages/docs/docs/config.mdx@@ -193,6 +193,22 @@ Config.setLogLevel('verbose');The [command line flag](/docs/cli/render#--log) `--log` will take precedence over this option.+## `addElementLibrary()`<AvailableFrom v="4.0.517" />++Adds an externally hosted Element library to Remotion Studio.++```ts twoslash title="remotion.config.ts"+import {Config} from '@remotion/cli/config';+// ---cut---+Config.addElementLibrary('https://example.com/elements', 'Acme Elements');+```++Call `addElementLibrary()` once for each external library. The second argument sets its display name. If it is omitted, the URL host and path are shown instead.++When at least one library is configured, Browse Elements shows a dropdown containing Remotion Elements and every configured library. All libraries open in an embedded Studio modal.++The URL must be an absolute HTTP or HTTPS URL. Remotion Elements remains available without adding it to the configuration.+## `setMaxTimelineTracks()`<AvailableFrom v="2.1.10" />Set how many tracks are displayed in the Studio timeline at most. This does not affect your video, only the number of tracks shown while previewing. From <AvailableFrom v="4.0.514" inline />, all tracks are available by default and the timeline is virtualized.diff --git a/packages/example/e2e/studio-protocol.test.mts b/packages/example/e2e/studio-protocol.test.mtsindex ed26e67dab..637b4b020d 100644--- a/packages/example/e2e/studio-protocol.test.mts+++ b/packages/example/e2e/studio-protocol.test.mts@@ -78,6 +78,14 @@ export const MyComponent = () => {};`,);+ const externalLibraryUrl = 'https://external-elements.example.com/library';+ const reloadedExternalLibraryUrl =+ 'https://second-elements.example.com/components';+ const configFile = path.join(temporaryProject, 'remotion.config.ts');+ fs.appendFileSync(+ configFile,+ `\nConfig.addElementLibrary('${externalLibraryUrl}', 'External Elements');\n`,+ );fs.rmSync(path.join(temporaryProject, 'node_modules'), {force: true,recursive: true,@@ -162,10 +170,18 @@ export const MyComponent = () => {}const senderUrl = `http://127.0.0.1:${address.port}`;- const elementsLibraryRequests: string[] = [];+ const officialLibraryRequests: string[] = [];+ const externalLibraryRequests: string[] = [];const context = await browser.newContext();await context.route('https://www.remotion.dev/elements', async (route) => {- elementsLibraryRequests.push(route.request().url());+ officialLibraryRequests.push(route.request().url());+ await route.fulfill({+ status: 302,+ headers: {Location: senderUrl},+ });+ });+ await context.route(externalLibraryUrl, async (route) => {+ externalLibraryRequests.push(route.request().url());await route.fulfill({status: 302,headers: {Location: senderUrl},@@ -213,21 +229,55 @@ export const MyComponent = () => {});await expect(browseElements).toBeVisible();await browseElements.click();- const elementsIframe = studioPage.locator(+ const officialLibraryItem = studioPage.getByRole('button', {+ name: 'Remotion Elements',+ exact: true,+ });+ const externalLibraryLabel = 'External Elements';+ const externalLibraryItem = studioPage.getByRole('button', {+ name: externalLibraryLabel,+ exact: true,+ });+ await expect(officialLibraryItem).toBeVisible();+ await expect(externalLibraryItem).toBeVisible();+ await officialLibraryItem.click();++ const officialElementsIframe = studioPage.locator('iframe[title="Remotion Elements library"]',);+ await expect(officialElementsIframe).toBeVisible();+ expect(officialLibraryRequests).toEqual([+ 'https://www.remotion.dev/elements',+ ]);+ expect(context.pages()).toHaveLength(2);+ await studioPage.keyboard.press('Escape');+ await expect(officialElementsIframe).toHaveCount(0);++ fs.appendFileSync(+ configFile,+ `Config.addElementLibrary('${reloadedExternalLibraryUrl}');\n`,+ );+ await browseElements.click();+ await expect(+ studioPage.getByRole('button', {+ name: 'second-elements.example.com/components',+ exact: true,+ }),+ ).toBeVisible({timeout: 30_000});+ await externalLibraryItem.click();+ const elementsIframe = studioPage.locator(+ `iframe[title="${externalLibraryLabel} library"]`,+ );await expect(elementsIframe).toBeVisible();await expect(elementsIframe).toHaveAttribute('allow','local-network-access; loopback-network',);await expect(elementsIframe).toHaveAttribute('credentialless', '');+ expect(externalLibraryRequests).toEqual([externalLibraryUrl]);expect(context.pages()).toHaveLength(2);- expect(elementsLibraryRequests).toEqual([- 'https://www.remotion.dev/elements',- ]);const elementsFrame = studioPage.frameLocator(- 'iframe[title="Remotion Elements library"]',+ `iframe[title="${externalLibraryLabel} library"]`,);const installInStudio = elementsFrame.getByRole('button', {name: 'Install in Studio',diff --git a/packages/example/remotion.config.ts b/packages/example/remotion.config.tsindex 9acaf825e8..1751343a07 100644--- a/packages/example/remotion.config.ts+++ b/packages/example/remotion.config.ts@@ -10,3 +10,4 @@ Config.overrideBundlerConfig(async (config) => {return bundlerOverride(config);});Config.setEnableCrossSiteIsolation(true);+Config.addElementLibrary('https://remocn.dev/docs/typography', 'Remocn');diff --git a/packages/studio-shared/src/config-method-lifecycles.ts b/packages/studio-shared/src/config-method-lifecycles.tsindex 40f74173c6..2b7efbb83f 100644--- a/packages/studio-shared/src/config-method-lifecycles.ts+++ b/packages/studio-shared/src/config-method-lifecycles.ts@@ -1,6 +1,7 @@import type {ConfigFileChangeType} from './config-file-change';export const configMethodLifecycles = {+ addElementLibrary: 'runtime',overrideBundlerConfig: 'restart',overrideDuration: 'runtime',overrideFfmpegCommand: 'runtime',diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.tsindex f9864c3fb6..67d849227b 100644--- a/packages/studio-shared/src/index.ts+++ b/packages/studio-shared/src/index.ts@@ -363,6 +363,7 @@ export {export {studioHtml, type StudioHtmlOptions} from './studio-html';export type {ConfigFileStudioSettings,+ StudioElementLibrary,StudioRuntimeConfig,} from './studio-runtime-config';export {diff --git a/packages/studio-shared/src/studio-runtime-config.ts b/packages/studio-shared/src/studio-runtime-config.tsindex 192449877d..e2fba2c1b4 100644--- a/packages/studio-shared/src/studio-runtime-config.ts+++ b/packages/studio-shared/src/studio-runtime-config.ts@@ -17,9 +17,15 @@ export type ConfigFileStudioSettings = {readonly rspack: boolean | null;};+export type StudioElementLibrary = {+ readonly displayName: string | null;+ readonly url: string;+};+export type StudioRuntimeConfig = {readonly maxTimelineTracks: number | null;readonly askAIEnabled: boolean;+ readonly elementLibraries?: readonly StudioElementLibrary[];readonly interactivityEnabled: boolean;readonly keyboardShortcutsEnabled: boolean;readonly bufferStateDelayInMilliseconds: number | null;diff --git a/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx b/packages/studio/src/components/InspectorPanel/CompositionInspector.tsxindex bc4c6d30cb..04efe18751 100644--- a/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx+++ b/packages/studio/src/components/InspectorPanel/CompositionInspector.tsx@@ -8,15 +8,12 @@ import React, {import type {_InternalTypes} from 'remotion';import {getBrowserStudioOperations} from '../../helpers/browser-studio-operations';import {StudioServerConnectionCtx} from '../../helpers/client-id';-import {CURRENT_COLOR} from '../../helpers/colors';import {downloadBlob} from '../../helpers/download-blob';import {isStudioInteractivityEnabled} from '../../helpers/interactivity-enabled';-import {BrowseElementsIcon} from '../../icons/browse-elements';import {CloudDownloadIcon} from '../../icons/cloud-download';import {PicIcon} from '../../icons/frame';import {SolidIcon} from '../../icons/solid';import {FilmIcon} from '../../icons/video';-import {SetSelectedModalContext} from '../../state/modals';import {VisualControlsContext} from '../../visual-controls/VisualControls';import {DefaultPropsEditor} from '../DefaultPropsEditor';import {useZodIfPossible, useZodTypesIfPossible} from '../get-zod-if-possible';@@ -45,6 +42,7 @@ import {} from './common';import {CompositionInspectorHeader} from './CompositionInspectorHeader';import {CompositionMetadata} from './CompositionMetadata';+import {ElementLibraryButton} from './ElementLibraryButton';import {compositionDefaultPropsSection,compositionVisualControlsSection,@@ -63,26 +61,6 @@ const actionIconStyle: React.CSSProperties = {width: 18,};-const browseElementsIconStyle: React.CSSProperties = {- height: 22,- width: 22,-};--const browseElementsIconContainerStyle: React.CSSProperties = {- height: 22,- marginLeft: -2,- marginRight: -2,- width: 22,-};--const browseElementsArrowStyle: React.CSSProperties = {- display: 'inline-block',- height: 12,- marginLeft: 4,- verticalAlign: -2,- width: 12,-};-const CompositionActions: React.FC = () => {const {canInsertAsset,@@ -95,10 +73,7 @@ const CompositionActions: React.FC = () => {insertComposition,insertSolid,} = useCompositionActions();- const {setSelectedModal} = useContext(SetSelectedModalContext);- const browserStudioOperations = getBrowserStudioOperations();- const downloadProject = browserStudioOperations?.downloadProject ?? null;- const isBrowserStudio = browserStudioOperations !== null;+ const downloadProject = getBrowserStudioOperations()?.downloadProject ?? null;const onDownloadProject = useCallback(async () => {if (downloadProject === null) {@@ -125,23 +100,6 @@ const CompositionActions: React.FC = () => {}}, [downloadProject]);- const openElementsLibrary = useCallback(() => {- if (isBrowserStudio) {- window.open(- 'https://www.remotion.dev/elements',- '_blank',- 'noopener,noreferrer',- );- return;- }-- setSelectedModal({- type: 'element-library',- name: 'Remotion Elements',- url: 'https://www.remotion.dev/elements',- });- }, [isBrowserStudio, setSelectedModal]);-if (!canShowInsertAsset &&!canShowInsertComposition &&@@ -186,39 +144,7 @@ const CompositionActions: React.FC = () => {Add composition...</InspectorQuickAction>) : null}- {canShowInsertAsset ? (- <InspectorQuickAction- disabled={false}- iconContainerStyle={browseElementsIconContainerStyle}- onClick={openElementsLibrary}- renderIcon={(color) => (- <BrowseElementsIcon color={color} style={browseElementsIconStyle} />- )}- title={- isBrowserStudio- ? 'Open the Remotion Elements library in a new tab. Install an Element there to send it to this composition.'- : 'Browse the Remotion Elements library inside Studio.'- }- >- Browse Elements- {isBrowserStudio ? (- <svg- aria-hidden="true"- viewBox="0 0 16 16"- style={browseElementsArrowStyle}- >- <path- d="M4 12 12 4M6 4h6v6"- fill="none"- stroke={CURRENT_COLOR}- strokeLinecap="round"- strokeLinejoin="round"- strokeWidth="1.5"- />- </svg>- ) : null}- </InspectorQuickAction>- ) : null}+ {canShowInsertAsset ? <ElementLibraryButton /> : null}{downloadProject ? (<InspectorQuickActiondisabled={false}diff --git a/packages/studio/src/components/InspectorPanel/ElementLibraryButton.tsx b/packages/studio/src/components/InspectorPanel/ElementLibraryButton.tsxnew file mode 100644index 0000000000..82843c270c--- /dev/null+++ b/packages/studio/src/components/InspectorPanel/ElementLibraryButton.tsx@@ -0,0 +1,208 @@+import React, {useCallback, useContext, useMemo} from 'react';+import {getBrowserStudioOperations} from '../../helpers/browser-studio-operations';+import {CURRENT_COLOR, LIGHT_TEXT} from '../../helpers/colors';+import {BrowseElementsIcon} from '../../icons/browse-elements';+import {CaretDown} from '../../icons/caret';+import {SetSelectedModalContext} from '../../state/modals';+import {INSPECTOR_PANEL_HORIZONTAL_PADDING} from '../InspectorPanelLayout';+import type {SegmentedButtonSegment} from '../SegmentedButton';+import {SegmentedButton} from '../SegmentedButton';+import {useSettings} from '../SettingsContext';+import {InspectorQuickAction} from './common';++const noElementLibraries = [] as const;++const browseElementsIconStyle: React.CSSProperties = {+ height: 22,+ width: 22,+};++const browseElementsIconContainerStyle: React.CSSProperties = {+ height: 22,+ marginLeft: -2,+ marginRight: -2,+ width: 22,+};++const browseElementsArrowStyle: React.CSSProperties = {+ display: 'inline-block',+ height: 12,+ marginLeft: 4,+ verticalAlign: -2,+ width: 12,+};++const elementLibraryDropdownStyle: React.CSSProperties = {+ borderRadius: 4,+ height: 28,+ margin: '0 4px',+ width: 'calc(100% - 8px)',+};++const elementLibraryDropdownSegmentStyle: React.CSSProperties = {+ fontSize: 13,+ gap: 8,+ justifyContent: 'flex-start',+ padding: `0 ${INSPECTOR_PANEL_HORIZONTAL_PADDING - 4}px`,+ width: '100%',+};++const elementLibraryDropdownLabelStyle: React.CSSProperties = {+ flex: 1,+ fontFamily: 'sans-serif',+ fontSize: 13,+ lineHeight: '18px',+ minWidth: 0,+ overflow: 'hidden',+ textAlign: 'left',+ textOverflow: 'ellipsis',+ whiteSpace: 'nowrap',+};++const elementLibraryDropdownCaretStyle: React.CSSProperties = {+ display: 'flex',+ height: 12,+ width: 12,+};++export const ElementLibraryButton: React.FC = () => {+ const {setSelectedModal} = useContext(SetSelectedModalContext);+ const {studioRuntimeConfig} = useSettings();+ const isBrowserStudio = getBrowserStudioOperations() !== null;+ const elementLibraries =+ studioRuntimeConfig?.elementLibraries ?? noElementLibraries;++ const openElementLibrary = useCallback(+ (name: string, url: string) => {+ if (isBrowserStudio) {+ window.open(url, '_blank', 'noopener,noreferrer');+ return;+ }++ setSelectedModal({+ type: 'element-library',+ name,+ url,+ });+ },+ [isBrowserStudio, setSelectedModal],+ );++ const openElementsLibrary = useCallback(() => {+ openElementLibrary(+ 'Remotion Elements',+ 'https://www.remotion.dev/elements',+ );+ }, [openElementLibrary]);++ const elementLibraryDropdownSegments = useMemo<SegmentedButtonSegment[]>(+ () => [+ {+ ariaLabel: 'Browse Elements',+ buttonId: null,+ disabled: false,+ idleColor: LIGHT_TEXT,+ leaveLeftSpace: false,+ onOpenChange: null,+ renderContent: (color) => (+ <>+ <span style={browseElementsIconContainerStyle}>+ <BrowseElementsIcon+ color={color}+ style={browseElementsIconStyle}+ />+ </span>+ <span style={elementLibraryDropdownLabelStyle}>+ Browse Elements+ </span>+ <span style={elementLibraryDropdownCaretStyle}>+ <CaretDown color={color} />+ </span>+ </>+ ),+ segmentId: 'element-library',+ selectedId: null,+ style: elementLibraryDropdownSegmentStyle,+ title: 'Choose an Element library to browse inside Studio.',+ type: 'menu',+ values: [+ {+ disabled: false,+ id: 'remotion-elements',+ keyHint: null,+ label: 'Remotion Elements',+ leftItem: null,+ onClick: openElementsLibrary,+ quickSwitcherLabel: null,+ subMenu: null,+ type: 'item',+ value: 'https://www.remotion.dev/elements',+ },+ ...elementLibraries.map((library, index) => {+ const parsedUrl = new URL(library.url);+ const pathname = parsedUrl.pathname.replace(/\/$/, '');+ const label = library.displayName ?? `${parsedUrl.host}${pathname}`;++ return {+ disabled: false,+ id: `external-element-library-${index}`,+ keyHint: null,+ label,+ leftItem: null,+ onClick: () => openElementLibrary(label, library.url),+ quickSwitcherLabel: null,+ subMenu: null,+ type: 'item' as const,+ value: library.url,+ };+ }),+ ],+ },+ ],+ [elementLibraries, openElementLibrary, openElementsLibrary],+ );++ if (elementLibraries.length > 0 && !isBrowserStudio) {+ return (+ <SegmentedButton+ segments={elementLibraryDropdownSegments}+ style={elementLibraryDropdownStyle}+ title={null}+ />+ );+ }++ return (+ <InspectorQuickAction+ disabled={false}+ iconContainerStyle={browseElementsIconContainerStyle}+ onClick={openElementsLibrary}+ renderIcon={(color) => (+ <BrowseElementsIcon color={color} style={browseElementsIconStyle} />+ )}+ title={+ isBrowserStudio+ ? 'Open the Remotion Elements library in a new tab. Install an Element there to send it to this composition.'+ : 'Browse the Remotion Elements library inside Studio.'+ }+ >+ Browse Elements+ {isBrowserStudio ? (+ <svg+ aria-hidden="true"+ viewBox="0 0 16 16"+ style={browseElementsArrowStyle}+ >+ <path+ d="M4 12 12 4M6 4h6v6"+ fill="none"+ stroke={CURRENT_COLOR}+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ </svg>+ ) : null}+ </InspectorQuickAction>+ );+};