Skip to content

Commit aa5d823

Browse files
authored
Merge pull request #12520 from remotion-dev/codex/stack-timeline-layer-and-asset-names
`@remotion/studio`: Stack timeline layer and asset names
2 parents bed108f + 7a5a9a8 commit aa5d823

7 files changed

Lines changed: 269 additions & 65 deletions

File tree

‎packages/example/e2e/effect-keyframes.test.mts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,9 @@ test.describe('effect keyframes', () => {
293293
).toBeVisible({timeout: 1_000});
294294
}).toPass({timeout: 15_000});
295295

296-
const timelineExpansionLabel = page
297-
.getByText('Timeline expansion', {exact: true})
298-
.last();
299-
const timelineExpansionRow = timelineExpansionLabel
300-
.locator('..')
301-
.locator('..');
296+
const timelineExpansionRow = page
297+
.locator('[data-remotion-sequence-reorder-row]')
298+
.filter({has: page.getByText('Timeline expansion', {exact: true})});
302299
const opacityRow = page.getByText('Opacity', {exact: true});
303300
await expect(async () => {
304301
await page

‎packages/studio/src/components/ActionTooltip.tsx‎

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let visibleTooltipCount = 0;
5151
let lastTooltipHiddenAt: number | null = null;
5252
const TOOLTIP_SKIP_DELAY_WINDOW = 300;
5353

54-
export const ActionTooltip: React.FC<{
54+
type ActionTooltipProps = {
5555
readonly label: React.ReactNode;
5656
readonly shortcut: string | null;
5757
/** Hover delay in milliseconds. Pass null to show immediately. */
@@ -60,14 +60,21 @@ export const ActionTooltip: React.FC<{
6060
readonly side?: 'top' | 'right';
6161
readonly triggerStyle?: React.CSSProperties;
6262
readonly children: React.ReactNode;
63-
}> = ({
63+
};
64+
65+
const Tooltip: React.FC<
66+
ActionTooltipProps & {
67+
readonly overflowTarget: React.RefObject<HTMLElement | null> | null;
68+
}
69+
> = ({
6470
label,
6571
shortcut,
6672
delay,
6773
dismissOnClick,
6874
side = 'top',
6975
triggerStyle,
7076
children,
77+
overflowTarget,
7178
}) => {
7279
const triggerRef = useRef<HTMLSpanElement>(null);
7380
const tooltipRef = useRef<HTMLDivElement>(null);
@@ -110,15 +117,33 @@ export const ActionTooltip: React.FC<{
110117
setPosition(null);
111118
}, []);
112119

120+
const canShow = useCallback(() => {
121+
if (overflowTarget === null) {
122+
return true;
123+
}
124+
125+
const element = overflowTarget.current;
126+
return (
127+
element !== null &&
128+
(element.scrollWidth > element.clientWidth ||
129+
element.scrollHeight > element.clientHeight)
130+
);
131+
}, [overflowTarget]);
132+
113133
const show = useCallback(() => {
114134
if (timer.current !== null) {
115135
clearTimeout(timer.current);
116136
timer.current = null;
117137
}
118138

139+
if (!canShow()) {
140+
hide();
141+
return;
142+
}
143+
119144
setActive(true);
120145
setVisible(true);
121-
}, []);
146+
}, [canShow, hide]);
122147

123148
useLayoutEffect(() => {
124149
const trigger = triggerRef.current;
@@ -134,7 +159,7 @@ export const ActionTooltip: React.FC<{
134159
return;
135160
}
136161

137-
if (!hovered) {
162+
if (!hovered || !canShow()) {
138163
hide();
139164
return;
140165
}
@@ -171,7 +196,22 @@ export const ActionTooltip: React.FC<{
171196
timer.current = null;
172197
}
173198
};
174-
}, [hide, show]);
199+
}, [canShow, hide, show]);
200+
201+
useEffect(() => {
202+
const element = overflowTarget?.current;
203+
if (!active || !element) {
204+
return;
205+
}
206+
207+
const observer = new ResizeObserver(() => {
208+
if (!canShow()) {
209+
hide();
210+
}
211+
});
212+
observer.observe(element);
213+
return () => observer.disconnect();
214+
}, [active, canShow, hide, overflowTarget]);
175215

176216
useEffect(() => {
177217
if (!active) {
@@ -221,6 +261,11 @@ export const ActionTooltip: React.FC<{
221261
return;
222262
}
223263

264+
if (!canShow()) {
265+
hide();
266+
return;
267+
}
268+
224269
const trigger = triggerRef.current.getBoundingClientRect();
225270
const tooltip = tooltipRef.current.getBoundingClientRect();
226271
if (side === 'right') {
@@ -258,7 +303,7 @@ export const ActionTooltip: React.FC<{
258303
),
259304
),
260305
});
261-
}, [label, shortcut, side, visible]);
306+
}, [canShow, hide, label, shortcut, side, visible]);
262307

263308
return (
264309
<>
@@ -310,3 +355,15 @@ export const ActionTooltip: React.FC<{
310355
</>
311356
);
312357
};
358+
359+
export const ActionTooltip: React.FC<ActionTooltipProps> = (props) => {
360+
return <Tooltip {...props} overflowTarget={null} />;
361+
};
362+
363+
export const ClippedTextTooltip: React.FC<
364+
ActionTooltipProps & {
365+
readonly overflowTarget: React.RefObject<HTMLElement | null>;
366+
}
367+
> = (props) => {
368+
return <Tooltip {...props} />;
369+
};

‎packages/studio/src/components/Timeline/TimelineList.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ export const TimelineList: React.FC = () => {
268268
font-family: Arial, Helvetica, sans-serif;
269269
font-size: 12px;
270270
line-height: normal;
271+
padding-right: 10px;
271272
visibility: hidden;
272273
}`}</style>
273274
{virtualItems.map((virtualItem) =>

‎packages/studio/src/components/Timeline/TimelineMediaInfo.tsx‎

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
import React, {useMemo} from 'react';
1+
import React, {useCallback, useMemo, useState} from 'react';
22
import {Internals} from 'remotion';
33
import {WHITE_ALPHA_30} from '../../helpers/colors';
4+
import {formatMediaDuration} from '../../helpers/format-media-duration';
5+
import {useImageMetadata} from '../../helpers/use-image-metadata';
6+
import {useMediaMetadata} from '../../helpers/use-media-metadata';
7+
import {ActionTooltip} from '../ActionTooltip';
48
import {getTimelineAssetLinkInfo} from './timeline-asset-link';
59

610
const lineStyle: React.CSSProperties = {
711
whiteSpace: 'nowrap',
812
overflow: 'hidden',
9-
textOverflow: 'ellipsis',
13+
paddingRight: 10,
14+
maskImage: 'linear-gradient(to right, black calc(100% - 10px), transparent)',
15+
WebkitMaskImage:
16+
'linear-gradient(to right, black calc(100% - 10px), transparent)',
1017
minWidth: 0,
1118
fontSize: 12,
19+
lineHeight: '14px',
1220
color: WHITE_ALPHA_30,
1321
display: 'inline-block',
1422
};
@@ -24,7 +32,6 @@ const useAssetLink = (src: string) => {
2432
display: 'inline-block',
2533
overflow: 'hidden',
2634
whiteSpace: 'pre',
27-
textOverflow: 'ellipsis',
2835
userSelect: 'none',
2936
WebkitUserSelect: 'none',
3037
}),
@@ -39,18 +46,79 @@ const useAssetLink = (src: string) => {
3946

4047
export const TimelineMediaInfo: React.FC<{
4148
readonly src: string;
42-
}> = ({src}) => {
49+
readonly isImage: boolean;
50+
}> = ({src, isImage}) => {
4351
const fileName = useMemo(() => Internals.getAssetDisplayName(src), [src]);
4452

4553
const {linkInfo, fileNameStyle} = useAssetLink(src);
54+
// Share the asset inspector's caches, but only load metadata after hovering.
55+
const [requestedSrc, setRequestedSrc] = useState<string | null>(null);
56+
const metadataSrc = requestedSrc === src ? src : null;
57+
const mediaMetadata = useMediaMetadata(isImage ? null : metadataSrc);
58+
const imageMetadata = useImageMetadata(isImage ? metadataSrc : null);
59+
const onPointerEnter = useCallback(() => setRequestedSrc(src), [src]);
60+
const visualDetails: string[] = [];
61+
const fileDetails: string[] = [];
62+
if (mediaMetadata && Number.isFinite(mediaMetadata.duration)) {
63+
fileDetails.push(formatMediaDuration(mediaMetadata.duration));
64+
}
65+
66+
const dimensions = isImage ? imageMetadata : mediaMetadata;
67+
if (dimensions?.width && dimensions.height) {
68+
visualDetails.push(`${dimensions.width} × ${dimensions.height}`);
69+
}
70+
71+
if (mediaMetadata?.fps && Number.isFinite(mediaMetadata.fps)) {
72+
visualDetails.push(`${Number(mediaMetadata.fps.toFixed(2))} fps`);
73+
}
74+
75+
const format = isImage ? imageMetadata?.format : mediaMetadata?.format;
76+
if (format) {
77+
(isImage ? visualDetails : fileDetails).push(format);
78+
}
79+
80+
const metadataLines = [visualDetails, fileDetails]
81+
.filter((details) => details.length > 0)
82+
.map((details) => details.join(' · '));
83+
84+
const source =
85+
linkInfo?.kind === 'local'
86+
? linkInfo.assetPath
87+
: linkInfo?.kind === 'remote'
88+
? linkInfo.href
89+
: null;
4690

4791
return (
48-
<div
49-
role="group"
50-
style={fileNameStyle}
51-
aria-label={linkInfo ? linkInfo.title : fileName}
92+
<ActionTooltip
93+
label={
94+
<span
95+
style={{
96+
display: 'inline-block',
97+
font: 'inherit',
98+
color: 'inherit',
99+
maxWidth: 360,
100+
}}
101+
>
102+
<strong style={{font: 'inherit', fontWeight: 600, color: 'inherit'}}>
103+
{fileName}
104+
</strong>
105+
{source !== null && source !== fileName ? `\n${source}` : null}
106+
{metadataLines.length > 0 ? `\n${metadataLines.join('\n')}` : null}
107+
</span>
108+
}
109+
shortcut={null}
110+
delay={800}
111+
dismissOnClick
112+
triggerStyle={{minWidth: 0, maxWidth: '100%'}}
52113
>
53-
{fileName}
54-
</div>
114+
<div
115+
role="group"
116+
style={fileNameStyle}
117+
aria-label={linkInfo ? linkInfo.title : fileName}
118+
onPointerEnter={onPointerEnter}
119+
>
120+
{fileName}
121+
</div>
122+
</ActionTooltip>
55123
);
56124
};

0 commit comments

Comments
 (0)