Skip to content

Write HTML. Render video. Built for agents.

refactor(studio): split bulk easing helpers

Miguel Angel Simon Sierra23ab104aff7a
diff --git a/packages/studio/src/components/editor/PropertyPanelFlat.tsx b/packages/studio/src/components/editor/PropertyPanelFlat.tsx
index 049b1c5a4f..7b94479491 100644
--- a/packages/studio/src/components/editor/PropertyPanelFlat.tsx
+++ b/packages/studio/src/components/editor/PropertyPanelFlat.tsx
@@ -1,11 +1,9 @@
import { scopedElementKey } from "../../hooks/gsapKeyframeCacheHelpers";
import { type ReactNode, useEffect, useRef, useState } from "react";
-import { resolveEditingSections } from "@hyperframes/core/editing";
import { DesignPanelInputProvider } from "../../contexts/DesignPanelInputContext";
import { slugifyDesignInput } from "../../utils/designInputTracking";
-import type { DomEditSelection } from "./domEditing";
import { isTextEditableSelection } from "./domEditing";
-import type { PropertyPanelProps } from "./propertyPanelHelpers";
+import type { PropertyPanelFlatProps } from "./propertyPanelFlatProps";
import { formatPxMetricValue } from "./propertyPanelHelpers";
import { PropertyPanelFlatHeader } from "./PropertyPanelFlatHeader";
import { PropertyPanelFlatFooter } from "./PropertyPanelFlatFooter";
@@ -35,8 +33,6 @@ import {
FlatOverlaysSection,
} from "./propertyPanelFlatOverlaysSection";
-type EditingSections = ReturnType<typeof resolveEditingSections>;
-
type FlatGroupDescriptor = {
id: string;
title: string;
@@ -138,92 +134,7 @@ export function PropertyPanelFlat({
onUpdateKeyframeEase,
onUpdateSegmentEase,
onSetAllKeyframeEases,
-}: Pick<
- PropertyPanelProps,
- | "projectId"
- | "projectDir"
- | "assets"
- | "previewIframeRef"
- | "onClearSelection"
- | "onUngroup"
- | "onSetStyle"
- | "onPreviewStyle"
- | "onSetAttribute"
- | "onSetAttributes"
- | "onSetAttributeLive"
- | "onApplyColorGradingScope"
- | "onSetHtmlAttribute"
- | "onRemoveBackground"
- | "onSetText"
- | "onSetTextFieldStyle"
- | "onPreviewTextFieldStyle"
- | "onAddTextField"
- | "onRemoveTextField"
- | "onAskAgent"
- | "onToggleElementHidden"
- | "onImportAssets"
- | "onAddMediaOverlay"
- | "onImportFonts"
- | "fontAssets"
- | "gsapAnimations"
- | "gsapMultipleTimelines"
- | "gsapUnsupportedTimelinePattern"
- | "onUpdateGsapProperty"
- | "onUpdateGsapMeta"
- | "onDeleteGsapAnimation"
- | "onAddGsapProperty"
- | "onRemoveGsapProperty"
- | "onUpdateGsapFromProperty"
- | "onAddGsapFromProperty"
- | "onRemoveGsapFromProperty"
- | "onAddGsapAnimation"
- | "onSetArcPath"
- | "onUpdateArcSegment"
- | "onUnroll"
- | "onUpdateKeyframeEase"
- | "onSetAllKeyframeEases"
- | "onUpdateSegmentEase"
- | "recordingState"
- | "recordingDuration"
- | "onToggleRecording"
-> &
- Pick<
- Parameters<typeof FlatLayoutSection>[0],
- | "displayX"
- | "displayY"
- | "displayW"
- | "displayH"
- | "displayR"
- | "manualOffsetEditingDisabled"
- | "manualSizeEditingDisabled"
- | "manualRotationEditingDisabled"
- | "commitManualOffset"
- | "commitManualSize"
- | "commitManualRotation"
- | "gsapAnimId"
- | "navKeyframes"
- | "animIdForProp"
- | "gsapRuntimeValues"
- | "elStart"
- | "elDuration"
- | "onCommitAnimatedProperty"
- | "onCommitAnimatedProperties"
- | "onSeekToTime"
- | "onRemoveKeyframe"
- | "onConvertToKeyframes"
- > & {
- element: DomEditSelection;
- styles: Record<string, string>;
- sections: EditingSections;
- sourceLabel: string;
- gsapBorderRadius: { tl: number; tr: number; br: number; bl: number } | null;
- showEditableSections: boolean;
- selectedElementHidden: boolean;
- selectedElementId: string | null;
- clipboardCopied: boolean;
- onCopyElementInfo: () => void;
- currentTime: number;
- }) {
+}: PropertyPanelFlatProps) {
// PropertyPanel keys this component by selection, so the default is per element.
const [openGroupId, setOpenGroupId] = useState<string>(() =>
isTextEditableSelection(element)
diff --git a/packages/studio/src/components/editor/propertyPanelFlatProps.ts b/packages/studio/src/components/editor/propertyPanelFlatProps.ts
new file mode 100644
index 0000000000..7c91a0ad98
--- /dev/null
+++ b/packages/studio/src/components/editor/propertyPanelFlatProps.ts
@@ -0,0 +1,91 @@
+import type { resolveEditingSections } from "@hyperframes/core/editing";
+import type { DomEditSelection } from "./domEditing";
+import type { PropertyPanelProps } from "./propertyPanelHelpers";
+import type { FlatLayoutSection } from "./propertyPanelFlatLayoutSection";
+
+export type PropertyPanelFlatProps = Pick<
+ PropertyPanelProps,
+ | "projectId"
+ | "projectDir"
+ | "assets"
+ | "previewIframeRef"
+ | "onClearSelection"
+ | "onUngroup"
+ | "onSetStyle"
+ | "onPreviewStyle"
+ | "onSetAttribute"
+ | "onSetAttributes"
+ | "onSetAttributeLive"
+ | "onApplyColorGradingScope"
+ | "onSetHtmlAttribute"
+ | "onRemoveBackground"
+ | "onSetText"
+ | "onSetTextFieldStyle"
+ | "onPreviewTextFieldStyle"
+ | "onAddTextField"
+ | "onRemoveTextField"
+ | "onAskAgent"
+ | "onToggleElementHidden"
+ | "onImportAssets"
+ | "onAddMediaOverlay"
+ | "onImportFonts"
+ | "fontAssets"
+ | "gsapAnimations"
+ | "gsapMultipleTimelines"
+ | "gsapUnsupportedTimelinePattern"
+ | "onUpdateGsapProperty"
+ | "onUpdateGsapMeta"
+ | "onDeleteGsapAnimation"
+ | "onAddGsapProperty"
+ | "onRemoveGsapProperty"
+ | "onUpdateGsapFromProperty"
+ | "onAddGsapFromProperty"
+ | "onRemoveGsapFromProperty"
+ | "onAddGsapAnimation"
+ | "onSetArcPath"
+ | "onUpdateArcSegment"
+ | "onUnroll"
+ | "onUpdateKeyframeEase"
+ | "onSetAllKeyframeEases"
+ | "onUpdateSegmentEase"
+ | "recordingState"
+ | "recordingDuration"
+ | "onToggleRecording"
+> &
+ Pick<
+ Parameters<typeof FlatLayoutSection>[0],
+ | "displayX"
+ | "displayY"
+ | "displayW"
+ | "displayH"
+ | "displayR"
+ | "manualOffsetEditingDisabled"
+ | "manualSizeEditingDisabled"
+ | "manualRotationEditingDisabled"
+ | "commitManualOffset"
+ | "commitManualSize"
+ | "commitManualRotation"
+ | "gsapAnimId"
+ | "navKeyframes"
+ | "animIdForProp"
+ | "gsapRuntimeValues"
+ | "elStart"
+ | "elDuration"
+ | "onCommitAnimatedProperty"
+ | "onCommitAnimatedProperties"
+ | "onSeekToTime"
+ | "onRemoveKeyframe"
+ | "onConvertToKeyframes"
+ > & {
+ element: DomEditSelection;
+ styles: Record<string, string>;
+ sections: ReturnType<typeof resolveEditingSections>;
+ sourceLabel: string;
+ gsapBorderRadius: { tl: number; tr: number; br: number; bl: number } | null;
+ showEditableSections: boolean;
+ selectedElementHidden: boolean;
+ selectedElementId: string | null;
+ clipboardCopied: boolean;
+ onCopyElementInfo: () => void;
+ currentTime: number;
+ };
diff --git a/packages/studio/src/hooks/useDomEditSession.ts b/packages/studio/src/hooks/useDomEditSession.ts
index 12b9d6261e..2b5e50d37f 100644
--- a/packages/studio/src/hooks/useDomEditSession.ts
+++ b/packages/studio/src/hooks/useDomEditSession.ts
@@ -19,7 +19,7 @@ import { useGsapCacheVersion } from "./useGsapTweenCache";
import { useDomEditWiring } from "./useDomEditWiring";
import { useGsapAwareEditing } from "./useGsapAwareEditing";
import { useStudioSelectionPublisher } from "./useStudioSelectionPublisher";
-import type { AnimationKeyframeTarget } from "./gsapTweenSynth";
+import { useKeyframeEaseCommits } from "./useKeyframeEaseCommits";
interface RecordEditInput {
label: string;
@@ -460,65 +460,8 @@ export function useDomEditSession({
setArcPath,
updateArcSegment,
});
- const handleUpdateSegmentEase = useCallback(
- (targets: AnimationKeyframeTarget[], ease: string) => {
- const selection = domEditSelectionRef.current;
- if (!selection || targets.length === 0) return;
- const options = {
- label: targets.length === 1 ? "Update keyframe ease" : "Update segment ease",
- softReload: true,
- };
- const calls = targets.map(({ animationId, tweenPercentage }) => ({
- selection,
- mutation: {
- type: "update-keyframe",
- animationId,
- percentage: tweenPercentage,
- properties: {},
- ease,
- },
- options,
- }));
- if (calls.length === 1) {
- const call = calls[0];
- if (call) void gsapCommitMutation(call.selection, call.mutation, call.options);
- return;
- }
- const batch = gsapCommitMutation.batch;
- if (batch) {
- void batch(calls, options);
- return;
- }
- // A wrapped commit (a gesture transaction, say) carries no batch
- // transport. Serial keeps the edit correct at the cost of one round trip
- // per tween and one undo entry per tween; an optional-chained call here
- // would silently drop the whole edit instead.
- for (const call of calls)
- void gsapCommitMutation(call.selection, call.mutation, call.options);
- },
- [gsapCommitMutation, domEditSelectionRef],
- );
- const handleUpdateKeyframeEase = useCallback(
- (animationId: string, percentage: number, ease: string) =>
- handleUpdateSegmentEase([{ animationId, tweenPercentage: percentage }], ease),
- [handleUpdateSegmentEase],
- );
- const handleSetAllKeyframeEases = useCallback(
- (animationId: string, ease: string) => {
- const sel = domEditSelectionRef.current;
- if (!sel) return;
- gsapCommitMutation(
- sel,
- {
- type: "update-meta",
- animationId,
- updates: { easeEach: ease, resetKeyframeEases: true },
- },
- { label: "Apply ease to all segments", softReload: true },
- );
- },
- [gsapCommitMutation, domEditSelectionRef],
- );
+ const { handleUpdateSegmentEase, handleUpdateKeyframeEase, handleSetAllKeyframeEases } =
+ useKeyframeEaseCommits({ gsapCommitMutation, domEditSelectionRef });
return {
// State
domEditSelection,
diff --git a/packages/studio/src/hooks/useKeyframeEaseCommits.ts b/packages/studio/src/hooks/useKeyframeEaseCommits.ts
new file mode 100644
index 0000000000..4434fc4696
--- /dev/null
+++ b/packages/studio/src/hooks/useKeyframeEaseCommits.ts
@@ -0,0 +1,78 @@
+import { useCallback, type RefObject } from "react";
+import type { CommitMutation } from "./gsapScriptCommitTypes";
+import type { AnimationKeyframeTarget } from "./gsapTweenSynth";
+import type { DomEditSelection } from "../components/editor/domEditing";
+
+interface KeyframeEaseCommitsInput {
+ gsapCommitMutation: CommitMutation;
+ domEditSelectionRef: RefObject<DomEditSelection | null>;
+}
+
+export function useKeyframeEaseCommits({
+ gsapCommitMutation,
+ domEditSelectionRef,
+}: KeyframeEaseCommitsInput) {
+ const handleUpdateSegmentEase = useCallback(
+ (targets: AnimationKeyframeTarget[], ease: string) => {
+ const selection = domEditSelectionRef.current;
+ if (!selection || targets.length === 0) return;
+ const options = {
+ label: targets.length === 1 ? "Update keyframe ease" : "Update segment ease",
+ softReload: true,
+ };
+ const calls = targets.map(({ animationId, tweenPercentage }) => ({
+ selection,
+ mutation: {
+ type: "update-keyframe",
+ animationId,
+ percentage: tweenPercentage,
+ properties: {},
+ ease,
+ },
+ options,
+ }));
+ if (calls.length === 1) {
+ const call = calls[0];
+ if (call) void gsapCommitMutation(call.selection, call.mutation, call.options);
+ return;
+ }
+ const batch = gsapCommitMutation.batch;
+ if (batch) {
+ void batch(calls, options);
+ return;
+ }
+ // A wrapped commit (a gesture transaction, say) carries no batch
+ // transport. Serial keeps the edit correct at the cost of one round trip
+ // per tween and one undo entry per tween; an optional-chained call here
+ // would silently drop the whole edit instead.
+ for (const call of calls)
+ void gsapCommitMutation(call.selection, call.mutation, call.options);
+ },
+ [gsapCommitMutation, domEditSelectionRef],
+ );
+
+ const handleUpdateKeyframeEase = useCallback(
+ (animationId: string, percentage: number, ease: string) =>
+ handleUpdateSegmentEase([{ animationId, tweenPercentage: percentage }], ease),
+ [handleUpdateSegmentEase],
+ );
+
+ const handleSetAllKeyframeEases = useCallback(
+ (animationId: string, ease: string) => {
+ const sel = domEditSelectionRef.current;
+ if (!sel) return;
+ gsapCommitMutation(
+ sel,
+ {
+ type: "update-meta",
+ animationId,
+ updates: { easeEach: ease, resetKeyframeEases: true },
+ },
+ { label: "Apply ease to all segments", softReload: true },
+ );
+ },
+ [gsapCommitMutation, domEditSelectionRef],
+ );
+
+ return { handleUpdateSegmentEase, handleUpdateKeyframeEase, handleSetAllKeyframeEases };
+}