@@ -11,13 +11,14 @@ import { useDomEditPreviewSync } from "./useDomEditPreviewSync";
1111import type { ImportedFontAsset } from "../components/editor/fontAssets" ;
1212import type { EditHistoryKind } from "../utils/editHistory" ;
1313import type { RightPanelTab } from "../utils/studioHelpers" ;
14- import type { PatchTarget } from "../utils/sourcePatcher" ;
14+ import type { PatchOperation , PatchTarget } from "../utils/sourcePatcher" ;
1515import type { SidebarTab } from "../components/sidebar/LeftSidebar" ;
1616import { useAskAgentModal } from "./useAskAgentModal" ;
1717import { useDomSelection } from "./useDomSelection" ;
1818import { usePreviewInteraction } from "./usePreviewInteraction" ;
1919import { useDomEditCommits } from "./useDomEditCommits" ;
2020import { reportShadowDispatch } from "../utils/sdkShadow" ;
21+ import { sdkCutoverPersist } from "../utils/sdkCutover" ;
2122import { useGsapScriptCommits } from "./useGsapScriptCommits" ;
2223import {
2324 useGsapAnimationsForElement ,
@@ -34,8 +35,6 @@ import {
3435import { useAnimatedPropertyCommit } from "./useAnimatedPropertyCommit" ;
3536import { useGsapSelectionHandlers } from "./useGsapSelectionHandlers" ;
3637
37- // ── Types ──
38-
3938interface RecordEditInput {
4039 label : string ;
4140 kind : EditHistoryKind ;
@@ -79,12 +78,9 @@ export interface UseDomEditSessionParams {
7978 openSourceForSelection ?: ( sourceFile : string , target : PatchTarget ) => void ;
8079 selectSidebarTab ?: ( tab : SidebarTab ) => void ;
8180 getSidebarTab ?: ( ) => SidebarTab ;
82- /** Stage 7 Step 3b: SDK session for shadow dispatch parity tracking. */
8381 sdkSession ?: Composition | null ;
8482}
8583
86- // ── Hook ──
87-
8884// fallow-ignore-next-line complexity
8985export function useDomEditSession ( {
9086 projectId,
@@ -138,8 +134,6 @@ export function useDomEditSession({
138134 [ openSourceForSelection , selectSidebarTab ] ,
139135 ) ;
140136
141- // ── Selection (delegated to useDomSelection) ──
142-
143137 const {
144138 domEditSelection,
145139 domEditGroupSelections,
@@ -170,8 +164,6 @@ export function useDomEditSession({
170164 rightPanelTab,
171165 } ) ;
172166
173- // ── Agent modal (delegated to useAskAgentModal) ──
174-
175167 const {
176168 agentModalOpen,
177169 agentModalAnchorPoint,
@@ -192,8 +184,6 @@ export function useDomEditSession({
192184 domEditSelection,
193185 } ) ;
194186
195- // ── Preview interaction (delegated to usePreviewInteraction) ──
196-
197187 const {
198188 handlePreviewCanvasMouseDown,
199189 handlePreviewCanvasPointerMove,
@@ -212,8 +202,7 @@ export function useDomEditSession({
212202 onClickToSource,
213203 } ) ;
214204
215- // Sync DOM selection → timeline selectedElementId so that clip selection
216- // highlights and diamond playhead fills work on cold-load URL restore.
205+ // Sync DOM selection → timeline selectedElementId for cold-load URL restore.
217206 useEffect ( ( ) => {
218207 if ( ! domEditSelection ?. id ) return ;
219208 const { selectedElementId, elements, setSelectedElementId } = usePlayerStore . getState ( ) ;
@@ -224,13 +213,9 @@ export function useDomEditSession({
224213 if ( key && key !== selectedElementId ) setSelectedElementId ( key ) ;
225214 } , [ domEditSelection ?. id ] ) ;
226215
227- // ── GSAP script editing ──
228-
229216 const { version : gsapCacheVersion , bump : bumpGsapCache } = useGsapCacheVersion ( ) ;
230217
231- // Bump GSAP cache when refreshKey changes (code-tab edits trigger iframe
232- // reload via refreshKey but don't go through commitMutation, so the cache
233- // would otherwise retain stale keyframe entries).
218+ // Bump GSAP cache on refreshKey — code-tab edits bypass commitMutation.
234219 const prevRefreshKeyRef = useRef ( refreshKey ) ;
235220 // eslint-disable-next-line no-restricted-syntax
236221 useEffect ( ( ) => {
@@ -292,7 +277,16 @@ export function useDomEditSession({
292277 onFileContentChanged : updateEditingFileContent ,
293278 } ) ;
294279
295- // ── Commit handlers (delegated to useDomEditCommits) ──
280+ const onTrySdkPersist = useCallback (
281+ ( sel : DomEditSelection , ops : PatchOperation [ ] , html : string , path : string ) =>
282+ sdkCutoverPersist ( sel , ops , html , path , sdkSession , {
283+ editHistory,
284+ writeProjectFile,
285+ reloadPreview,
286+ domEditSaveTimestampRef,
287+ } ) ,
288+ [ sdkSession , editHistory , writeProjectFile , reloadPreview , domEditSaveTimestampRef ] ,
289+ ) ;
296290
297291 const {
298292 resolveImportedFontAsset,
@@ -333,6 +327,7 @@ export function useDomEditSession({
333327 onDomEditPersisted : sdkSession
334328 ? ( sel , ops ) => reportShadowDispatch ( sdkSession , sel , ops )
335329 : undefined ,
330+ onTrySdkPersist,
336331 } ) ;
337332
338333 // GSAP-aware: intercept offset/resize/rotation to commit via script mutation when animated.
0 commit comments