🎥 Make videos programmatically with React
@remotion/studio: Restore Source Inspector asset actions
Jonny Burgerca704c8c9aa6
diff --git a/packages/studio/src/components/AssetSelectorItem.tsx b/packages/studio/src/components/AssetSelectorItem.tsxindex f809d0eacf..9e6a1c3693 100644--- a/packages/studio/src/components/AssetSelectorItem.tsx+++ b/packages/studio/src/components/AssetSelectorItem.tsx@@ -31,7 +31,6 @@ import {NO_HOVER_BACKGROUND_STYLE,hoverableStyle,} from '../helpers/hoverable';-import {openInRemotionConvert} from '../helpers/open-in-remotion-convert';import {markAssetSidebarScrollFromRowClick,maybeScrollAssetSidebarRowIntoView,@@ -44,7 +43,10 @@ import {getCachedImageMetadata} from '../helpers/use-image-metadata';import {getCachedMediaMetadata} from '../helpers/use-media-metadata';import {EllipsisIcon} from '../icons/ellipsis';import {CollapsedFolderIcon, ExpandedFolderIcon} from '../icons/folder';-import {SetSelectedModalContext} from '../state/modals';+import {+ getAssetActionAvailability,+ useAssetContextMenuItems,+} from './asset-context-menu';import {AssetFileIcon} from './AssetFileIcon';import {ContextMenu} from './ContextMenu';import {getAssetElementFromPath} from './import-assets';@@ -54,9 +56,12 @@ import {InlineDropdown} from './InlineDropdown';import {COMPACT_CONTROL_ROW_HEIGHT, Row, Spacing} from './layout';import type {ComboboxValue} from './NewComposition/ComboBox';import {showNotification} from './Notifications/NotificationCenter';-import {getOpenInNewWindowMenuItem} from './open-in-new-window';import {openInFileExplorer} from './RenderQueue/actions';-import {useDeleteAsset} from './use-delete-asset';++export {+ getAssetActionAvailability,+ getAssetContextMenuItems,+} from './asset-context-menu';const iconStyle: React.CSSProperties = {width: 18,@@ -114,29 +119,6 @@ const renderContextMenuAction: RenderInlineAction = (color) => {return <EllipsisIcon svgProps={ellipsisIconStyle} fill={color} />;};-export const getAssetActionAvailability = ({- browserStudioCanMutateAssets,- readOnlyStudio,- connectionStatus,- publicFolderExists,-}: {- browserStudioCanMutateAssets: boolean | null;- readOnlyStudio: boolean;- connectionStatus: 'init' | 'connected' | 'disconnected';- publicFolderExists: string | null;-}) => {- return {- mutationsDisabled:- browserStudioCanMutateAssets !== true &&- (readOnlyStudio || connectionStatus !== 'connected'),- fileExplorerDisabled:- browserStudioCanMutateAssets !== null ||- publicFolderExists === null ||- readOnlyStudio ||- connectionStatus !== 'connected',- };-};-export const getCanDragAsset = ({readOnlyStudio,relativePath,@@ -147,137 +129,6 @@ export const getCanDragAsset = ({return !readOnlyStudio && getAssetElementFromPath(relativePath) !== null;};-export const getAssetContextMenuItems = ({- relativePath,- fileManagerName,- copyFileName,- copyStaticFilePath,- copyAbsolutePath,- openAssetInConvert,- openAssetInExplorer,- renameAsset,- deleteAsset,- fileExplorerAvailable,- fileExplorerDisabled,- mutationsDisabled,-}: {- relativePath: string;- fileManagerName: string;- copyFileName: () => void;- copyStaticFilePath: () => void;- copyAbsolutePath: (() => void) | null;- openAssetInConvert: () => void;- openAssetInExplorer: () => void;- renameAsset: () => void;- deleteAsset: () => void;- fileExplorerAvailable: boolean;- fileExplorerDisabled: boolean;- mutationsDisabled: boolean;-}): ComboboxValue[] => {- const previewFileType = getPreviewFileType(relativePath);- const canOpenInConvert =- previewFileType === 'audio' || previewFileType === 'video';- const items: (ComboboxValue | null)[] = [- getOpenInNewWindowMenuItem(`/assets/${relativePath}`),- canOpenInConvert- ? {- id: 'open-asset-in-convert',- keyHint: null,- label: 'Open in Remotion Convert',- leftItem: null,- onClick: openAssetInConvert,- quickSwitcherLabel: 'Open asset in Remotion Convert',- subMenu: null,- type: 'item',- value: 'open-asset-in-convert',- }- : null,- {- type: 'divider',- id: 'open-in-new-window-divider',- },- {- id: 'copy-asset-file-name',- keyHint: null,- label: 'Copy file name',- leftItem: null,- onClick: copyFileName,- quickSwitcherLabel: 'Copy asset file name',- subMenu: null,- type: 'item',- value: 'copy-asset-file-name',- },- {- id: 'copy-asset-static-file-path',- keyHint: null,- label: 'Copy staticFile() path',- leftItem: null,- onClick: copyStaticFilePath,- quickSwitcherLabel: 'Copy staticFile() path',- subMenu: null,- type: 'item',- value: 'copy-asset-static-file-path',- },- copyAbsolutePath- ? {- id: 'copy-asset-absolute-path',- keyHint: null,- label: 'Copy absolute path',- leftItem: null,- onClick: copyAbsolutePath,- quickSwitcherLabel: 'Copy asset absolute path',- subMenu: null,- type: 'item',- value: 'copy-asset-absolute-path',- }- : null,- {- type: 'divider',- id: 'asset-file-actions-divider',- },- fileExplorerAvailable- ? {- id: 'open-asset-in-explorer',- keyHint: null,- label: `Show in ${fileManagerName}`,- leftItem: null,- onClick: openAssetInExplorer,- quickSwitcherLabel: `Show asset in ${fileManagerName}`,- subMenu: null,- type: 'item',- value: 'open-asset-in-explorer',- disabled: fileExplorerDisabled,- }- : null,- {- id: 'rename-asset',- keyHint: null,- label: 'Rename...',- leftItem: null,- onClick: renameAsset,- quickSwitcherLabel: 'Rename asset...',- subMenu: null,- type: 'item',- value: 'rename-asset',- disabled: mutationsDisabled,- },- {- id: 'delete-asset',- keyHint: null,- label: 'Delete...',- leftItem: null,- onClick: deleteAsset,- quickSwitcherLabel: 'Delete asset...',- subMenu: null,- type: 'item',- value: 'delete-asset',- disabled: mutationsDisabled,- },- ];-- return items.filter(NoReactInternals.truthy);-};-export const getAssetFolderContextMenuItems = ({folderPath,fileManagerName,@@ -640,19 +491,18 @@ const AssetSelectorItem: React.FC<{readonly parentFolder: string;readonly readOnlyStudio: boolean;}> = ({item, tabIndex, level, parentFolder, readOnlyStudio}) => {- const fileManagerName = getFileManagerName(- window.remotion_fileSystemPlatform,- );const [isDragging, setIsDragging] = useState(false);- const {setSelectedModal} = useContext(SetSelectedModalContext);- const connectionStatus = useContext(StudioServerConnectionCtx)- .previewServerState.type;const {setCanvasContent} = useContext(Internals.CompositionSetters);const {canvasContent} = useContext(Internals.CompositionManager);const relativePath = useMemo(() => {return parentFolder ? parentFolder + '/' + item.name : item.name;}, [parentFolder, item.name]);+ const {fileExplorerDisabled, fileManagerName, getContextMenuItems} =+ useAssetContextMenuItems({+ relativePath,+ readOnlyStudio,+ });const previewFileType = useMemo(() => {return getPreviewFileType(relativePath);}, [relativePath]);@@ -749,46 +599,6 @@ const AssetSelectorItem: React.FC<{return <ExpandedFolderIcon style={revealIconStyle} color={color} />;}, []);- const copyFileName = useCallback(() => {- copyText(item.name)- .then(() => {- showNotification(`Copied '${item.name}' to clipboard`, 1000);- })- .catch((err) => {- showNotification(`Could not copy: ${err.message}`, 2000);- });- }, [item.name]);-- const copyStaticFilePath = useCallback(() => {- const content = `staticFile("${relativePath}")`;- copyText(content)- .then(() => {- showNotification(`Copied '${content}' to clipboard`, 1000);- })- .catch((err) => {- showNotification(`Could not copy: ${err.message}`, 2000);- });- }, [relativePath]);-- const copyAbsolutePath = useCallback(() => {- if (window.remotion_publicFolderExists === null) {- return;- }-- const content = `${window.remotion_publicFolderExists}/${relativePath}`;- copyText(content)- .then(() => {- showNotification(`Copied '${content}' to clipboard`, 1000);- })- .catch((err) => {- showNotification(`Could not copy: ${err.message}`, 2000);- });- }, [relativePath]);-- const openAssetInConvert = useCallback(() => {- openInRemotionConvert({relativePath});- }, [relativePath]);-const openAssetInExplorer = useCallback(() => {if (!window.remotion_publicFolderExists) {showNotification('Could not find the public folder', 2000);@@ -802,53 +612,6 @@ const AssetSelectorItem: React.FC<{});}, [relativePath]);- const {mutationsDisabled, fileExplorerDisabled} = getAssetActionAvailability({- browserStudioCanMutateAssets:- getBrowserStudioOperations() === null ? null : true,- readOnlyStudio,- connectionStatus,- publicFolderExists: window.remotion_publicFolderExists,- });-- const deleteAsset = useDeleteAsset(relativePath);-- const renameAsset = useCallback(() => {- setSelectedModal({- type: 'rename-static-file',- relativePath,- });- }, [relativePath, setSelectedModal]);-- const getContextMenuItems = useCallback((): ComboboxValue[] => {- return getAssetContextMenuItems({- relativePath,- fileManagerName,- copyFileName,- copyStaticFilePath,- copyAbsolutePath:- window.remotion_publicFolderExists === null ? null : copyAbsolutePath,- openAssetInConvert,- openAssetInExplorer,- renameAsset,- deleteAsset,- fileExplorerAvailable: getBrowserStudioOperations() === null,- fileExplorerDisabled,- mutationsDisabled,- });- }, [- copyFileName,- copyStaticFilePath,- copyAbsolutePath,- deleteAsset,- fileExplorerDisabled,- fileManagerName,- mutationsDisabled,- openAssetInConvert,- openAssetInExplorer,- renameAsset,- relativePath,- ]);-const revealInExplorer: React.MouseEventHandler<HTMLButtonElement> =useCallback((e) => {diff --git a/packages/studio/src/components/Timeline/TimelineAssetField.tsx b/packages/studio/src/components/Timeline/TimelineAssetField.tsxindex bb9a2e42d2..17184d12e7 100644--- a/packages/studio/src/components/Timeline/TimelineAssetField.tsx+++ b/packages/studio/src/components/Timeline/TimelineAssetField.tsx@@ -15,6 +15,8 @@ import type {} from '../../helpers/timeline-layout';import {PenIcon} from '../../icons/pen';import {SetSelectedModalContext} from '../../state/modals';+import {useAssetContextMenuItems} from '../asset-context-menu';+import {ContextMenu} from '../ContextMenu';import {pickFilesToImport} from '../import-assets';import {InlineAction} from '../InlineAction';import {@@ -62,6 +64,14 @@ const imageAssetField: React.CSSProperties = {padding: '4px 12px',};+const imageAssetPreview: React.CSSProperties = {+ alignItems: 'center',+ display: 'flex',+ flex: 1,+ gap: 8,+ minWidth: 0,+};+const thumbnailButton: React.CSSProperties = {...hoverableStyle({idleBackground: TRANSPARENT,@@ -170,6 +180,17 @@ export const TimelineAssetField: React.FC<TimelineAssetFieldProps> = ({const {getSourceAction, sourceAction} = useContext(AssetSelectionContext);const {assetType} = field.fieldSchema;const initialQuery = assetType ? `type:${assetType} ` : '';+ const imageLinkInfo =+ assetType === 'image' && typeof effectiveValue === 'string'+ ? getTimelineAssetLinkInfo(effectiveValue)+ : null;+ const localAssetPath =+ imageLinkInfo?.kind === 'local' ? imageLinkInfo.assetPath : null;+ const {getContextMenuItems: getLocalAssetContextMenuItems} =+ useAssetContextMenuItems({+ relativePath: localAssetPath,+ readOnlyStudio: window.remotion_isReadOnlyStudio,+ });const inlineSourceAction = useMemo(() => {if (typeof effectiveValue === 'string') {return getSourceAction(effectiveValue);@@ -302,64 +323,87 @@ export const TimelineAssetField: React.FC<TimelineAssetFieldProps> = ({/>);- if (assetType === 'image' && typeof effectiveValue === 'string') {- const linkInfo = getTimelineAssetLinkInfo(effectiveValue);- if (linkInfo !== null) {- let name: string;- let source: string | null;- let previewSrc: string;- if (linkInfo.kind === 'local') {- name = linkInfo.assetPath.split('/').pop() ?? linkInfo.assetPath;- source = null;- previewSrc = staticFile(linkInfo.assetPath);- } else {- previewSrc = linkInfo.href.startsWith('//')- ? `https:${linkInfo.href}`- : linkInfo.href;- try {- const url = new URL(previewSrc);- const encodedName = url.pathname.split('/').filter(Boolean).pop();- name = encodedName ? decodeURIComponent(encodedName) : url.hostname;- source = url.hostname;- } catch {- name = 'Remote image';- source = linkInfo.href;- }+ if (imageLinkInfo !== null) {+ const linkInfo = imageLinkInfo;+ let name: string;+ let source: string | null;+ let previewSrc: string;+ if (linkInfo.kind === 'local') {+ name = linkInfo.assetPath.split('/').pop() ?? linkInfo.assetPath;+ source = null;+ previewSrc = staticFile(linkInfo.assetPath);+ } else {+ previewSrc = linkInfo.href.startsWith('//')+ ? `https:${linkInfo.href}`+ : linkInfo.href;+ try {+ const url = new URL(previewSrc);+ const encodedName = url.pathname.split('/').filter(Boolean).pop();+ name = encodedName ? decodeURIComponent(encodedName) : url.hostname;+ source = url.hostname;+ } catch {+ name = 'Remote image';+ source = linkInfo.href;}+ }- const title = inlineSourceAction?.title ?? linkInfo.title;-- return (- <div style={imageAssetField}>- <button- aria-label={`Replace ${name}`}- className={`${HOVERABLE_CLASS_NAME} ${FOCUS_VISIBLE_ONLY_CLASS_NAME}`}- disabled={window.remotion_isReadOnlyStudio}- onClick={openAssetSelection}- style={thumbnailButton}- title={title}- type="button"- >- <img alt="" draggable={false} src={previewSrc} style={thumbnail} />- </button>- <button- aria-label={`Replace ${name}`}- className={`${HOVERABLE_CLASS_NAME} ${FOCUS_VISIBLE_ONLY_CLASS_NAME}`}- disabled={window.remotion_isReadOnlyStudio}- onClick={openAssetSelection}- style={imageAssetInfo}- title={title}- type="button"+ const opensSource =+ linkInfo.kind === 'local' &&+ inlineSourceAction !== null &&+ inlineSourceAction.onClick !== null;+ const title = inlineSourceAction?.title ?? linkInfo.title;+ const onPreviewClick = opensSource+ ? inlineSourceAction.onClick+ : openAssetSelection;+ const previewLabel = `${opensSource ? 'Open' : 'Replace'} ${name}`;+ const previewDisabled = opensSource+ ? inlineSourceAction.disabled+ : window.remotion_isReadOnlyStudio;+ const previewAction = (+ <>+ <button+ aria-label={previewLabel}+ className={`${HOVERABLE_CLASS_NAME} ${FOCUS_VISIBLE_ONLY_CLASS_NAME}`}+ disabled={previewDisabled}+ onClick={onPreviewClick}+ style={thumbnailButton}+ title={title}+ type="button"+ >+ <img alt="" draggable={false} src={previewSrc} style={thumbnail} />+ </button>+ <button+ aria-label={previewLabel}+ className={`${HOVERABLE_CLASS_NAME} ${FOCUS_VISIBLE_ONLY_CLASS_NAME}`}+ disabled={previewDisabled}+ onClick={onPreviewClick}+ style={imageAssetInfo}+ title={title}+ type="button"+ >+ <span style={imageAssetName}>{name}</span>+ {source === null ? null : (+ <span style={imageAssetSource}>{source}</span>+ )}+ </button>+ </>+ );++ return (+ <div style={imageAssetField}>+ {localAssetPath === null ? (+ <div style={imageAssetPreview}>{previewAction}</div>+ ) : (+ <ContextMenu+ getItems={getLocalAssetContextMenuItems}+ style={imageAssetPreview}>- <span style={imageAssetName}>{name}</span>- {source === null ? null : (- <span style={imageAssetSource}>{source}</span>- )}- </button>- {action}- </div>- );- }+ {previewAction}+ </ContextMenu>+ )}+ {action}+ </div>+ );}if (inlineSourceAction === null) {diff --git a/packages/studio/src/components/asset-context-menu.ts b/packages/studio/src/components/asset-context-menu.tsnew file mode 100644index 0000000000..d1ae125738--- /dev/null+++ b/packages/studio/src/components/asset-context-menu.ts@@ -0,0 +1,306 @@+import {useCallback, useContext} from 'react';+import {NoReactInternals} from 'remotion/no-react';+import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';+import {StudioServerConnectionCtx} from '../helpers/client-id';+import {copyText} from '../helpers/copy-text';+import {getFileManagerName} from '../helpers/get-file-manager-name';+import {getPreviewFileType} from '../helpers/get-preview-file-type';+import {openInRemotionConvert} from '../helpers/open-in-remotion-convert';+import {SetSelectedModalContext} from '../state/modals';+import type {ComboboxValue} from './NewComposition/ComboBox';+import {showNotification} from './Notifications/NotificationCenter';+import {getOpenInNewWindowMenuItem} from './open-in-new-window';+import {openInFileExplorer} from './RenderQueue/actions';+import {useDeleteAsset} from './use-delete-asset';++export const getAssetActionAvailability = ({+ browserStudioCanMutateAssets,+ readOnlyStudio,+ connectionStatus,+ publicFolderExists,+}: {+ browserStudioCanMutateAssets: boolean | null;+ readOnlyStudio: boolean;+ connectionStatus: 'init' | 'connected' | 'disconnected';+ publicFolderExists: string | null;+}) => {+ return {+ mutationsDisabled:+ browserStudioCanMutateAssets !== true &&+ (readOnlyStudio || connectionStatus !== 'connected'),+ fileExplorerDisabled:+ browserStudioCanMutateAssets !== null ||+ publicFolderExists === null ||+ readOnlyStudio ||+ connectionStatus !== 'connected',+ };+};++export const getAssetContextMenuItems = ({+ relativePath,+ fileManagerName,+ copyFileName,+ copyStaticFilePath,+ copyAbsolutePath,+ openAssetInConvert,+ openAssetInExplorer,+ renameAsset,+ deleteAsset,+ fileExplorerAvailable,+ fileExplorerDisabled,+ mutationsDisabled,+}: {+ relativePath: string;+ fileManagerName: string;+ copyFileName: () => void;+ copyStaticFilePath: () => void;+ copyAbsolutePath: (() => void) | null;+ openAssetInConvert: () => void;+ openAssetInExplorer: () => void;+ renameAsset: () => void;+ deleteAsset: () => void;+ fileExplorerAvailable: boolean;+ fileExplorerDisabled: boolean;+ mutationsDisabled: boolean;+}): ComboboxValue[] => {+ const previewFileType = getPreviewFileType(relativePath);+ const canOpenInConvert =+ previewFileType === 'audio' || previewFileType === 'video';+ const items: (ComboboxValue | null)[] = [+ getOpenInNewWindowMenuItem(`/assets/${relativePath}`),+ canOpenInConvert+ ? {+ id: 'open-asset-in-convert',+ keyHint: null,+ label: 'Open in Remotion Convert',+ leftItem: null,+ onClick: openAssetInConvert,+ quickSwitcherLabel: 'Open asset in Remotion Convert',+ subMenu: null,+ type: 'item',+ value: 'open-asset-in-convert',+ }+ : null,+ {+ type: 'divider',+ id: 'open-in-new-window-divider',+ },+ {+ id: 'copy-asset-file-name',+ keyHint: null,+ label: 'Copy file name',+ leftItem: null,+ onClick: copyFileName,+ quickSwitcherLabel: 'Copy asset file name',+ subMenu: null,+ type: 'item',+ value: 'copy-asset-file-name',+ },+ {+ id: 'copy-asset-static-file-path',+ keyHint: null,+ label: 'Copy staticFile() path',+ leftItem: null,+ onClick: copyStaticFilePath,+ quickSwitcherLabel: 'Copy staticFile() path',+ subMenu: null,+ type: 'item',+ value: 'copy-asset-static-file-path',+ },+ copyAbsolutePath+ ? {+ id: 'copy-asset-absolute-path',+ keyHint: null,+ label: 'Copy absolute path',+ leftItem: null,+ onClick: copyAbsolutePath,+ quickSwitcherLabel: 'Copy asset absolute path',+ subMenu: null,+ type: 'item',+ value: 'copy-asset-absolute-path',+ }+ : null,+ {+ type: 'divider',+ id: 'asset-file-actions-divider',+ },+ fileExplorerAvailable+ ? {+ id: 'open-asset-in-explorer',+ keyHint: null,+ label: `Show in ${fileManagerName}`,+ leftItem: null,+ onClick: openAssetInExplorer,+ quickSwitcherLabel: `Show asset in ${fileManagerName}`,+ subMenu: null,+ type: 'item',+ value: 'open-asset-in-explorer',+ disabled: fileExplorerDisabled,+ }+ : null,+ {+ id: 'rename-asset',+ keyHint: null,+ label: 'Rename...',+ leftItem: null,+ onClick: renameAsset,+ quickSwitcherLabel: 'Rename asset...',+ subMenu: null,+ type: 'item',+ value: 'rename-asset',+ disabled: mutationsDisabled,+ },+ {+ id: 'delete-asset',+ keyHint: null,+ label: 'Delete...',+ leftItem: null,+ onClick: deleteAsset,+ quickSwitcherLabel: 'Delete asset...',+ subMenu: null,+ type: 'item',+ value: 'delete-asset',+ disabled: mutationsDisabled,+ },+ ];++ return items.filter(NoReactInternals.truthy);+};++export const useAssetContextMenuItems = ({+ relativePath,+ readOnlyStudio,+}: {+ relativePath: string | null;+ readOnlyStudio: boolean;+}) => {+ const fileManagerName = getFileManagerName(+ window.remotion_fileSystemPlatform,+ );+ const {setSelectedModal} = useContext(SetSelectedModalContext);+ const connectionStatus = useContext(StudioServerConnectionCtx)+ .previewServerState.type;+ const fileName = relativePath?.split('/').pop() ?? null;++ const copyFileName = useCallback(() => {+ if (fileName === null) {+ return;+ }++ copyText(fileName)+ .then(() => {+ showNotification(`Copied '${fileName}' to clipboard`, 1000);+ })+ .catch((err) => {+ showNotification(`Could not copy: ${err.message}`, 2000);+ });+ }, [fileName]);++ const copyStaticFilePath = useCallback(() => {+ if (relativePath === null) {+ return;+ }++ const content = `staticFile("${relativePath}")`;+ copyText(content)+ .then(() => {+ showNotification(`Copied '${content}' to clipboard`, 1000);+ })+ .catch((err) => {+ showNotification(`Could not copy: ${err.message}`, 2000);+ });+ }, [relativePath]);++ const copyAbsolutePath = useCallback(() => {+ if (relativePath === null || window.remotion_publicFolderExists === null) {+ return;+ }++ const content = `${window.remotion_publicFolderExists}/${relativePath}`;+ copyText(content)+ .then(() => {+ showNotification(`Copied '${content}' to clipboard`, 1000);+ })+ .catch((err) => {+ showNotification(`Could not copy: ${err.message}`, 2000);+ });+ }, [relativePath]);++ const openAssetInConvert = useCallback(() => {+ if (relativePath === null) {+ return;+ }++ openInRemotionConvert({relativePath});+ }, [relativePath]);++ const openAssetInExplorer = useCallback(() => {+ if (relativePath === null || !window.remotion_publicFolderExists) {+ showNotification('Could not find the public folder', 2000);+ return;+ }++ openInFileExplorer({+ directory: window.remotion_publicFolderExists + '/' + relativePath,+ }).catch((err) => {+ showNotification(`Could not open file: ${err.message}`, 2000);+ });+ }, [relativePath]);++ const {mutationsDisabled, fileExplorerDisabled} = getAssetActionAvailability({+ browserStudioCanMutateAssets:+ getBrowserStudioOperations() === null ? null : true,+ readOnlyStudio,+ connectionStatus,+ publicFolderExists: window.remotion_publicFolderExists,+ });++ const deleteAsset = useDeleteAsset(relativePath);++ const renameAsset = useCallback(() => {+ if (relativePath === null) {+ return;+ }++ setSelectedModal({+ type: 'rename-static-file',+ relativePath,+ });+ }, [relativePath, setSelectedModal]);++ const getContextMenuItems = useCallback((): ComboboxValue[] => {+ if (relativePath === null) {+ return [];+ }++ return getAssetContextMenuItems({+ relativePath,+ fileManagerName,+ copyFileName,+ copyStaticFilePath,+ copyAbsolutePath:+ window.remotion_publicFolderExists === null ? null : copyAbsolutePath,+ openAssetInConvert,+ openAssetInExplorer,+ renameAsset,+ deleteAsset,+ fileExplorerAvailable: getBrowserStudioOperations() === null,+ fileExplorerDisabled,+ mutationsDisabled,+ });+ }, [+ copyFileName,+ copyStaticFilePath,+ copyAbsolutePath,+ deleteAsset,+ fileExplorerDisabled,+ fileManagerName,+ mutationsDisabled,+ openAssetInConvert,+ openAssetInExplorer,+ renameAsset,+ relativePath,+ ]);++ return {fileExplorerDisabled, fileManagerName, getContextMenuItems};+};diff --git a/packages/studio/src/test/quick-switcher-asset-search.test.tsx b/packages/studio/src/test/quick-switcher-asset-search.test.tsxindex bb1101c8eb..1be162592e 100644--- a/packages/studio/src/test/quick-switcher-asset-search.test.tsx+++ b/packages/studio/src/test/quick-switcher-asset-search.test.tsx@@ -3,8 +3,12 @@ import {cleanup, fireEvent, render, screen} from '@testing-library/react';import type {AssetFieldSchema} from 'remotion';import type {StaticFile} from '../api/get-static-files';import {AssetSelectorModal} from '../components/AssetSelectorModal';+import {portals} from '../components/Menu/portals';import {filterAssetsByType} from '../components/QuickSwitcher/asset-search';-import {TimelineAssetField} from '../components/Timeline/TimelineAssetField';+import {+ AssetSelectionContext,+ TimelineAssetField,+} from '../components/Timeline/TimelineAssetField';import {SetSelectedModalContext, type ModalState} from '../state/modals';afterEach(cleanup);@@ -259,33 +263,48 @@ test('an image asset field replaces a protocol-relative URL', () => {expect(selectedModal).toBeNull();});-test('a local image preview has no generic source label and is not draggable', () => {+test('a local image preview supports navigation and asset actions', async () => {const fieldSchema = {type: 'asset',assetType: 'image',default: undefined,} satisfies AssetFieldSchema;+ let navigationCount = 0;render(- <TimelineAssetField- field={{- key: 'imageSrc',- description: 'Image source',- typeName: 'asset',- rowHeight: 56,- fieldSchema,- group: 'source',- }}- propStatus={{- status: 'static',- codeValue: 'remotion-file:images/logo.png',- keyframeDisplayOffsetAdjustment: null,+ <AssetSelectionContext.Provider+ value={{+ getSourceAction: () => ({+ children: 'logo.png',+ disabled: false,+ onClick: () => {+ navigationCount++;+ },+ title: 'images/logo.png',+ }),+ sourceAction: null,}}- effectiveValue="remotion-file:images/logo.png"- onSave={() => Promise.resolve()}- onDragValueChange={() => undefined}- onDragEnd={() => undefined}- />,+ >+ <TimelineAssetField+ field={{+ key: 'imageSrc',+ description: 'Image source',+ typeName: 'asset',+ rowHeight: 56,+ fieldSchema,+ group: 'source',+ }}+ propStatus={{+ status: 'static',+ codeValue: 'remotion-file:images/logo.png',+ keyframeDisplayOffsetAdjustment: null,+ }}+ effectiveValue="remotion-file:images/logo.png"+ onSave={() => Promise.resolve()}+ onDragValueChange={() => undefined}+ onDragEnd={() => undefined}+ />+ </AssetSelectionContext.Provider>,);expect(screen.getByText('logo.png')).toBeTruthy();@@ -293,6 +312,20 @@ test('a local image preview has no generic source label and is not draggable', (expect(document.querySelector('img')?.getAttribute('draggable')).toBe('false',);+ const previewButtons = screen.getAllByRole('button', {+ name: 'Open logo.png',+ });+ expect(previewButtons).toHaveLength(2);+ fireEvent.click(previewButtons[0]);+ expect(navigationCount).toBe(1);+ const previousMenuPortal = portals[0];+ portals[0] = document.body;+ try {+ fireEvent.contextMenu(previewButtons[1]);+ expect(await screen.findByText('Copy file name')).toBeTruthy();+ } finally {+ portals[0] = previousMenuPortal;+ }});test('an image asset filter includes SVG files', () => {