({
activeCompPath,
previewIframeRef,
showToast,
queueDomEditSave,
writeProjectFile,
domEditSaveTimestampRef,
editHistory,
fileTree,
importedFontAssetsRef,
projectId,
projectIdRef,
reloadPreview,
domEditSelection,
applyDomSelection,
clearDomSelection,
refreshDomEditSelectionFromPreview,
buildDomSelectionFromTarget,
forceReloadSdkSession,
onTrySdkPersist,
onTrySdkDelete,
onReorderShadow,
}: UseDomEditCommitsParams)
| 87 | } |
| 88 | |
| 89 | export 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 |
no test coverage detected