MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / useDomEditCommits

Function useDomEditCommits

packages/studio/src/hooks/useDomEditCommits.ts:89–348  ·  view source on GitHub ↗
({
  activeCompPath,
  previewIframeRef,
  showToast,
  queueDomEditSave,
  writeProjectFile,
  domEditSaveTimestampRef,
  editHistory,
  fileTree,
  importedFontAssetsRef,
  projectId,
  projectIdRef,
  reloadPreview,
  domEditSelection,
  applyDomSelection,
  clearDomSelection,
  refreshDomEditSelectionFromPreview,
  buildDomSelectionFromTarget,
  forceReloadSdkSession,
  onTrySdkPersist,
  onTrySdkDelete,
  onReorderShadow,
}: UseDomEditCommitsParams)

Source from the content-addressed store, hash-verified

87}
88
89export function useDomEditCommits({
90 activeCompPath,
91 previewIframeRef,
92 showToast,
93 queueDomEditSave,
94 writeProjectFile,
95 domEditSaveTimestampRef,
96 editHistory,
97 fileTree,
98 importedFontAssetsRef,
99 projectId,
100 projectIdRef,
101 reloadPreview,
102 domEditSelection,
103 applyDomSelection,
104 clearDomSelection,
105 refreshDomEditSelectionFromPreview,
106 buildDomSelectionFromTarget,
107 forceReloadSdkSession,
108 onTrySdkPersist,
109 onTrySdkDelete,
110 onReorderShadow,
111}: UseDomEditCommitsParams) {
112 const resolveImportedFontAsset = useCallback(
113 (fontFamilyValue: string): ImportedFontAsset | null => {
114 const family = primaryFontFamilyValue(fontFamilyValue);
115 if (!family) return null;
116 const imported = importedFontAssetsRef.current.find(
117 (font) => font.family.toLowerCase() === family.toLowerCase(),
118 );
119 if (imported) return imported;
120 const asset = fileTree.find(
121 (path) =>
122 FONT_EXT.test(path) &&
123 fontFamilyFromAssetPath(path).toLowerCase() === family.toLowerCase(),
124 );
125 if (!asset) return null;
126 return {
127 family: fontFamilyFromAssetPath(asset),
128 path: asset,
129 url: `/api/projects/${projectId}/preview/${asset}`,
130 };
131 },
132 [fileTree, projectId, importedFontAssetsRef],
133 );
134
135 const reportedUnresolvableRef = useRef(new Set<string>());
136
137 // fallow-ignore-next-line complexity
138 const persistDomEditOperations: PersistDomEditOperations = useCallback(
139 // fallow-ignore-next-line complexity
140 async (selection, operations, options) => {
141 const pid = projectIdRef.current;
142 if (!pid) throw new Error("No active project");
143 if (options?.shouldSave && !options.shouldSave()) return;
144
145 const targetPath = selection.sourceFile || activeCompPath || "index.html";
146

Callers 1

useDomEditSessionFunction · 0.90

Calls 15

primaryFontFamilyValueFunction · 0.90
fontFamilyFromAssetPathFunction · 0.90
buildDomEditPatchTargetFunction · 0.90
trackStudioEventFunction · 0.90
useDomEditTextCommitsFunction · 0.90
useDomGeometryCommitsFunction · 0.90
useElementLifecycleOpsFunction · 0.90
fetchFunction · 0.85
findUnsafeDomPatchValuesFunction · 0.85
formatUnsafeFieldListFunction · 0.85

Tested by

no test coverage detected