mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 15:15:35 +00:00
refactor(studio): split bulk easing helpers
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
Reference in New Issue
Block a user