Skip to content

🎥 Make videos programmatically with React

Add split clip action to inspector (#9319)

Jonny Burger2b47829ce4a0
diff --git a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx
index b0e4a8b27f..8963b31c92 100644
--- a/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx
+++ b/packages/studio/src/components/InspectorPanel/SequenceSelectionInspector.tsx
@@ -1,11 +1,17 @@
import React, {useCallback, useContext, useMemo} from 'react';
+import {Internals} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import type {TrackWithHash} from '../../helpers/get-timeline-sequence-sort-key';
+import {ScissorsIcon} from '../../icons/scissors';
import {
hasSequenceControls,
InspectorSequenceSection,
} from '../InspectorSequenceSection';
import {VERTICAL_SCROLLBAR_CLASSNAME} from '../Menu/is-menu-item';
+import {
+ getTimelineSequenceSplitEligibility,
+ splitTimelineSequenceFromSource,
+} from '../Timeline/split-selected-timeline-item';
import {
getTimelineSelectionKey,
type TimelineSelection,
@@ -13,9 +19,9 @@ import {
} from '../Timeline/TimelineSelection';
import {AlignmentControls} from './AlignmentControls';
import {
+ InspectorInlineAction,
InspectorMessage,
InspectorSectionDivider,
- InspectorSectionHeader,
} from './common';
import {
ConnectedCompositionsSection,
@@ -26,9 +32,82 @@ import {
SequenceInspectorHeader,
useSequenceInspectorSourceLocation,
} from './SequenceInspectorHeader';
-import {selectedContainer} from './styles';
+import {detailsContainer, selectedContainer} from './styles';
import {useTrackForSelection} from './use-track-for-selection';
+const splitIconStyle: React.CSSProperties = {
+ height: 13,
+ width: 13,
+};
+
+const splitActionContainer: React.CSSProperties = {
+ ...detailsContainer,
+ paddingBottom: 6,
+ paddingTop: 6,
+};
+
+const splitActionButton: React.CSSProperties = {
+ width: '100%',
+};
+
+const SplitSequenceAction: React.FC<{
+ readonly selection: Extract<TimelineSelection, {type: 'sequence'}>;
+ readonly track: TrackWithHash;
+}> = ({selection, track}) => {
+ const timelinePosition = Internals.Timeline.useTimelinePosition();
+ const {propStatuses} = useContext(Internals.VisualModePropStatusesContext);
+ const sequencePropStatuses = useMemo(
+ () =>
+ Internals.getPropStatusesCtx(
+ propStatuses,
+ selection.nodePathInfo.sequenceSubscriptionKey,
+ ),
+ [propStatuses, selection],
+ );
+ const eligibility = useMemo(
+ () =>
+ getTimelineSequenceSplitEligibility({
+ selection,
+ sequence: track.sequence,
+ splitFrame: timelinePosition,
+ propStatuses: sequencePropStatuses,
+ }),
+ [selection, sequencePropStatuses, timelinePosition, track.sequence],
+ );
+ const onSplit = useCallback(() => {
+ if (!eligibility.canSplit) {
+ return;
+ }
+
+ splitTimelineSequenceFromSource({
+ nodePathInfo: eligibility.nodePathInfo,
+ splitFrame: timelinePosition,
+ }).catch(() => undefined);
+ }, [eligibility, timelinePosition]);
+
+ if (!eligibility.canSplit) {
+ return null;
+ }
+
+ return (
+ <>
+ <InspectorSectionDivider />
+ <div style={splitActionContainer}>
+ <InspectorInlineAction
+ disabled={false}
+ onClick={onSplit}
+ style={splitActionButton}
+ renderIcon={(color) => (
+ <ScissorsIcon style={splitIconStyle} color={color} />
+ )}
+ >
+ Split clip
+ </InspectorInlineAction>
+ </div>
+ </>
+ );
+};
+
const SequenceExpandedInspector: React.FC<{
readonly track: TrackWithHash;
}> = ({track}) => {
@@ -37,7 +116,10 @@ const SequenceExpandedInspector: React.FC<{
const sourceLocation = useSequenceInspectorSourceLocation(track.sequence);
const connectedCompositions = useConnectedCompositions({track});
const {validatedLocation} = sourceLocation;
- const sequenceSelection = useMemo((): TimelineSelection | null => {
+ const sequenceSelection = useMemo((): Extract<
+ TimelineSelection,
+ {type: 'sequence'}
+ > | null => {
if (!track.nodePathInfo) {
return null;
}
@@ -79,6 +161,7 @@ const SequenceExpandedInspector: React.FC<{
if (
!track.nodePathInfo ||
+ sequenceSelection === null ||
!hasSequenceControls(track.sequence) ||
!validatedLocation
) {
@@ -100,17 +183,14 @@ const SequenceExpandedInspector: React.FC<{
/>
</>
) : null}
- <InspectorSectionDivider />
<InspectorSequenceSection
sequence={track.sequence}
validatedLocation={validatedLocation}
nodePathInfo={track.nodePathInfo}
keyframeDisplayOffset={track.keyframeDisplayOffset}
- renderSectionHeader={(children) => (
- <InspectorSectionHeader>{children}</InspectorSectionHeader>
- )}
renderTransformControls={() => <AlignmentControls track={track} />}
/>
+ <SplitSequenceAction selection={sequenceSelection} track={track} />
</div>
);
};
diff --git a/packages/studio/src/components/InspectorPanel/common.tsx b/packages/studio/src/components/InspectorPanel/common.tsx
index 02112af28b..cd25ea5025 100644
--- a/packages/studio/src/components/InspectorPanel/common.tsx
+++ b/packages/studio/src/components/InspectorPanel/common.tsx
@@ -10,6 +10,7 @@ import {
detailLabel,
detailRow,
detailValue,
+ inspectorSectionBody,
inspectorSectionDivider,
resolveLinkStyle,
sectionHeader,
@@ -25,6 +26,21 @@ export const InspectorSectionDivider: React.FC = () => (
<div style={inspectorSectionDivider} />
);
+export const InspectorSection: React.FC<{
+ readonly children: React.ReactNode;
+ readonly header: React.ReactNode;
+}> = ({children, header}) => {
+ return (
+ <>
+ <InspectorSectionDivider />
+ <InspectorSectionHeader>{header}</InspectorSectionHeader>
+ {children === null ? null : (
+ <div style={inspectorSectionBody}>{children}</div>
+ )}
+ </>
+ );
+};
+
const backIcon: React.CSSProperties = {
alignItems: 'center',
display: 'flex',
@@ -132,15 +148,17 @@ export const InspectorInlineAction: React.FC<{
readonly disabled: boolean;
readonly onClick: React.MouseEventHandler<HTMLButtonElement>;
readonly renderIcon: (color: string) => React.ReactNode;
-}> = ({children, disabled, onClick, renderIcon}) => {
+ readonly style?: React.CSSProperties;
+}> = ({children, disabled, onClick, renderIcon, style}) => {
const [hovered, setHovered] = React.useState(false);
const color = hovered && !disabled ? WHITE : LIGHT_TEXT;
const buttonStyle = React.useMemo(
(): React.CSSProperties => ({
...(disabled ? inlineLabelButtonDisabled : inlineLabelButton),
color,
+ ...style,
}),
- [color, disabled],
+ [color, disabled, style],
);
const textStyle = React.useMemo(
(): React.CSSProperties => ({
diff --git a/packages/studio/src/components/InspectorPanel/styles.ts b/packages/studio/src/components/InspectorPanel/styles.ts
index e7bfcac3cf..96cb429749 100644
--- a/packages/studio/src/components/InspectorPanel/styles.ts
+++ b/packages/studio/src/components/InspectorPanel/styles.ts
@@ -57,6 +57,13 @@ export const sectionHeader: React.CSSProperties = {
userSelect: 'none',
};
+export const inspectorSectionBody: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'column',
+ minWidth: 0,
+ paddingBottom: 8,
+};
+
export const sequenceHeader: React.CSSProperties = {
backgroundColor: BACKGROUND,
display: 'flex',
diff --git a/packages/studio/src/components/InspectorSequenceSection.tsx b/packages/studio/src/components/InspectorSequenceSection.tsx
index f1ac274779..42c767bf01 100644
--- a/packages/studio/src/components/InspectorSequenceSection.tsx
+++ b/packages/studio/src/components/InspectorSequenceSection.tsx
@@ -5,8 +5,8 @@ import {StudioServerConnectionCtx} from '../helpers/client-id';
import {LIGHT_TEXT, WHITE} from '../helpers/colors';
import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';
import {
- SCHEMA_FIELD_GROUPS,
flattenVisibleTreeNodes,
+ SCHEMA_FIELD_GROUPS,
type FlatTreeRow,
type SchemaFieldGroupInfo,
type TimelineTreeNode,
@@ -15,15 +15,12 @@ import {Plus} from '../icons/plus';
import {ModalsContext} from '../state/modals';
import {AssetInfo} from './CurrentAsset';
import {InlineAction} from './InlineAction';
-import {
- sectionHeaderRow,
- sectionHeaderTitle,
- sequenceHeaderDivider,
-} from './InspectorPanel/styles';
+import {InspectorSection} from './InspectorPanel/common';
+import {sectionHeaderRow, sectionHeaderTitle} from './InspectorPanel/styles';
import {INSPECTOR_PANEL_HORIZONTAL_PADDING} from './InspectorPanelLayout';
import {
- getTimelineAssetSrcFromSchema,
getTimelineAssetLinkInfo,
+ getTimelineAssetSrcFromSchema,
openTimelineAssetLink,
splitRemoteSourceForMiddleEllipsis,
} from './Timeline/timeline-asset-link';
@@ -53,12 +50,7 @@ const emptyState: React.CSSProperties = {
fontFamily: 'sans-serif',
fontSize: 12,
lineHeight: 1.4,
- padding: '0 12px 8px',
-};
-
-const controlsEffectsDivider: React.CSSProperties = {
- ...sequenceHeaderDivider,
- margin: '8px 0 4px',
+ padding: '0 12px',
};
const effectsHeaderTitle: React.CSSProperties = {
@@ -202,14 +194,12 @@ export const InspectorSequenceSection: React.FC<{
readonly validatedLocation: CodePosition;
readonly nodePathInfo: SequenceNodePathInfo;
readonly keyframeDisplayOffset: number;
- readonly renderSectionHeader: (children: React.ReactNode) => React.ReactNode;
readonly renderTransformControls: () => React.ReactNode;
}> = ({
sequence,
validatedLocation,
nodePathInfo,
keyframeDisplayOffset,
- renderSectionHeader,
renderTransformControls,
}) => {
const {tree} = useTimelineExpandedTree({
@@ -312,8 +302,6 @@ export const InspectorSequenceSection: React.FC<{
const {schema} = sequence.controls;
const showEffectsSection =
nodePathInfo.supportsEffects || effectRows.length > 0;
- const showControlsEffectsDivider =
- controlRows.length > 0 && showEffectsSection;
const canAddEffect =
nodePathInfo.supportsEffects &&
previewServerState.type === 'connected' &&
@@ -338,19 +326,17 @@ export const InspectorSequenceSection: React.FC<{
validatedLocation.source,
]);
- const renderEffectsHeader = () => {
- return renderSectionHeader(
- <div style={sectionHeaderRow}>
- <div style={effectsHeaderTitle}>Effects</div>
- <InlineAction
- disabled={!canAddEffect}
- onClick={onAddEffect}
- title={canAddEffect ? 'Add effect' : undefined}
- renderAction={(color) => <Plus color={color} style={plusIcon} />}
- />
- </div>,
- );
- };
+ const effectsHeader = (
+ <div style={sectionHeaderRow}>
+ <div style={effectsHeaderTitle}>Effects</div>
+ <InlineAction
+ disabled={!canAddEffect}
+ onClick={onAddEffect}
+ title={canAddEffect ? 'Add effect' : undefined}
+ renderAction={(color) => <Plus color={color} style={plusIcon} />}
+ />
+ </div>
+ );
const renderRow = ({node, depth}: FlatTreeRow) => {
return (
@@ -378,7 +364,9 @@ export const InspectorSequenceSection: React.FC<{
if (controlRows.length === 0 && !showEffectsSection) {
return (
<div style={container}>
- <div style={emptyState}>No schema</div>
+ <InspectorSection header="Controls">
+ <div style={emptyState}>No schema</div>
+ </InspectorSection>
</div>
);
}
@@ -387,10 +375,8 @@ export const InspectorSequenceSection: React.FC<{
<div style={container}>
{controlRows.length > 0 ? (
<TimelineSelectionOrderProvider items={controlSelectableItems}>
- {controlGroups.map((group, i) => (
- <React.Fragment key={group.id}>
- {i === 0 ? null : <div style={controlsEffectsDivider} />}
- {renderSectionHeader(group.label)}
+ {controlGroups.map((group) => (
+ <InspectorSection key={group.id} header={group.label}>
{group.id === 'source' && localAsset ? (
<AssetInfo
assetName={localAsset.assetPath}
@@ -411,22 +397,18 @@ export const InspectorSequenceSection: React.FC<{
) : null}
{group.id === 'transforms' ? renderTransformControls() : null}
{group.id === 'source' ? null : group.rows.map(renderRow)}
- </React.Fragment>
+ </InspectorSection>
))}
</TimelineSelectionOrderProvider>
) : null}
{showEffectsSection ? (
- <>
- {showControlsEffectsDivider ? (
- <div style={controlsEffectsDivider} />
- ) : null}
- {renderEffectsHeader()}
+ <InspectorSection header={effectsHeader}>
{effectRows.length > 0 ? (
<TimelineSelectionOrderProvider items={effectSelectableItems}>
{effectRows.map(renderRow)}
</TimelineSelectionOrderProvider>
) : null}
- </>
+ </InspectorSection>
) : null}
</div>
);
diff --git a/packages/studio/src/icons/scissors.tsx b/packages/studio/src/icons/scissors.tsx
new file mode 100644
index 0000000000..dc2f9dead1
--- /dev/null
+++ b/packages/studio/src/icons/scissors.tsx
@@ -0,0 +1,16 @@
+import type {SVGProps} from 'react';
+import React from 'react';
+
+export const ScissorsIcon: React.FC<SVGProps<SVGSVGElement>> = (props) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 640 640"
+ fill="currentColor"
+ stroke="currentColor"
+ {...props}
+ >
+ <path d="M256 320L216.5 359.5C203.9 354.6 190.3 352 176 352C114.1 352 64 402.1 64 464C64 525.9 114.1 576 176 576C237.9 576 288 525.9 288 464C288 449.7 285.3 436.1 280.5 423.5L563.2 140.8C570.3 133.7 570.3 122.3 563.2 115.2C534.9 86.9 489.1 86.9 460.8 115.2L320 256L280.5 216.5C285.4 203.9 288 190.3 288 176C288 114.1 237.9 64 176 64C114.1 64 64 114.1 64 176C64 237.9 114.1 288 176 288C190.3 288 203.9 285.3 216.5 280.5L256 320zM353.9 417.9L460.8 524.8C489.1 553.1 534.9 553.1 563.2 524.8C570.3 517.7 570.3 506.3 563.2 499.2L417.9 353.9L353.9 417.9zM128 176C128 149.5 149.5 128 176 128C202.5 128 224 149.5 224 176C224 202.5 202.5 224 176 224C149.5 224 128 202.5 128 176zM176 416C202.5 416 224 437.5 224 464C224 490.5 202.5 512 176 512C149.5 512 128 490.5 128 464C128 437.5 149.5 416 176 416z" />
+ </svg>
+ );
+};