🎥 Make videos programmatically with React
`@remotion/studio`: Fix Explorer item hover states and actions
JonnyBurger9d360d1e0e7c
diff --git a/packages/browser-studio/e2e/browser-studio.test.ts b/packages/browser-studio/e2e/browser-studio.test.tsindex 1d09cd8c02..4532e6cfd4 100644--- a/packages/browser-studio/e2e/browser-studio.test.ts+++ b/packages/browser-studio/e2e/browser-studio.test.ts@@ -1196,8 +1196,15 @@ test('clears hover backgrounds even if pointer leave events are lost', async ({await page.goto('/');const studio = page.frameLocator('iframe');await expect(studio.getByTitle('/project').getByText('MyComp')).toBeVisible();+ await waitForBrowserStudioOperations(studio);await studio.locator('[data-compname="MyComp"]').click();await studio.locator('[data-sidebar-toggle="right"]').click();+ await studio.locator('body').evaluate(async () => {+ await window.remotion_browserStudio.writeStaticFile({+ contents: new TextEncoder().encode('hover test').buffer,+ filePath: 'hover-test.txt',+ });+ });const addSolid = studio.getByRole('button', {name: 'Add Solid'});await expect(addSolid).toBeVisible();@@ -1229,7 +1236,33 @@ test('clears hover backgrounds even if pointer leave events are lost', async ({}});- const neutralArea = studio.locator('.remotion-studio-composition-container');+ const neutralArea = studio.locator('[data-sidebar-toggle="right"]');++ await studio.getByRole('button', {name: 'Assets', exact: true}).click();+ const assetItem = studio.getByTitle('hover-test.txt', {exact: true});+ await expect(assetItem).toBeVisible();+ await assetItem.hover();+ await expect+ .poll(() => getBackgroundColor(assetItem))+ .toBe('rgba(255, 255, 255, 0.06)');+ await neutralArea.hover();+ await expect+ .poll(() => getBackgroundColor(assetItem))+ .toBe('rgba(0, 0, 0, 0)');++ await assetItem.click();+ await studio.getByRole('button', {name: 'Compositions', exact: true}).click();+ const compositionItem = studio.locator('[data-compname="MyComp"]');+ await compositionItem.hover();+ await expect+ .poll(() => getBackgroundColor(compositionItem))+ .toBe('rgba(255, 255, 255, 0.06)');+ await neutralArea.hover();+ await expect+ .poll(() => getBackgroundColor(compositionItem))+ .toBe('rgba(0, 0, 0, 0)');+ await compositionItem.click();+ await expect(addSolid).toBeVisible();await neutralArea.hover();await expectdiff --git a/packages/studio/src/components/AssetSelectorItem.tsx b/packages/studio/src/components/AssetSelectorItem.tsxindex 54867fc53a..ecf5095814 100644--- a/packages/studio/src/components/AssetSelectorItem.tsx+++ b/packages/studio/src/components/AssetSelectorItem.tsx@@ -25,7 +25,11 @@ import {getFileManagerName} from '../helpers/get-file-manager-name';import {getPreviewFileType} from '../helpers/get-preview-file-type';import {FOCUS_VISIBLE_ONLY_CLASS_NAME,+ HOVERABLE_CLASS_NAME,+ HOVER_GROUP_CLASS_NAME,+ HOVER_GROUP_REVEAL_CLASS_NAME,NO_HOVER_BACKGROUND_STYLE,+ hoverableStyle,} from '../helpers/hoverable';import {openInRemotionConvert} from '../helpers/open-in-remotion-convert';import {@@ -61,7 +65,6 @@ const iconStyle: React.CSSProperties = {};const itemStyle: React.CSSProperties = {- paddingRight: 10,paddingTop: 5,paddingBottom: 5,fontSize: 13,@@ -76,7 +79,6 @@ const itemStyle: React.CSSProperties = {borderRadius: 4,width: 'calc(100% - 4px)',textAlign: 'left',- backgroundColor: BACKGROUND,height: COMPACT_CONTROL_ROW_HEIGHT,userSelect: 'none',WebkitUserSelect: 'none',@@ -103,6 +105,11 @@ const ellipsisIconStyle: React.SVGProps<SVGSVGElement> = {},};+const inlineActionsStyle: React.CSSProperties = {+ alignItems: 'center',+ display: 'flex',+};+export const getAssetActionAvailability = ({browserStudioCanMutateAssets,readOnlyStudio,@@ -119,6 +126,7 @@ export const getAssetActionAvailability = ({browserStudioCanMutateAssets !== true &&(readOnlyStudio || connectionStatus !== 'connected'),fileExplorerDisabled:+ browserStudioCanMutateAssets !== null ||publicFolderExists === null ||readOnlyStudio ||connectionStatus !== 'connected',@@ -288,7 +296,6 @@ const AssetFolderItem: React.FC<{setDropLocation,readOnlyStudio,}) => {- const [hovered, setHovered] = useState(false);const openFolderTimerRef = useRef<number | null>(null);const {isDropDiv, onDragEnter, onDragLeave} = useAssetDragEvents({@@ -298,28 +305,18 @@ const AssetFolderItem: React.FC<{setDropLocation,});- const onPointerEnter = useCallback(() => {- setHovered(true);- }, []);-- const onPointerLeave = useCallback(() => {- setHovered(false);- }, []);-const folderStyle: React.CSSProperties = useMemo(() => {return {...itemStyle,paddingLeft: 4 + level * 8,- backgroundColor: hovered ? WHITE_ALPHA_06 : TRANSPARENT,- };- }, [hovered, level]);-- const label = useMemo(() => {- return {- ...labelStyle,- color: hovered ? WHITE : LIGHT_TEXT,+ ...hoverableStyle({+ idleBackground: TRANSPARENT,+ hoverBackground: WHITE_ALPHA_06,+ idleColor: LIGHT_TEXT,+ hoverColor: WHITE,+ }),};- }, [hovered]);+ }, [level]);const onClick = useCallback(() => {toggleFolder(item.name, parentFolder);@@ -337,8 +334,7 @@ const AssetFolderItem: React.FC<{><divstyle={folderStyle}- onPointerEnter={onPointerEnter}- onPointerLeave={onPointerLeave}+ className={HOVERABLE_CLASS_NAME}tabIndex={tabIndex}title={item.name}onClick={onClick}@@ -364,9 +360,9 @@ const AssetFolderItem: React.FC<{}}><Row>- <Icon style={iconStyle} color={hovered ? WHITE : LIGHT_TEXT} />+ <Icon style={iconStyle} color={CURRENT_COLOR} /><Spacing x={1} />- <div style={label}>{item.name}</div>+ <div style={labelStyle}>{item.name}</div></Row></div>@@ -458,15 +454,10 @@ const AssetSelectorItem: React.FC<{const fileManagerName = getFileManagerName(window.remotion_fileSystemPlatform,);- const [hovered, setHovered] = useState(false);const [isDragging, setIsDragging] = useState(false);const {setSelectedModal} = useContext(SetSelectedModalContext);const connectionStatus = useContext(StudioServerConnectionCtx).previewServerState.type;- const onPointerEnter = useCallback(() => {- setHovered(true);- }, []);-const {setCanvasContent} = useContext(Internals.CompositionSetters);const {canvasContent} = useContext(Internals.CompositionManager);@@ -489,10 +480,6 @@ const AssetSelectorItem: React.FC<{return getCanDragAsset({readOnlyStudio, relativePath});}, [readOnlyStudio, relativePath]);- const onPointerLeave = useCallback(() => {- setHovered(false);- }, []);-const rowRef = useRef<HTMLDivElement>(null);useLayoutEffect(() => {maybeScrollAssetSidebarRowIntoView({@@ -559,18 +546,15 @@ const AssetSelectorItem: React.FC<{const style: React.CSSProperties = useMemo(() => {return {...itemStyle,- color: hovered || selected ? WHITE : LIGHT_TEXT,- backgroundColor: hovered || selected ? WHITE_ALPHA_06 : TRANSPARENT,+ ...hoverableStyle({+ idleBackground: selected ? WHITE_ALPHA_06 : TRANSPARENT,+ hoverBackground: WHITE_ALPHA_06,+ idleColor: selected ? WHITE : LIGHT_TEXT,+ hoverColor: WHITE,+ }),paddingLeft: 12 + level * 8,};- }, [hovered, level, selected]);-- const label = useMemo(() => {- return {- ...labelStyle,- color: hovered || selected ? WHITE : LIGHT_TEXT,- };- }, [hovered, selected]);+ }, [level, selected]);const renderFileExplorerAction: RenderInlineAction = useCallback((color) => {return <ExpandedFolderIcon style={revealIconStyle} color={color} />;@@ -695,8 +679,7 @@ const AssetSelectorItem: React.FC<{<divref={rowRef}style={style}- onPointerEnter={onPointerEnter}- onPointerLeave={onPointerLeave}+ className={`${HOVERABLE_CLASS_NAME} ${HOVER_GROUP_CLASS_NAME}`}onClick={onClick}draggable={canDragAsset}onDragStart={onDragStart}@@ -707,12 +690,15 @@ const AssetSelectorItem: React.FC<{<AssetFileIconfileType={previewFileType}style={iconStyle}- color={hovered || selected ? WHITE : LIGHT_TEXT}+ color={CURRENT_COLOR}/><Spacing x={1} />- <div style={label}>{item.name}</div>- {hovered && !isDragging ? (- <>+ <div style={labelStyle}>{item.name}</div>+ {!isDragging ? (+ <div+ className={HOVER_GROUP_REVEAL_CLASS_NAME}+ style={inlineActionsStyle}+ ><Spacing x={0.5} /><InlineDropdownvariant={null}@@ -735,7 +721,7 @@ const AssetSelectorItem: React.FC<{/></>)}- </>+ </div>) : null}</div></Row>diff --git a/packages/studio/src/components/CompositionContextButton.tsx b/packages/studio/src/components/CompositionContextButton.tsxindex 26af6b3e12..103733a89e 100644--- a/packages/studio/src/components/CompositionContextButton.tsx+++ b/packages/studio/src/components/CompositionContextButton.tsx@@ -3,6 +3,7 @@ import React, {useCallback, useContext, useMemo} from 'react';import {StudioServerConnectionCtx} from '../helpers/client-id';import {FOCUS_VISIBLE_ONLY_CLASS_NAME,+ HOVER_GROUP_REVEAL_CLASS_NAME,NO_HOVER_BACKGROUND_STYLE,} from '../helpers/hoverable';import {EllipsisIcon} from '../icons/ellipsis';@@ -10,10 +11,15 @@ import type {RenderInlineAction} from './InlineAction';import {InlineDropdown} from './InlineDropdown';import type {ComboboxValue} from './NewComposition/ComboBox';+const revealStyle: React.CSSProperties = {+ display: 'flex',+};+export const CompositionContextButton: React.FC<{readonly visible: boolean;readonly getItems: () => ComboboxValue[];-}> = ({visible, getItems}) => {+ readonly readOnlyStudio: boolean;+}> = ({visible, getItems, readOnlyStudio}) => {const iconStyle: SVGProps<SVGSVGElement> = useMemo(() => {return {style: {@@ -32,17 +38,19 @@ export const CompositionContextButton: React.FC<{[iconStyle],);- if (!visible || connectionStatus !== 'connected') {+ if (!visible || (connectionStatus !== 'connected' && !readOnlyStudio)) {return null;}return (- <InlineDropdown- renderAction={renderAction}- getItems={getItems}- variant={null}- style={NO_HOVER_BACKGROUND_STYLE}- className={FOCUS_VISIBLE_ONLY_CLASS_NAME}- />+ <div className={HOVER_GROUP_REVEAL_CLASS_NAME} style={revealStyle}>+ <InlineDropdown+ renderAction={renderAction}+ getItems={getItems}+ variant={null}+ style={NO_HOVER_BACKGROUND_STYLE}+ className={FOCUS_VISIBLE_ONLY_CLASS_NAME}+ />+ </div>);};diff --git a/packages/studio/src/components/CompositionSelectorItem.tsx b/packages/studio/src/components/CompositionSelectorItem.tsxindex fcd165e87b..ab2b917c02 100644--- a/packages/studio/src/components/CompositionSelectorItem.tsx+++ b/packages/studio/src/components/CompositionSelectorItem.tsx@@ -12,13 +12,18 @@ import React, {import {type _InternalTypes} from 'remotion';import {StudioServerConnectionCtx} from '../helpers/client-id';import {- BACKGROUND,+ CURRENT_COLOR,LIGHT_TEXT,TRANSPARENT,WHITE,WHITE_ALPHA_06,WHITE_ALPHA_12,} from '../helpers/colors';+import {+ HOVERABLE_CLASS_NAME,+ HOVER_GROUP_CLASS_NAME,+ hoverableStyle,+} from '../helpers/hoverable';import {noop} from '../helpers/noop';import {markCompositionSidebarScrollFromRowClick,@@ -56,7 +61,6 @@ const itemStyle: React.CSSProperties = {borderRadius: 4,width: 'calc(100% - 12px)',textAlign: 'left',- backgroundColor: BACKGROUND,height: COMPACT_CONTROL_ROW_HEIGHT,userSelect: 'none',};@@ -123,14 +127,6 @@ export const CompositionSelectorItem: React.FC<{return false;}, [item, currentComposition]);- const [hovered, setHovered] = useState(false);- const onPointerEnter = useCallback(() => {- setHovered(true);- }, []);-- const onPointerLeave = useCallback(() => {- setHovered(false);- }, []);const [isDragging, setIsDragging] = useState(false);const [dragHovered, setDragHovered] = useState(false);@@ -150,23 +146,22 @@ export const CompositionSelectorItem: React.FC<{}, [compositionId, selected]);const style: React.CSSProperties = useMemo(() => {+ const idleBackground = dragHovered+ ? WHITE_ALPHA_12+ : selected+ ? WHITE_ALPHA_06+ : TRANSPARENT;return {...itemStyle,- backgroundColor: dragHovered- ? WHITE_ALPHA_12- : hovered || selected- ? WHITE_ALPHA_06- : TRANSPARENT,+ ...hoverableStyle({+ idleBackground,+ hoverBackground: dragHovered ? WHITE_ALPHA_12 : WHITE_ALPHA_06,+ idleColor: selected ? WHITE : LIGHT_TEXT,+ hoverColor: WHITE,+ }),paddingLeft: 12 + level * 8,};- }, [dragHovered, hovered, level, selected]);-- const label = useMemo(() => {- return {- ...labelStyle,- color: selected || hovered ? WHITE : LIGHT_TEXT,- };- }, [hovered, selected]);+ }, [dragHovered, level, selected]);const onClick = useCallback((evt: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>) => {@@ -376,9 +371,7 @@ export const CompositionSelectorItem: React.FC<{<Row align="center"><divstyle={style}- className="__remotion-composition-selector-item"- onPointerEnter={onPointerEnter}- onPointerLeave={onPointerLeave}+ className={`__remotion-composition-selector-item ${HOVERABLE_CLASS_NAME} ${HOVER_GROUP_CLASS_NAME}`}tabIndex={tabIndex}onClick={onClick}onKeyDown={onKeyDown}@@ -389,22 +382,17 @@ export const CompositionSelectorItem: React.FC<{role="button">{item.expanded ? (- <ExpandedFolderIcon- style={iconStyle}- color={hovered || selected ? WHITE : LIGHT_TEXT}- />+ <ExpandedFolderIcon style={iconStyle} color={CURRENT_COLOR} />) : (- <CollapsedFolderIcon- color={hovered || selected ? WHITE : LIGHT_TEXT}- style={iconStyle}- />+ <CollapsedFolderIcon color={CURRENT_COLOR} style={iconStyle} />)}<Spacing x={1} />- <div style={label}>{item.folderName}</div>+ <div style={labelStyle}>{item.folderName}</div><Spacing x={0.5} /><CompositionContextButtongetItems={getContextMenuItems}- visible={hovered}+ visible+ readOnlyStudio={window.remotion_isReadOnlyStudio}/></div></Row>@@ -437,8 +425,6 @@ export const CompositionSelectorItem: React.FC<{<aref={compositionRowRef}style={style}- onPointerEnter={onPointerEnter}- onPointerLeave={onPointerLeave}tabIndex={tabIndex}onClick={onClick}onKeyDown={onKeyDown}@@ -447,24 +433,26 @@ export const CompositionSelectorItem: React.FC<{onDragEnd={onCompositionDragEnd}type="button"title={item.composition.id}- className="__remotion-composition __remotion-composition-selector-item"+ className={`__remotion-composition __remotion-composition-selector-item ${HOVERABLE_CLASS_NAME} ${HOVER_GROUP_CLASS_NAME}`}data-compname={item.composition.id}><CompositionOrStillIconcomposition={item.composition}- color={hovered || selected ? WHITE : LIGHT_TEXT}+ color={CURRENT_COLOR}style={iconStyle}/><Spacing x={1} />- <div style={label}>{item.composition.id}</div>+ <div style={labelStyle}>{item.composition.id}</div><Spacing x={0.5} /><CompositionContextButtongetItems={getContextMenuItems}- visible={hovered && !isDragging}+ visible={!isDragging}+ readOnlyStudio={window.remotion_isReadOnlyStudio}/><SidebarRenderButton- visible={hovered && !isDragging}+ visible={!isDragging}composition={item.composition}+ readOnlyStudio={window.remotion_isReadOnlyStudio}/></a></Row>diff --git a/packages/studio/src/components/SidebarRenderButton.tsx b/packages/studio/src/components/SidebarRenderButton.tsxindex dc0622b2d0..103717ddce 100644--- a/packages/studio/src/components/SidebarRenderButton.tsx+++ b/packages/studio/src/components/SidebarRenderButton.tsx@@ -13,6 +13,7 @@ import {Internals} from 'remotion';import {StudioServerConnectionCtx} from '../helpers/client-id';import {FOCUS_VISIBLE_ONLY_CLASS_NAME,+ HOVER_GROUP_REVEAL_CLASS_NAME,NO_HOVER_BACKGROUND_STYLE,} from '../helpers/hoverable';import {ThinRenderIcon} from '../icons/render';@@ -20,10 +21,15 @@ import {SetSelectedModalContext} from '../state/modals';import type {RenderInlineAction} from './InlineAction';import {InlineAction} from './InlineAction';+const revealStyle: React.CSSProperties = {+ display: 'flex',+};+export const SidebarRenderButton: React.FC<{readonly composition: _InternalTypes['AnyCompMetadata'];readonly visible: boolean;-}> = ({composition, visible}) => {+ readonly readOnlyStudio: boolean;+}> = ({composition, visible, readOnlyStudio}) => {const {setSelectedModal} = useContext(SetSelectedModalContext);const iconStyle: SVGProps<SVGSVGElement> = useMemo(() => {@@ -100,10 +106,16 @@ export const SidebarRenderButton: React.FC<{initialMediaCacheSizeInBytes: defaults.mediaCacheSizeInBytes,renderDefaults: defaults,initialDarkMode: defaults.darkMode,- readOnlyStudio: false,+ readOnlyStudio,});},- [composition.defaultProps, composition.id, props, setSelectedModal],+ [+ composition.defaultProps,+ composition.id,+ props,+ readOnlyStudio,+ setSelectedModal,+ ],);const renderAction: RenderInlineAction = useCallback(@@ -113,17 +125,19 @@ export const SidebarRenderButton: React.FC<{[iconStyle],);- if (!visible || connectionStatus !== 'connected') {+ if (!visible || (connectionStatus !== 'connected' && !readOnlyStudio)) {return null;}return (- <InlineAction- renderAction={renderAction}- onClick={onClick}- variant={null}- style={NO_HOVER_BACKGROUND_STYLE}- className={FOCUS_VISIBLE_ONLY_CLASS_NAME}- />+ <div className={HOVER_GROUP_REVEAL_CLASS_NAME} style={revealStyle}>+ <InlineAction+ renderAction={renderAction}+ onClick={onClick}+ variant={null}+ style={NO_HOVER_BACKGROUND_STYLE}+ className={FOCUS_VISIBLE_ONLY_CLASS_NAME}+ />+ </div>);};diff --git a/packages/studio/src/test/asset-context-menu.test.ts b/packages/studio/src/test/asset-context-menu.test.tsindex 52975e3c48..4ba0b5d2ed 100644--- a/packages/studio/src/test/asset-context-menu.test.ts+++ b/packages/studio/src/test/asset-context-menu.test.ts@@ -137,6 +137,20 @@ test('enables supported Browser Studio asset mutations', () => {});});+test('disables file-manager actions in editable Browser Studio', () => {+ const availability = getAssetActionAvailability({+ browserStudioCanMutateAssets: true,+ readOnlyStudio: false,+ connectionStatus: 'connected',+ publicFolderExists: '/public',+ });++ expect(availability).toEqual({+ fileExplorerDisabled: true,+ mutationsDisabled: false,+ });+});+test('disables drag insertion in read-only Studio', () => {expect(getCanDragAsset({