Skip to content

šŸŽ„ Make videos programmatically with React

@remotion/studio: Preview computed value source

Jonny Burgerb2aaed975ad9
diff --git a/packages/studio/src/components/FixComputedValueModal.tsx b/packages/studio/src/components/FixComputedValueModal.tsx
index 9980033464..d16b104b97 100644
--- a/packages/studio/src/components/FixComputedValueModal.tsx
+++ b/packages/studio/src/components/FixComputedValueModal.tsx
@@ -1,6 +1,18 @@
-import React, {useCallback} from 'react';
-import {BLACK_ALPHA_30, BLUE, LIGHT_TEXT, WHITE} from '../helpers/colors';
+import type {SymbolicatedStackFrame} from '@remotion/studio-shared';
+import React, {useCallback, useContext, useEffect, useState} from 'react';
+import {resolveFileSource} from '../error-overlay/react-overlay/effects/resolve-file-source';
+import {OpenInEditor} from '../error-overlay/remotion-overlay/OpenInEditor';
+import {StackElement} from '../error-overlay/remotion-overlay/StackFrame';
+import {StudioServerConnectionCtx} from '../helpers/client-id';
+import {
+ BLACK_ALPHA_30,
+ BLUE,
+ BORDER_WHITE_ALPHA_12,
+ LIGHT_TEXT,
+ WHITE,
+} from '../helpers/colors';
import {copyText} from '../helpers/copy-text';
+import {findOriginalPositionInFileAtProperty} from '../helpers/open-in-editor';
import {useCopyFeedback} from '../helpers/use-copy-feedback';
import {CopyIcon} from '../icons/copy';
import {SkillsIcon} from '../icons/skills';
@@ -9,11 +21,13 @@ import {CodingAgentButton} from './CodingAgentButton';
import type {RenderInlineAction} from './InlineAction';
import {InlineAction} from './InlineAction';
import {getMaxModalHeight, getMaxModalWidth} from './ModalContainer';
-import {ModalFooterContainer} from './ModalFooter';
import {ModalHeader} from './ModalHeader';
import {DismissableModal} from './NewComposition/DismissableModal';
+import {ValidationMessage} from './NewComposition/ValidationMessage';
import {showNotification} from './Notifications/NotificationCenter';
import {useSettings} from './SettingsContext';
+import {SkillSettingsRow} from './SkillsSettings';
+import {useEditorOpening} from './use-default-editor-info';
const panelStyle: React.CSSProperties = {
borderRadius: 6,
@@ -80,12 +94,31 @@ const copyIcon: React.CSSProperties = {
width: 12,
};
-const footer: React.CSSProperties = {
+const agentPromptHeader: React.CSSProperties = {
+ alignItems: 'center',
display: 'flex',
- flex: 'none',
- minWidth: 0,
- padding: '12px 16px',
- justifyContent: 'flex-end',
+ gap: 12,
+ justifyContent: 'space-between',
+};
+
+const sourcePreviewContainer: React.CSSProperties = {
+ marginBottom: 16,
+ marginTop: 4,
+};
+
+const sourcePreviewStatus: React.CSSProperties = {
+ ...text,
+ marginBottom: 16,
+ marginTop: 10,
+};
+
+const skillRowContainer: React.CSSProperties = {
+ borderTop: BORDER_WHITE_ALPHA_12,
+ marginTop: 10,
+};
+
+const skillError: React.CSSProperties = {
+ marginTop: 10,
};
type FixComputedValueModalState = Extract<
@@ -93,21 +126,96 @@ type FixComputedValueModalState = Extract<
{type: 'fix-computed-value'}
>;
+type SourcePreviewState =
+ | {
+ type: 'loading';
+ }
+ | {
+ type: 'loaded';
+ stack: SymbolicatedStackFrame;
+ }
+ | {
+ type: 'error';
+ message: string;
+ };
+
export const FixComputedValueModal: React.FC<{
readonly state: FixComputedValueModalState;
}> = ({state}) => {
- const {codingAgentInfo} = useSettings();
+ const {codingAgentInfo, remotionSkillsInfo, skillActionError} = useSettings();
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const {canOpenInEditor, defaultEditorId, defaultEditorName} =
+ useEditorOpening(previewServerState.type === 'connected');
+ const [sourcePreview, setSourcePreview] = useState<SourcePreviewState>({
+ type: 'loading',
+ });
const skillName = '/remotion-interactivity';
- const promptDetails = ` ${state.context} make "${state.prop}" interactive`;
+ const skillId = 'remotion-interactivity';
+ const remotionInteractivitySkillAvailable =
+ remotionSkillsInfo?.remotionInteractivitySkillAvailable ?? false;
+ const interactivitySkill =
+ remotionSkillsInfo?.skills.find((skill) => skill.name === skillId) ?? null;
+ const canInstallSkill =
+ !window.remotion_isReadOnlyStudio &&
+ previewServerState.type === 'connected' &&
+ remotionSkillsInfo !== null;
+ const promptLocation =
+ sourcePreview.type === 'loaded'
+ ? `${sourcePreview.stack.originalFileName}:${sourcePreview.stack.originalLineNumber}:${sourcePreview.stack.originalColumnNumber}`
+ : `${state.location.source}:${state.location.line}:${state.location.column}`;
+ const promptDetails = ` ${promptLocation} make "${state.prop}" interactive`;
const prompt = `${skillName}${promptDetails}`;
const installCommand = 'npx remotion skills add';
const hasCodingAgent =
(codingAgentInfo?.installedCodingAgents.length ?? 0) > 0;
+ const canOpenSourceInEditor =
+ sourcePreview.type === 'loaded' &&
+ canOpenInEditor &&
+ defaultEditorId !== null &&
+ defaultEditorName !== null;
const {copied: promptCopied, markCopied: markPromptCopied} =
useCopyFeedback();
const {copied: installCommandCopied, markCopied: markInstallCommandCopied} =
useCopyFeedback();
+ useEffect(() => {
+ let cancelled = false;
+ setSourcePreview({type: 'loading'});
+
+ findOriginalPositionInFileAtProperty({
+ originalPosition: state.location,
+ property: state.prop.split('.').at(-1) ?? state.prop,
+ })
+ .then((position) => {
+ return resolveFileSource(
+ {
+ columnNumber: position.column,
+ fileName: position.source,
+ lineNumber: position.line,
+ message: `Computed value "${state.prop}"`,
+ },
+ 1,
+ );
+ })
+ .then((stack) => {
+ if (!cancelled) {
+ setSourcePreview({type: 'loaded', stack});
+ }
+ })
+ .catch((err: unknown) => {
+ if (!cancelled) {
+ setSourcePreview({
+ type: 'error',
+ message: err instanceof Error ? err.message : String(err),
+ });
+ }
+ });
+
+ return () => {
+ cancelled = true;
+ };
+ }, [state.location, state.prop]);
+
const onCopyPrompt = useCallback(() => {
copyText(prompt)
.then(markPromptCopied)
@@ -147,30 +255,116 @@ export const FixComputedValueModal: React.FC<{
<DismissableModal panelStyle={panelStyle}>
<ModalHeader title="Fix computed value" />
<div style={container}>
- {state.remotionInteractivitySkillAvailable ? null : (
+ <div style={text}>
+ This value cannot be interactively edited because it is computed:
+ </div>
+ {sourcePreview.type === 'loaded' ? (
+ <div style={sourcePreviewContainer}>
+ <StackElement
+ collapsible={false}
+ defaultFunctionName={null}
+ editorId={canOpenInEditor ? defaultEditorId : null}
+ fontSize={13}
+ headerAction={
+ canOpenSourceInEditor ? (
+ <OpenInEditor
+ canHaveKeyboardShortcuts={false}
+ editorId={defaultEditorId}
+ editorName={defaultEditorName}
+ size="compact"
+ stack={sourcePreview.stack}
+ />
+ ) : null
+ }
+ horizontalSpacing={0}
+ isFirst
+ lineNumberWidth={
+ String(
+ Math.max(
+ 0,
+ ...(sourcePreview.stack.originalScriptCode ?? []).map(
+ (line) => line.lineNumber,
+ ),
+ ),
+ ).length
+ }
+ s={sourcePreview.stack}
+ />
+ </div>
+ ) : (
+ <div style={sourcePreviewStatus}>
+ {sourcePreview.type === 'loading'
+ ? 'Loading code preview...'
+ : `Could not load code preview: ${sourcePreview.message}`}
+ </div>
+ )}
+ {remotionInteractivitySkillAvailable ? null : (
+ <div style={text}>You can ask an agent to restructure the code.</div>
+ )}
+ {remotionInteractivitySkillAvailable ? null : (
<>
- <div style={text}>First, install the Remotion Agent Skills:</div>
- <div style={commandField}>
- <pre style={code}>{installCommand}</pre>
- <InlineAction
- style={copyAction}
- variant={null}
- onClick={onCopyInstallCommand}
- renderAction={renderInstallCommandCopyAction}
- title="Copy command"
- />
- </div>
+ <div style={text}>Install the Agent Skill first:</div>
+ {canInstallSkill && interactivitySkill ? (
+ <div
+ aria-label="Remotion Agent Skills"
+ role="list"
+ style={skillRowContainer}
+ >
+ <SkillSettingsRow isLast={false} skill={interactivitySkill} />
+ </div>
+ ) : (
+ <div style={commandField}>
+ <pre style={code}>{installCommand}</pre>
+ <InlineAction
+ style={copyAction}
+ variant={null}
+ onClick={onCopyInstallCommand}
+ renderAction={renderInstallCommandCopyAction}
+ title="Copy command"
+ />
+ </div>
+ )}
+ {skillActionError ? (
+ <div style={skillError}>
+ <ValidationMessage
+ align="flex-start"
+ message={skillActionError}
+ type="error"
+ />
+ </div>
+ ) : null}
</>
)}
<div
style={{
- ...text,
- marginTop: state.remotionInteractivitySkillAvailable ? 0 : 16,
+ ...agentPromptHeader,
+ marginTop: remotionInteractivitySkillAvailable ? 0 : 16,
}}
>
- {state.remotionInteractivitySkillAvailable
- ? 'Paste this prompt into your coding agent to make this value editable in Studio:'
- : 'Then, paste this prompt into your coding agent:'}
+ <div>
+ {remotionInteractivitySkillAvailable ? (
+ <>
+ <div style={text}>
+ You can ask an agent to restructure the code.
+ </div>
+ <div style={text}>
+ Use this prompt to make this value editable:
+ </div>
+ </>
+ ) : (
+ <div style={text}>
+ Then use this prompt to make the value editable:
+ </div>
+ )}
+ </div>
+ {hasCodingAgent ? (
+ <CodingAgentButton
+ label="Open in"
+ prompt={prompt}
+ size="compact"
+ style={null}
+ />
+ ) : null}
</div>
<div style={commandField}>
<pre style={code}>
@@ -196,16 +390,6 @@ export const FixComputedValueModal: React.FC<{
/>
</div>
</div>
- {hasCodingAgent ? (
- <ModalFooterContainer style={footer}>
- <CodingAgentButton
- label="Open in"
- prompt={prompt}
- size="compact"
- style={null}
- />
- </ModalFooterContainer>
- ) : null}
</DismissableModal>
);
};
diff --git a/packages/studio/src/components/SkillsSettings.tsx b/packages/studio/src/components/SkillsSettings.tsx
index d14a5e3959..67dda075d7 100644
--- a/packages/studio/src/components/SkillsSettings.tsx
+++ b/packages/studio/src/components/SkillsSettings.tsx
@@ -1,3 +1,4 @@
+import type {GetRemotionSkillsInfoResponse} from '@remotion/studio-shared';
import React, {useCallback, useContext, useMemo} from 'react';
import {StudioServerConnectionCtx} from '../helpers/client-id';
import {
@@ -125,15 +126,76 @@ const loading: React.CSSProperties = {
marginTop: 14,
};
+export const SkillSettingsRow: React.FC<{
+ readonly isLast: boolean;
+ readonly skill: GetRemotionSkillsInfoResponse['skills'][number];
+}> = ({isLast, skill}) => {
+ const {installSkill, removeSkill, skillAction} = useSettings();
+ const {previewServerState} = useContext(StudioServerConnectionCtx);
+ const canInstall =
+ !window.remotion_isReadOnlyStudio &&
+ previewServerState.type === 'connected';
+ const installed = skill.installedInProject || skill.installedGlobally;
+ const processingThisSkill = skillAction?.skill === skill.name;
+ const installedLocation =
+ skill.installedInProject && skill.installedGlobally
+ ? 'Project and global'
+ : skill.installedInProject
+ ? 'Project'
+ : skill.installedGlobally
+ ? 'Global'
+ : null;
+ const renderInstallAction: RenderInlineAction = useCallback((color) => {
+ return <CloudDownloadIcon color={color} style={actionIcon} />;
+ }, []);
+ const renderRemoveAction: RenderInlineAction = useCallback((color) => {
+ return <TrashIcon color={color} style={actionIcon} />;
+ }, []);
+
+ return (
+ <div role="listitem" style={isLast ? lastSkillRow : skillRow}>
+ <span style={skillName}>/{skill.name}</span>
+ {processingThisSkill ? (
+ <span style={status}>
+ {skillAction.type === 'installing' ? 'Installing…' : 'Removing…'}
+ </span>
+ ) : installedLocation ? (
+ <span style={status}>{installedLocation}</span>
+ ) : null}
+ {installed ? (
+ <CheckCircleFilled aria-hidden style={{...statusIcon, fill: BLUE}} />
+ ) : null}
+ {processingThisSkill ? (
+ <span style={actionSlot}>
+ <Spinner duration={0.5} size={14} />
+ </span>
+ ) : installed && canInstall ? (
+ <InlineAction
+ title={
+ skill.installedInProject
+ ? `Remove ${skill.name} from this project`
+ : `Remove ${skill.name} globally`
+ }
+ disabled={skillAction !== null}
+ onClick={() => removeSkill(skill.name)}
+ renderAction={renderRemoveAction}
+ variant={null}
+ />
+ ) : canInstall ? (
+ <InlineAction
+ title={`Install ${skill.name} in this project`}
+ disabled={skillAction !== null}
+ onClick={() => installSkill(skill.name)}
+ renderAction={renderInstallAction}
+ variant={null}
+ />
+ ) : null}
+ </div>
+ );
+};
+
export const SkillsSettings: React.FC = () => {
- const {
- error,
- remotionSkillsInfo,
- installSkill,
- removeSkill,
- skillAction,
- skillActionError,
- } = useSettings();
+ const {error, remotionSkillsInfo, skillActionError} = useSettings();
const {previewServerState} = useContext(StudioServerConnectionCtx);
const canInstall =
!window.remotion_isReadOnlyStudio &&
@@ -163,14 +225,6 @@ export const SkillsSettings: React.FC = () => {
},
[copied],
);
- const renderInstallAction: RenderInlineAction = useCallback((color) => {
- return <CloudDownloadIcon color={color} style={actionIcon} />;
- }, []);
- const renderRemoveAction: RenderInlineAction = useCallback((color) => {
- return <TrashIcon color={color} style={actionIcon} />;
- }, []);
- const actionInProgress = skillAction !== null;
-
return (
<div style={container}>
{remotionSkillsInfo === null && error === null ? (
@@ -215,70 +269,12 @@ export const SkillsSettings: React.FC = () => {
{remotionSkillsInfo ? (
<div style={list} role="list" aria-label="Remotion Agent Skills">
{remotionSkillsInfo.skills.map((skill, index) => {
- const installed =
- skill.installedInProject || skill.installedGlobally;
- const processingThisSkill = skillAction?.skill === skill.name;
- const installedLocation =
- skill.installedInProject && skill.installedGlobally
- ? 'Project and global'
- : skill.installedInProject
- ? 'Project'
- : skill.installedGlobally
- ? 'Global'
- : null;
-
return (
- <div
+ <SkillSettingsRow
key={skill.name}
- role="listitem"
- style={
- index === remotionSkillsInfo.skills.length - 1
- ? lastSkillRow
- : skillRow
- }
- >
- <span style={skillName}>/{skill.name}</span>
- {processingThisSkill ? (
- <span style={status}>
- {skillAction.type === 'installing'
- ? 'Installing…'
- : 'Removing…'}
- </span>
- ) : installedLocation ? (
- <span style={status}>{installedLocation}</span>
- ) : null}
- {installed ? (
- <CheckCircleFilled
- aria-hidden
- style={{...statusIcon, fill: BLUE}}
- />
- ) : null}
- {processingThisSkill ? (
- <span style={actionSlot}>
- <Spinner duration={0.5} size={14} />
- </span>
- ) : installed && canInstall ? (
- <InlineAction
- title={
- skill.installedInProject
- ? `Remove ${skill.name} from this project`
- : `Remove ${skill.name} globally`
- }
- disabled={actionInProgress}
- onClick={() => removeSkill(skill.name)}
- renderAction={renderRemoveAction}
- variant={null}
- />
- ) : canInstall ? (
- <InlineAction
- title={`Install ${skill.name} in this project`}
- disabled={actionInProgress}
- onClick={() => installSkill(skill.name)}
- renderAction={renderInstallAction}
- variant={null}
- />
- ) : null}
- </div>
+ isLast={index === remotionSkillsInfo.skills.length - 1}
+ skill={skill}
+ />
);
})}
</div>
diff --git a/packages/studio/src/components/Timeline/TimelineSchemaField.tsx b/packages/studio/src/components/Timeline/TimelineSchemaField.tsx
index 74d1584858..1b20ad2294 100644
--- a/packages/studio/src/components/Timeline/TimelineSchemaField.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSchemaField.tsx
@@ -22,7 +22,6 @@ import type {
TimelineFieldOnSave,
} from '../../helpers/timeline-layout';
import {SetSelectedModalContext} from '../../state/modals';
-import {useSettings} from '../SettingsContext';
import {formatTimelineFieldValueForDisplay} from './timeline-field-display-utils';
import {TimelineArrayField} from './TimelineArrayField';
import {
@@ -154,16 +153,13 @@ export const TimelineNonEditableStatus: React.FC<{
readonly validatedLocation: CodePosition;
}> = ({propStatus, field, runtimeValue, validatedLocation}) => {
const {setSelectedModal} = useContext(SetSelectedModalContext);
- const {remotionSkillsInfo} = useSettings();
const onFix = useCallback(() => {
setSelectedModal({
type: 'fix-computed-value',
prop: field.key,
- context: `${validatedLocation.source}:${validatedLocation.line}:${validatedLocation.column}`,
- remotionInteractivitySkillAvailable:
- remotionSkillsInfo?.remotionInteractivitySkillAvailable ?? false,
+ location: validatedLocation,
});
- }, [field.key, remotionSkillsInfo, setSelectedModal, validatedLocation]);
+ }, [field.key, setSelectedModal, validatedLocation]);
if (propStatus.status === 'computed') {
return (
diff --git a/packages/studio/src/error-overlay/remotion-overlay/CodeFrame.tsx b/packages/studio/src/error-overlay/remotion-overlay/CodeFrame.tsx
index c9b3248a3a..df026169ed 100644
--- a/packages/studio/src/error-overlay/remotion-overlay/CodeFrame.tsx
+++ b/packages/studio/src/error-overlay/remotion-overlay/CodeFrame.tsx
@@ -21,8 +21,6 @@ const frame: React.CSSProperties = {
backgroundColor: ERROR_CODE_FRAME_BACKGROUND,
borderRadius: 6,
marginBottom: 20,
- marginLeft: 14,
- marginRight: 14,
overflowY: 'auto',
};
@@ -30,7 +28,6 @@ const lineNumber: React.CSSProperties = {
whiteSpace: 'pre',
paddingRight: 12,
color: 'inherit',
- fontSize: 14,
lineHeight: 1.7,
width: 60,
flexShrink: 0,
@@ -43,9 +40,18 @@ const lineNumber: React.CSSProperties = {
export const CodeFrame: React.FC<{
readonly source: ScriptLine[];
readonly lineNumberWidth: number;
-}> = ({source, lineNumberWidth}) => {
+ readonly fontSize: number;
+ readonly horizontalMargin: number;
+}> = ({source, lineNumberWidth, fontSize, horizontalMargin}) => {
return (
- <div style={frame} className={HORIZONTAL_SCROLLBAR_CLASSNAME}>
+ <div
+ style={{
+ ...frame,
+ marginLeft: horizontalMargin,
+ marginRight: horizontalMargin,
+ }}
+ className={HORIZONTAL_SCROLLBAR_CLASSNAME}
+ >
{/* Keep every row as wide as the longest line when scrolling. */}
<div style={{minWidth: '100%', width: 'max-content'}}>
{source.map((s, j) => {
@@ -63,6 +69,7 @@ export const CodeFrame: React.FC<{
<div
style={{
...lineNumber,
+ fontSize,
backgroundColor: s.highlight
? TRANSPARENT
: ERROR_CODE_FRAME_LINE_BACKGROUND,
@@ -75,7 +82,7 @@ export const CodeFrame: React.FC<{
className="language-tsx"
style={{
fontFamily: 'monospace',
- fontSize: 14,
+ fontSize,
color: '#9cdcfe',
whiteSpace: 'pre',
tabSize: 2,
diff --git a/packages/studio/src/error-overlay/remotion-overlay/ErrorDisplay.tsx b/packages/studio/src/error-overlay/remotion-overlay/ErrorDisplay.tsx
index 815a9bf0f5..9a52e42b8e 100644
--- a/packages/studio/src/error-overlay/remotion-overlay/ErrorDisplay.tsx
+++ b/packages/studio/src/error-overlay/remotion-overlay/ErrorDisplay.tsx
@@ -177,6 +177,7 @@ export const ErrorDisplay: React.FC<{
canHaveKeyboardShortcuts={keyboardShortcuts}
editorId={defaultEditorId}
editorName={defaultEditorName}
+ size="default"
stack={stackFrames[0]}
/>
<div style={spacer} />
@@ -227,8 +228,12 @@ export const ErrorDisplay: React.FC<{
<StackElement
// eslint-disable-next-line react/no-array-index-key
key={i}
+ collapsible
isFirst={i === 0}
s={s}
+ fontSize={14}
+ headerAction={null}
+ horizontalSpacing={14}
lineNumberWidth={lineNumberWidth}
defaultFunctionName={'(anonymous function)'}
editorId={canOpenInEditor ? defaultEditorId : null}
diff --git a/packages/studio/src/error-overlay/remotion-overlay/OpenInEditor.tsx b/packages/studio/src/error-overlay/remotion-overlay/OpenInEditor.tsx
index 8ce09af3ba..e27a99bddc 100644
--- a/packages/studio/src/error-overlay/remotion-overlay/OpenInEditor.tsx
+++ b/packages/studio/src/error-overlay/remotion-overlay/OpenInEditor.tsx
@@ -25,7 +25,8 @@ export const OpenInEditor: React.FC<{
readonly canHaveKeyboardShortcuts: boolean;
readonly editorId: EditorPickerId;
readonly editorName: string;
-}> = ({stack, canHaveKeyboardShortcuts, editorId, editorName}) => {
+ readonly size: 'compact' | 'default';
+}> = ({stack, canHaveKeyboardShortcuts, editorId, editorName, size}) => {
const {editorInfo} = useSettings();
const configureDefaultApps = useConfigureDefaultApps();
const {registerKeybinding} = useKeybinding();
@@ -96,11 +97,11 @@ export const OpenInEditor: React.FC<{
menuItems={menuItems}
onConfigureApps={configureDefaultApps}
onClick={openPreferredEditor}
- size="default"
+ size={size}
style={null}
title={`Open in ${editorName}`}
>
- <EditorIcon editorId={editorId} size={14} />
+ <EditorIcon editorId={editorId} size={size === 'default' ? 14 : 18} />
Open in {editorName}
{canHaveKeyboardShortcuts ? (
<ShortcutHint keyToPress="o" cmdOrCtrl />
diff --git a/packages/studio/src/error-overlay/remotion-overlay/StackFrame.tsx b/packages/studio/src/error-overlay/remotion-overlay/StackFrame.tsx
index 1ae5690dc8..45b3acabcf 100644
--- a/packages/studio/src/error-overlay/remotion-overlay/StackFrame.tsx
+++ b/packages/studio/src/error-overlay/remotion-overlay/StackFrame.tsx
@@ -4,7 +4,17 @@ import type {
} from '@remotion/studio-shared';
import React, {useCallback, useState} from 'react';
import {Button} from '../../components/Button';
-import {BORDER_WHITE_ALPHA_12, LIGHT_TEXT, WHITE} from '../../helpers/colors';
+import {
+ BORDER_WHITE_ALPHA_12,
+ LIGHT_TEXT,
+ TRANSPARENT,
+ WHITE,
+} from '../../helpers/colors';
+import {
+ FOCUS_VISIBLE_ONLY_CLASS_NAME,
+ HOVERABLE_CLASS_NAME,
+ hoverableStyle,
+} from '../../helpers/hoverable';
import {openInEditor} from '../../helpers/open-in-editor';
import {CaretDown} from '../../icons/caret';
import {CodeFrame} from './CodeFrame';
@@ -13,15 +23,12 @@ import {formatLocation} from './format-location';
const location: React.CSSProperties = {
color: LIGHT_TEXT,
fontFamily: 'monospace',
- fontSize: 14,
overflowWrap: 'anywhere',
};
const header: React.CSSProperties = {
- paddingLeft: 14,
paddingTop: 10,
paddingBottom: 10,
- paddingRight: 14,
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
@@ -34,7 +41,6 @@ const left: React.CSSProperties = {
};
const fnName: React.CSSProperties = {
- fontSize: 14,
lineHeight: 1.5,
marginBottom: 3,
};
@@ -43,16 +49,29 @@ export const StackElement: React.FC<{
readonly s: SymbolicatedStackFrame;
readonly lineNumberWidth: number;
readonly isFirst: boolean;
- readonly defaultFunctionName: string;
+ readonly defaultFunctionName: string | null;
readonly editorId: EditorPickerId | null;
-}> = ({s, lineNumberWidth, isFirst, defaultFunctionName, editorId}) => {
+ readonly collapsible: boolean;
+ readonly fontSize: number;
+ readonly horizontalSpacing: number;
+ readonly headerAction: React.ReactNode;
+}> = ({
+ s,
+ lineNumberWidth,
+ isFirst,
+ defaultFunctionName,
+ editorId,
+ collapsible,
+ fontSize,
+ horizontalSpacing,
+ headerAction,
+}) => {
const [showCodeFrame, setShowCodeFrame] = useState(
() =>
(!s.originalFileName?.includes('node_modules') &&
!s.originalFileName?.startsWith('webpack/')) ||
isFirst,
);
- const [locationHovered, setLocationHovered] = useState(false);
const canOpenFileLocation = Boolean(editorId && s.originalFileName);
const onOpenFileLocation = useCallback(() => {
if (!canOpenFileLocation) {
@@ -71,38 +90,48 @@ export const StackElement: React.FC<{
const toggleCodeFrame = useCallback(() => {
setShowCodeFrame((f) => !f);
}, []);
+ const functionName = s.originalFunctionName ?? defaultFunctionName;
+ const shouldShowCodeFrame = collapsible ? showCodeFrame : true;
return (
<div className="css-reset">
<div
style={{
...header,
- borderBottom: showCodeFrame ? 'none' : BORDER_WHITE_ALPHA_12,
+ borderBottom: shouldShowCodeFrame ? 'none' : BORDER_WHITE_ALPHA_12,
+ paddingLeft: horizontalSpacing,
+ paddingRight: horizontalSpacing,
}}
>
<div style={left}>
- <div style={fnName}>
- {s.originalFunctionName ?? defaultFunctionName}
- </div>
+ {functionName === null ? null : (
+ <div style={{...fnName, fontSize}}>{functionName}</div>
+ )}
{s.originalFileName ? (
- <div style={location}>
+ <div style={{...location, fontSize}}>
{canOpenFileLocation ? (
- <span
+ <button
+ type="button"
+ className={`${HOVERABLE_CLASS_NAME} ${FOCUS_VISIBLE_ONLY_CLASS_NAME}`}
onClick={onOpenFileLocation}
- onPointerEnter={() => {
- setLocationHovered(true);
- }}
- onPointerLeave={() => {
- setLocationHovered(false);
- }}
style={{
...location,
- color: locationHovered ? WHITE : LIGHT_TEXT,
- cursor: 'pointer',
+ ...hoverableStyle({
+ idleBackground: TRANSPARENT,
+ hoverBackground: TRANSPARENT,
+ idleColor: LIGHT_TEXT,
+ hoverColor: WHITE,
+ }),
+ appearance: 'none',
+ border: 'none',
+ color: undefined,
+ cursor: 'default',
+ fontSize,
+ padding: 0,
}}
>
{formatLocation(s.originalFileName as string)}:
{s.originalLineNumber}
- </span>
+ </button>
) : (
<>
{formatLocation(s.originalFileName as string)}:
@@ -112,12 +141,15 @@ export const StackElement: React.FC<{
</div>
) : null}
</div>
- {s.originalScriptCode && s.originalScriptCode.length > 0 ? (
+ {headerAction}
+ {collapsible &&
+ s.originalScriptCode &&
+ s.originalScriptCode.length > 0 ? (
<Button onClick={toggleCodeFrame}>
<div
style={{
display: 'flex',
- transform: showCodeFrame ? undefined : 'rotate(-90deg)',
+ transform: shouldShowCodeFrame ? undefined : 'rotate(-90deg)',
}}
>
<CaretDown />
@@ -128,8 +160,10 @@ export const StackElement: React.FC<{
<div>
{s.originalScriptCode &&
s.originalScriptCode.length > 0 &&
- showCodeFrame ? (
+ shouldShowCodeFrame ? (
<CodeFrame
+ fontSize={fontSize}
+ horizontalMargin={horizontalSpacing}
lineNumberWidth={lineNumberWidth}
source={s.originalScriptCode}
/>
diff --git a/packages/studio/src/helpers/open-in-editor.ts b/packages/studio/src/helpers/open-in-editor.ts
index 51dc3cc68d..186e4a90e0 100644
--- a/packages/studio/src/helpers/open-in-editor.ts
+++ b/packages/studio/src/helpers/open-in-editor.ts
@@ -1,10 +1,11 @@
import type {DefaultCodingAgent} from '@remotion/renderer';
-import type {GitClientId, TerminalId} from '@remotion/studio-shared';
import type {
CompositionComponentInfoResponse,
EditorPickerId,
+ GitClientId,
OpenInTerminalResponse,
SymbolicatedStackFrame,
+ TerminalId,
} from '@remotion/studio-shared';
import {useEffect} from 'react';
import {callApi} from '../components/call-api';
@@ -77,15 +78,13 @@ export const openOriginalPositionInEditor = async (
}
};
-export const openOriginalPositionInEditorAtProperty = async ({
- editorId,
+export const findOriginalPositionInFileAtProperty = async ({
originalPosition,
property,
}: {
- editorId: EditorPickerId;
originalPosition: CodePosition;
property: string;
-}) => {
+}): Promise<CodePosition> => {
const request = {
fileName: originalPosition.source,
lineNumber: originalPosition.line,
@@ -97,14 +96,28 @@ export const openOriginalPositionInEditorAtProperty = async ({
? await browserStudioOperations.findInFile(request)
: await callApi('/api/find-in-file', request);
- await openOriginalPositionInEditor(
- {
- source: originalPosition.source,
- line: position.lineNumber,
- column: position.columnNumber,
- },
- editorId,
- );
+ return {
+ source: originalPosition.source,
+ line: position.lineNumber,
+ column: position.columnNumber,
+ };
+};
+
+export const openOriginalPositionInEditorAtProperty = async ({
+ editorId,
+ originalPosition,
+ property,
+}: {
+ editorId: EditorPickerId;
+ originalPosition: CodePosition;
+ property: string;
+}) => {
+ const position = await findOriginalPositionInFileAtProperty({
+ originalPosition,
+ property,
+ });
+
+ await openOriginalPositionInEditor(position, editorId);
};
type ResolvedCompositionComponentInfo = {
diff --git a/packages/studio/src/state/modals.ts b/packages/studio/src/state/modals.ts
index f8bbf3fd6c..653c190590 100644
--- a/packages/studio/src/state/modals.ts
+++ b/packages/studio/src/state/modals.ts
@@ -260,8 +260,11 @@ export type ModalState =
| {
type: 'fix-computed-value';
prop: string;
- context: string;
- remotionInteractivitySkillAvailable: boolean;
+ location: {
+ source: string;
+ line: number;
+ column: number;
+ };
}
| {
type: 'quick-switcher';