@pierre/diffs 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (477) hide show
  1. package/dist/components/CodeView.d.ts +4 -4
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +8 -6
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +3 -15
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/FileDiff.d.ts +9 -37
  8. package/dist/components/FileDiff.d.ts.map +1 -1
  9. package/dist/components/FileDiff.js +15 -12
  10. package/dist/components/FileDiff.js.map +1 -1
  11. package/dist/components/FileStream.d.ts +1 -0
  12. package/dist/components/FileStream.d.ts.map +1 -1
  13. package/dist/components/UnresolvedFile.d.ts +1 -1
  14. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  15. package/dist/components/UnresolvedFile.js +2 -1
  16. package/dist/components/UnresolvedFile.js.map +1 -1
  17. package/dist/components/VirtualizedFile.d.ts +2 -8
  18. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  19. package/dist/components/VirtualizedFile.js +11 -9
  20. package/dist/components/VirtualizedFile.js.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.d.ts +2 -8
  22. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  23. package/dist/components/VirtualizedFileDiff.js +11 -9
  24. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  25. package/dist/components/Virtualizer.d.ts +1 -5
  26. package/dist/components/Virtualizer.d.ts.map +1 -1
  27. package/dist/components/Virtualizer.js.map +1 -1
  28. package/dist/components/VirtulizerDevelopment.d.ts +0 -1
  29. package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
  30. package/dist/components/web-components.d.ts.map +1 -1
  31. package/dist/components/web-components.js +2 -1
  32. package/dist/components/web-components.js.map +1 -1
  33. package/dist/constants.d.ts +0 -1
  34. package/dist/constants.d.ts.map +1 -1
  35. package/dist/editor/EditStateManager.d.ts +0 -1
  36. package/dist/editor/EditStateManager.d.ts.map +1 -1
  37. package/dist/editor/EditStateManager.js.map +1 -1
  38. package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts +0 -1
  39. package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts.map +1 -1
  40. package/dist/editor/command.d.ts +2 -1
  41. package/dist/editor/command.d.ts.map +1 -1
  42. package/dist/editor/editPrediction.d.ts +3 -2
  43. package/dist/editor/editPrediction.d.ts.map +1 -1
  44. package/dist/editor/editPrediction.js +11 -11
  45. package/dist/editor/editPrediction.js.map +1 -1
  46. package/dist/editor/editStack.d.ts +0 -1
  47. package/dist/editor/editStack.d.ts.map +1 -1
  48. package/dist/editor/editStack.js.map +1 -1
  49. package/dist/editor/editor.d.ts +1 -5
  50. package/dist/editor/editor.d.ts.map +1 -1
  51. package/dist/editor/editor.js +24 -19
  52. package/dist/editor/editor.js.map +1 -1
  53. package/dist/editor/editor2.js.map +1 -1
  54. package/dist/editor/languages.d.ts +0 -1
  55. package/dist/editor/languages.d.ts.map +1 -1
  56. package/dist/editor/languages.js +1 -1
  57. package/dist/editor/languages.js.map +1 -1
  58. package/dist/editor/lineAnnotations.d.ts +0 -1
  59. package/dist/editor/lineAnnotations.d.ts.map +1 -1
  60. package/dist/editor/lineAnnotations.js +2 -1
  61. package/dist/editor/lineAnnotations.js.map +1 -1
  62. package/dist/editor/marker.d.ts +0 -1
  63. package/dist/editor/marker.d.ts.map +1 -1
  64. package/dist/editor/marker.js +5 -3
  65. package/dist/editor/marker.js.map +1 -1
  66. package/dist/editor/matchBrackets.d.ts +0 -1
  67. package/dist/editor/matchBrackets.d.ts.map +1 -1
  68. package/dist/editor/pieceTable.d.ts +0 -1
  69. package/dist/editor/pieceTable.d.ts.map +1 -1
  70. package/dist/editor/pieceTable.js.map +1 -1
  71. package/dist/editor/platform.d.ts +1 -5
  72. package/dist/editor/platform.d.ts.map +1 -1
  73. package/dist/editor/platform.js.map +1 -1
  74. package/dist/editor/popover.d.ts +12 -12
  75. package/dist/editor/popover.d.ts.map +1 -1
  76. package/dist/editor/popover.js.map +1 -1
  77. package/dist/editor/searchPanel.d.ts +0 -1
  78. package/dist/editor/searchPanel.d.ts.map +1 -1
  79. package/dist/editor/searchPanel.js +16 -12
  80. package/dist/editor/searchPanel.js.map +1 -1
  81. package/dist/editor/selection.d.ts +0 -1
  82. package/dist/editor/selection.d.ts.map +1 -1
  83. package/dist/editor/selection.js.map +1 -1
  84. package/dist/editor/selectionAction.d.ts +0 -1
  85. package/dist/editor/selectionAction.d.ts.map +1 -1
  86. package/dist/editor/selectionAction.js.map +1 -1
  87. package/dist/editor/sprite.d.ts.map +1 -1
  88. package/dist/editor/textDocument.d.ts +0 -1
  89. package/dist/editor/textDocument.d.ts.map +1 -1
  90. package/dist/editor/textDocument.js.map +1 -1
  91. package/dist/editor/textDocumentChangeTransaction.d.ts +0 -1
  92. package/dist/editor/textDocumentChangeTransaction.d.ts.map +1 -1
  93. package/dist/editor/textMeasure.d.ts.map +1 -1
  94. package/dist/editor/textMeasure.js.map +1 -1
  95. package/dist/editor/tokenizer.d.ts +1 -11
  96. package/dist/editor/tokenizer.d.ts.map +1 -1
  97. package/dist/editor/tokenizer.js +8 -4
  98. package/dist/editor/tokenizer.js.map +1 -1
  99. package/dist/editor/types.d.ts +0 -1
  100. package/dist/editor/types.d.ts.map +1 -1
  101. package/dist/editor/utils.d.ts.map +1 -1
  102. package/dist/editor/utils.js +11 -7
  103. package/dist/editor/utils.js.map +1 -1
  104. package/dist/highlighter/languages/areLanguagesAttached.d.ts +0 -1
  105. package/dist/highlighter/languages/areLanguagesAttached.d.ts.map +1 -1
  106. package/dist/highlighter/languages/attachResolvedLanguages.d.ts +1 -0
  107. package/dist/highlighter/languages/attachResolvedLanguages.d.ts.map +1 -1
  108. package/dist/highlighter/languages/cleanUpResolvedLanguages.d.ts.map +1 -1
  109. package/dist/highlighter/languages/constants.d.ts +1 -1
  110. package/dist/highlighter/languages/constants.d.ts.map +1 -1
  111. package/dist/highlighter/languages/getResolvedLanguages.d.ts +1 -0
  112. package/dist/highlighter/languages/getResolvedLanguages.d.ts.map +1 -1
  113. package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts +1 -0
  114. package/dist/highlighter/languages/getResolvedOrResolveLanguage.d.ts.map +1 -1
  115. package/dist/highlighter/languages/hasResolvedLanguages.d.ts +0 -1
  116. package/dist/highlighter/languages/hasResolvedLanguages.d.ts.map +1 -1
  117. package/dist/highlighter/languages/registerCustomLanguage.d.ts +0 -1
  118. package/dist/highlighter/languages/registerCustomLanguage.d.ts.map +1 -1
  119. package/dist/highlighter/languages/resolveLanguage.d.ts +1 -0
  120. package/dist/highlighter/languages/resolveLanguage.d.ts.map +1 -1
  121. package/dist/highlighter/languages/resolveLanguages.d.ts +1 -0
  122. package/dist/highlighter/languages/resolveLanguages.d.ts.map +1 -1
  123. package/dist/highlighter/shared_highlighter.d.ts +1 -6
  124. package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
  125. package/dist/highlighter/themes/areThemesAttached.d.ts +0 -1
  126. package/dist/highlighter/themes/areThemesAttached.d.ts.map +1 -1
  127. package/dist/highlighter/themes/attachResolvedThemes.d.ts +0 -1
  128. package/dist/highlighter/themes/attachResolvedThemes.d.ts.map +1 -1
  129. package/dist/highlighter/themes/cleanUpResolvedThemes.d.ts.map +1 -1
  130. package/dist/highlighter/themes/constants.d.ts.map +1 -1
  131. package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts +0 -1
  132. package/dist/highlighter/themes/getResolvedOrResolveTheme.d.ts.map +1 -1
  133. package/dist/highlighter/themes/getResolvedThemes.d.ts +0 -1
  134. package/dist/highlighter/themes/getResolvedThemes.d.ts.map +1 -1
  135. package/dist/highlighter/themes/hasResolvedThemes.d.ts +0 -1
  136. package/dist/highlighter/themes/hasResolvedThemes.d.ts.map +1 -1
  137. package/dist/highlighter/themes/registerCustomCSSVariableTheme.d.ts.map +1 -1
  138. package/dist/highlighter/themes/registerCustomTheme.d.ts +0 -1
  139. package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
  140. package/dist/highlighter/themes/resolveTheme.d.ts +0 -1
  141. package/dist/highlighter/themes/resolveTheme.d.ts.map +1 -1
  142. package/dist/highlighter/themes/resolveThemes.d.ts +0 -1
  143. package/dist/highlighter/themes/resolveThemes.d.ts.map +1 -1
  144. package/dist/highlighter/themes/themeResolution.d.ts +0 -1
  145. package/dist/highlighter/themes/themeResolution.d.ts.map +1 -1
  146. package/dist/highlighter/themes/themeResolver.d.ts +0 -1
  147. package/dist/highlighter/themes/themeResolver.d.ts.map +1 -1
  148. package/dist/index.d.ts +1 -0
  149. package/dist/managers/InteractionManager.d.ts +2 -26
  150. package/dist/managers/InteractionManager.d.ts.map +1 -1
  151. package/dist/managers/InteractionManager.js +1 -3
  152. package/dist/managers/InteractionManager.js.map +1 -1
  153. package/dist/managers/ResizeManager.d.ts +1 -4
  154. package/dist/managers/ResizeManager.d.ts.map +1 -1
  155. package/dist/managers/ScrollSyncManager.d.ts.map +1 -1
  156. package/dist/managers/UniversalRenderingManager.d.ts.map +1 -1
  157. package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts +0 -1
  158. package/dist/node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.d.ts.map +1 -1
  159. package/dist/node_modules/.pnpm/@types_unist@3.0.3/node_modules/@types/unist/index.d.ts.map +1 -1
  160. package/dist/react/CodeView.d.ts +9 -1
  161. package/dist/react/CodeView.d.ts.map +1 -1
  162. package/dist/react/CodeView.js +39 -33
  163. package/dist/react/CodeView.js.map +1 -1
  164. package/dist/react/EditContext.d.ts +2 -5
  165. package/dist/react/EditContext.d.ts.map +1 -1
  166. package/dist/react/File.d.ts +1 -23
  167. package/dist/react/File.d.ts.map +1 -1
  168. package/dist/react/File.js +13 -12
  169. package/dist/react/File.js.map +1 -1
  170. package/dist/react/FileDiff.d.ts +1 -23
  171. package/dist/react/FileDiff.d.ts.map +1 -1
  172. package/dist/react/FileDiff.js +13 -12
  173. package/dist/react/FileDiff.js.map +1 -1
  174. package/dist/react/MultiFileDiff.d.ts +1 -24
  175. package/dist/react/MultiFileDiff.d.ts.map +1 -1
  176. package/dist/react/MultiFileDiff.js +13 -12
  177. package/dist/react/MultiFileDiff.js.map +1 -1
  178. package/dist/react/PatchDiff.d.ts +1 -23
  179. package/dist/react/PatchDiff.d.ts.map +1 -1
  180. package/dist/react/PatchDiff.js +13 -12
  181. package/dist/react/PatchDiff.js.map +1 -1
  182. package/dist/react/UnresolvedFile.d.ts +1 -18
  183. package/dist/react/UnresolvedFile.d.ts.map +1 -1
  184. package/dist/react/UnresolvedFile.js +15 -14
  185. package/dist/react/UnresolvedFile.js.map +1 -1
  186. package/dist/react/Virtualizer.d.ts +1 -9
  187. package/dist/react/Virtualizer.d.ts.map +1 -1
  188. package/dist/react/Virtualizer.js.map +1 -1
  189. package/dist/react/WorkerPoolContext.d.ts +2 -6
  190. package/dist/react/WorkerPoolContext.d.ts.map +1 -1
  191. package/dist/react/constants.d.ts +0 -1
  192. package/dist/react/constants.d.ts.map +1 -1
  193. package/dist/react/jsx.d.ts +1 -0
  194. package/dist/react/jsx.d.ts.map +1 -1
  195. package/dist/react/types.d.ts +1 -1
  196. package/dist/react/types.d.ts.map +1 -1
  197. package/dist/react/utils/assignRef.d.ts +6 -0
  198. package/dist/react/utils/assignRef.d.ts.map +1 -0
  199. package/dist/react/utils/assignRef.js +9 -0
  200. package/dist/react/utils/assignRef.js.map +1 -0
  201. package/dist/react/utils/renderDiffChildren.d.ts +1 -16
  202. package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
  203. package/dist/react/utils/renderDiffChildren.js.map +1 -1
  204. package/dist/react/utils/renderFileChildren.d.ts +1 -13
  205. package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
  206. package/dist/react/utils/renderFileChildren.js.map +1 -1
  207. package/dist/react/utils/templateRender.d.ts +0 -1
  208. package/dist/react/utils/templateRender.d.ts.map +1 -1
  209. package/dist/react/utils/useFileDiffInstance.d.ts +2 -18
  210. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  211. package/dist/react/utils/useFileDiffInstance.js +31 -17
  212. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  213. package/dist/react/utils/useFileInstance.d.ts +2 -16
  214. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  215. package/dist/react/utils/useFileInstance.js +8 -4
  216. package/dist/react/utils/useFileInstance.js.map +1 -1
  217. package/dist/react/utils/useStableCallback.d.ts.map +1 -1
  218. package/dist/react/utils/useUnresolvedFileInstance.d.ts +1 -12
  219. package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
  220. package/dist/renderers/DiffHunksRenderer.d.ts +4 -9
  221. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  222. package/dist/renderers/DiffHunksRenderer.js +28 -21
  223. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  224. package/dist/renderers/FileRenderer.d.ts +1 -0
  225. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  226. package/dist/renderers/FileRenderer.js.map +1 -1
  227. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +3 -9
  228. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
  229. package/dist/shiki-stream/stream.d.ts +0 -1
  230. package/dist/shiki-stream/stream.d.ts.map +1 -1
  231. package/dist/shiki-stream/stream.js.map +1 -1
  232. package/dist/shiki-stream/tokenizer.d.ts +0 -1
  233. package/dist/shiki-stream/tokenizer.d.ts.map +1 -1
  234. package/dist/shiki-stream/types.d.ts +0 -1
  235. package/dist/shiki-stream/types.d.ts.map +1 -1
  236. package/dist/sprite.d.ts.map +1 -1
  237. package/dist/ssr/FileDiffReact.d.ts +1 -8
  238. package/dist/ssr/FileDiffReact.d.ts.map +1 -1
  239. package/dist/ssr/FileDiffReact.js +8 -3
  240. package/dist/ssr/FileDiffReact.js.map +1 -1
  241. package/dist/ssr/preloadDiffs.d.ts +6 -34
  242. package/dist/ssr/preloadDiffs.d.ts.map +1 -1
  243. package/dist/ssr/preloadFile.d.ts +1 -6
  244. package/dist/ssr/preloadFile.d.ts.map +1 -1
  245. package/dist/ssr/preloadPatchFile.d.ts +1 -5
  246. package/dist/ssr/preloadPatchFile.d.ts.map +1 -1
  247. package/dist/ssr/renderHTML.d.ts +0 -1
  248. package/dist/ssr/renderHTML.d.ts.map +1 -1
  249. package/dist/string-import.d.ts.map +1 -1
  250. package/dist/style.js.map +1 -1
  251. package/dist/types.d.ts +0 -1
  252. package/dist/types.d.ts.map +1 -1
  253. package/dist/utils/annotationHelpers.d.ts +0 -1
  254. package/dist/utils/annotationHelpers.d.ts.map +1 -1
  255. package/dist/utils/appendItems.d.ts.map +1 -1
  256. package/dist/utils/applyLineTextWithNewline.d.ts.map +1 -1
  257. package/dist/utils/areDiffLineAnnotationsEqual.d.ts +0 -1
  258. package/dist/utils/areDiffLineAnnotationsEqual.d.ts.map +1 -1
  259. package/dist/utils/areDiffRenderOptionsEqual.d.ts +0 -1
  260. package/dist/utils/areDiffRenderOptionsEqual.d.ts.map +1 -1
  261. package/dist/utils/areDiffTargetsEqual.d.ts +0 -1
  262. package/dist/utils/areDiffTargetsEqual.d.ts.map +1 -1
  263. package/dist/utils/areFileRenderOptionsEqual.d.ts +0 -1
  264. package/dist/utils/areFileRenderOptionsEqual.d.ts.map +1 -1
  265. package/dist/utils/areFileTargetsEqual.d.ts +0 -1
  266. package/dist/utils/areFileTargetsEqual.d.ts.map +1 -1
  267. package/dist/utils/areFilesEqual.d.ts +0 -1
  268. package/dist/utils/areFilesEqual.d.ts.map +1 -1
  269. package/dist/utils/areHunkDataEqual.d.ts +0 -1
  270. package/dist/utils/areHunkDataEqual.d.ts.map +1 -1
  271. package/dist/utils/areLineAnnotationsEqual.d.ts +0 -1
  272. package/dist/utils/areLineAnnotationsEqual.d.ts.map +1 -1
  273. package/dist/utils/areManagedSnapshotsEqual.d.ts +0 -1
  274. package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
  275. package/dist/utils/areMergeConflictActionsEqual.d.ts +0 -1
  276. package/dist/utils/areMergeConflictActionsEqual.d.ts.map +1 -1
  277. package/dist/utils/areObjectsEqual.d.ts.map +1 -1
  278. package/dist/utils/areOptionsEqual.d.ts +1 -0
  279. package/dist/utils/areOptionsEqual.d.ts.map +1 -1
  280. package/dist/utils/arePrePropertiesEqual.d.ts +0 -1
  281. package/dist/utils/arePrePropertiesEqual.d.ts.map +1 -1
  282. package/dist/utils/areRenderRangesEqual.d.ts +0 -1
  283. package/dist/utils/areRenderRangesEqual.d.ts.map +1 -1
  284. package/dist/utils/areSelectionPointsEqual.d.ts +0 -1
  285. package/dist/utils/areSelectionPointsEqual.d.ts.map +1 -1
  286. package/dist/utils/areSelectionsEqual.d.ts +0 -1
  287. package/dist/utils/areSelectionsEqual.d.ts.map +1 -1
  288. package/dist/utils/areThemesEqual.d.ts +0 -1
  289. package/dist/utils/areThemesEqual.d.ts.map +1 -1
  290. package/dist/utils/areVirtualWindowSpecsEqual.d.ts +0 -1
  291. package/dist/utils/areVirtualWindowSpecsEqual.d.ts.map +1 -1
  292. package/dist/utils/areWorkerStatsEqual.d.ts +1 -0
  293. package/dist/utils/areWorkerStatsEqual.d.ts.map +1 -1
  294. package/dist/utils/awaitWithTimeout.d.ts.map +1 -1
  295. package/dist/utils/cleanLastNewline.d.ts.map +1 -1
  296. package/dist/utils/cloneFileDiffMetadata.d.ts +0 -1
  297. package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -1
  298. package/dist/utils/composeCacheKey.d.ts.map +1 -1
  299. package/dist/utils/computeEstimatedDiffHeights.d.ts +1 -11
  300. package/dist/utils/computeEstimatedDiffHeights.d.ts.map +1 -1
  301. package/dist/utils/computeFileOffsets.d.ts.map +1 -1
  302. package/dist/utils/computeFileOffsets.js +9 -8
  303. package/dist/utils/computeFileOffsets.js.map +1 -1
  304. package/dist/utils/computeVirtualFileMetrics.d.ts +0 -1
  305. package/dist/utils/computeVirtualFileMetrics.d.ts.map +1 -1
  306. package/dist/utils/createAnnotationElement.d.ts +0 -1
  307. package/dist/utils/createAnnotationElement.d.ts.map +1 -1
  308. package/dist/utils/createAnnotationWrapperNode.d.ts.map +1 -1
  309. package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts.map +1 -1
  310. package/dist/utils/createContentColumn.d.ts +0 -1
  311. package/dist/utils/createContentColumn.d.ts.map +1 -1
  312. package/dist/utils/createEmptyRowBuffer.d.ts +0 -1
  313. package/dist/utils/createEmptyRowBuffer.d.ts.map +1 -1
  314. package/dist/utils/createFileHeaderElement.d.ts +1 -6
  315. package/dist/utils/createFileHeaderElement.d.ts.map +1 -1
  316. package/dist/utils/createGutterUtilityContentNode.d.ts.map +1 -1
  317. package/dist/utils/createGutterUtilityElement.d.ts +0 -1
  318. package/dist/utils/createGutterUtilityElement.d.ts.map +1 -1
  319. package/dist/utils/createNoNewlineElement.d.ts +0 -1
  320. package/dist/utils/createNoNewlineElement.d.ts.map +1 -1
  321. package/dist/utils/createPreElement.d.ts +1 -11
  322. package/dist/utils/createPreElement.d.ts.map +1 -1
  323. package/dist/utils/createRowNodes.d.ts.map +1 -1
  324. package/dist/utils/createSeparator.d.ts +1 -10
  325. package/dist/utils/createSeparator.d.ts.map +1 -1
  326. package/dist/utils/createSeparator.js +12 -10
  327. package/dist/utils/createSeparator.js.map +1 -1
  328. package/dist/utils/createSpanNodeFromToken.d.ts +0 -1
  329. package/dist/utils/createSpanNodeFromToken.d.ts.map +1 -1
  330. package/dist/utils/createSpanNodeFromToken.js +2 -1
  331. package/dist/utils/createSpanNodeFromToken.js.map +1 -1
  332. package/dist/utils/createStyleElement.d.ts +0 -1
  333. package/dist/utils/createStyleElement.d.ts.map +1 -1
  334. package/dist/utils/createTransformerWithState.d.ts +0 -1
  335. package/dist/utils/createTransformerWithState.d.ts.map +1 -1
  336. package/dist/utils/createUnsafeCSSStyleNode.d.ts.map +1 -1
  337. package/dist/utils/createWindowFromScrollPosition.d.ts +1 -9
  338. package/dist/utils/createWindowFromScrollPosition.d.ts.map +1 -1
  339. package/dist/utils/cssWrappers.d.ts +0 -1
  340. package/dist/utils/cssWrappers.d.ts.map +1 -1
  341. package/dist/utils/cssWrappers.js +5 -3
  342. package/dist/utils/cssWrappers.js.map +1 -1
  343. package/dist/utils/detachString.d.ts.map +1 -1
  344. package/dist/utils/diffAcceptRejectHunk.d.ts +0 -1
  345. package/dist/utils/diffAcceptRejectHunk.d.ts.map +1 -1
  346. package/dist/utils/editSessionAnnotations.d.ts +0 -1
  347. package/dist/utils/editSessionAnnotations.d.ts.map +1 -1
  348. package/dist/utils/editSessionHunks.d.ts +0 -1
  349. package/dist/utils/editSessionHunks.d.ts.map +1 -1
  350. package/dist/utils/formatCSSVariablePrefix.d.ts.map +1 -1
  351. package/dist/utils/getDiffFileInput.d.ts +1 -5
  352. package/dist/utils/getDiffFileInput.d.ts.map +1 -1
  353. package/dist/utils/getDiffHunksRendererOptions.d.ts +0 -1
  354. package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
  355. package/dist/utils/getFileRendererOptions.d.ts +0 -1
  356. package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
  357. package/dist/utils/getFiletypeFromFileName.d.ts +0 -1
  358. package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
  359. package/dist/utils/getFiletypeFromFileName.js.map +1 -1
  360. package/dist/utils/getHighlighterOptions.d.ts +1 -5
  361. package/dist/utils/getHighlighterOptions.d.ts.map +1 -1
  362. package/dist/utils/getHighlighterOptions.js +1 -1
  363. package/dist/utils/getHighlighterOptions.js.map +1 -1
  364. package/dist/utils/getHighlighterThemeStyles.d.ts +1 -6
  365. package/dist/utils/getHighlighterThemeStyles.d.ts.map +1 -1
  366. package/dist/utils/getHunkSeparatorSlotName.d.ts +0 -1
  367. package/dist/utils/getHunkSeparatorSlotName.d.ts.map +1 -1
  368. package/dist/utils/getHunkSideBoundaries.d.ts.map +1 -1
  369. package/dist/utils/getIconForType.d.ts +0 -1
  370. package/dist/utils/getIconForType.d.ts.map +1 -1
  371. package/dist/utils/getLineAnnotationName.d.ts +0 -1
  372. package/dist/utils/getLineAnnotationName.d.ts.map +1 -1
  373. package/dist/utils/getLineEndingType.d.ts.map +1 -1
  374. package/dist/utils/getLineNodes.d.ts +0 -1
  375. package/dist/utils/getLineNodes.d.ts.map +1 -1
  376. package/dist/utils/getMergeConflictActionSlotName.d.ts +1 -5
  377. package/dist/utils/getMergeConflictActionSlotName.d.ts.map +1 -1
  378. package/dist/utils/getMergeConflictLineTypes.d.ts +0 -1
  379. package/dist/utils/getMergeConflictLineTypes.d.ts.map +1 -1
  380. package/dist/utils/getOrCreateCodeNode.d.ts +1 -7
  381. package/dist/utils/getOrCreateCodeNode.d.ts.map +1 -1
  382. package/dist/utils/getSingularPatch.d.ts +0 -1
  383. package/dist/utils/getSingularPatch.d.ts.map +1 -1
  384. package/dist/utils/getThemes.d.ts +0 -1
  385. package/dist/utils/getThemes.d.ts.map +1 -1
  386. package/dist/utils/getTotalLineCountFromHunks.d.ts +0 -1
  387. package/dist/utils/getTotalLineCountFromHunks.d.ts.map +1 -1
  388. package/dist/utils/guardWebKitScrollDuringRebuild.d.ts.map +1 -1
  389. package/dist/utils/hast_utils.d.ts +2 -12
  390. package/dist/utils/hast_utils.d.ts.map +1 -1
  391. package/dist/utils/hostTheme.d.ts +1 -5
  392. package/dist/utils/hostTheme.d.ts.map +1 -1
  393. package/dist/utils/hydratePartialDiff.d.ts +0 -1
  394. package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
  395. package/dist/utils/includesFileAnnotations.d.ts +0 -1
  396. package/dist/utils/includesFileAnnotations.d.ts.map +1 -1
  397. package/dist/utils/isDefaultRenderRange.d.ts +0 -1
  398. package/dist/utils/isDefaultRenderRange.d.ts.map +1 -1
  399. package/dist/utils/isDiffPlainText.d.ts +0 -1
  400. package/dist/utils/isDiffPlainText.d.ts.map +1 -1
  401. package/dist/utils/isFilePlainText.d.ts +0 -1
  402. package/dist/utils/isFilePlainText.d.ts.map +1 -1
  403. package/dist/utils/isGutterUtilityPath.d.ts.map +1 -1
  404. package/dist/utils/isStyleNode.d.ts.map +1 -1
  405. package/dist/utils/isWorkerContext.d.ts.map +1 -1
  406. package/dist/utils/iterateOverDiff.d.ts +1 -10
  407. package/dist/utils/iterateOverDiff.d.ts.map +1 -1
  408. package/dist/utils/iterateOverDiff.js +5 -3
  409. package/dist/utils/iterateOverDiff.js.map +1 -1
  410. package/dist/utils/lineAnnotationIdentity.d.ts +0 -1
  411. package/dist/utils/lineAnnotationIdentity.d.ts.map +1 -1
  412. package/dist/utils/normalizeDiffResolution.d.ts +0 -1
  413. package/dist/utils/normalizeDiffResolution.d.ts.map +1 -1
  414. package/dist/utils/parseDiffDecorations.d.ts +2 -13
  415. package/dist/utils/parseDiffDecorations.d.ts.map +1 -1
  416. package/dist/utils/parseDiffFromFile.d.ts +0 -1
  417. package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
  418. package/dist/utils/parseDiffFromFile.js +2 -1
  419. package/dist/utils/parseDiffFromFile.js.map +1 -1
  420. package/dist/utils/parseLineType.d.ts +0 -1
  421. package/dist/utils/parseLineType.d.ts.map +1 -1
  422. package/dist/utils/parseMergeConflictDiffFromFile.d.ts +0 -1
  423. package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
  424. package/dist/utils/parsePatchFiles.d.ts +0 -1
  425. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  426. package/dist/utils/parsePatchFiles.js +8 -5
  427. package/dist/utils/parsePatchFiles.js.map +1 -1
  428. package/dist/utils/platform.d.ts.map +1 -1
  429. package/dist/utils/prefersReducedMotion.d.ts.map +1 -1
  430. package/dist/utils/prerenderHTMLIfNecessary.d.ts.map +1 -1
  431. package/dist/utils/processLine.d.ts +0 -1
  432. package/dist/utils/processLine.d.ts.map +1 -1
  433. package/dist/utils/realignChangeContent.d.ts +0 -1
  434. package/dist/utils/realignChangeContent.d.ts.map +1 -1
  435. package/dist/utils/renderDiffWithHighlighter.d.ts +1 -8
  436. package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
  437. package/dist/utils/renderFileWithHighlighter.d.ts +1 -11
  438. package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
  439. package/dist/utils/resolveConflict.d.ts +0 -1
  440. package/dist/utils/resolveConflict.d.ts.map +1 -1
  441. package/dist/utils/resolveRegion.d.ts +0 -1
  442. package/dist/utils/resolveRegion.d.ts.map +1 -1
  443. package/dist/utils/roundToDevicePixel.d.ts.map +1 -1
  444. package/dist/utils/scrollbarGutter.d.ts.map +1 -1
  445. package/dist/utils/scrollbarGutter.js +2 -1
  446. package/dist/utils/scrollbarGutter.js.map +1 -1
  447. package/dist/utils/setLanguageOverride.d.ts +0 -1
  448. package/dist/utils/setLanguageOverride.d.ts.map +1 -1
  449. package/dist/utils/setWrapperNodeProps.d.ts +1 -11
  450. package/dist/utils/setWrapperNodeProps.d.ts.map +1 -1
  451. package/dist/utils/setWrapperNodeProps.js +1 -3
  452. package/dist/utils/setWrapperNodeProps.js.map +1 -1
  453. package/dist/utils/shouldUseTokenTransformer.d.ts +0 -1
  454. package/dist/utils/shouldUseTokenTransformer.d.ts.map +1 -1
  455. package/dist/utils/splitFileContents.d.ts.map +1 -1
  456. package/dist/utils/trimPatchContext.d.ts.map +1 -1
  457. package/dist/utils/updateDiffHunks.d.ts +0 -1
  458. package/dist/utils/updateDiffHunks.d.ts.map +1 -1
  459. package/dist/utils/virtualDiffLayout.d.ts +10 -55
  460. package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
  461. package/dist/utils/wrapTokenFragments.d.ts +0 -1
  462. package/dist/utils/wrapTokenFragments.d.ts.map +1 -1
  463. package/dist/worker/WorkerPoolManager.d.ts +2 -17
  464. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  465. package/dist/worker/WorkerPoolManager.js +8 -5
  466. package/dist/worker/WorkerPoolManager.js.map +1 -1
  467. package/dist/worker/getOrCreateWorkerPoolSingleton.d.ts +1 -5
  468. package/dist/worker/getOrCreateWorkerPoolSingleton.d.ts.map +1 -1
  469. package/dist/worker/types.d.ts +0 -1
  470. package/dist/worker/types.d.ts.map +1 -1
  471. package/dist/worker/worker-portable.d.ts +1 -1
  472. package/dist/worker/worker-portable.js +113 -354
  473. package/dist/worker/worker-portable.js.map +1 -1
  474. package/dist/worker/worker.d.ts +1 -1
  475. package/dist/worker/worker.js +14 -11
  476. package/dist/worker/worker.js.map +1 -1
  477. package/package.json +4 -5
@@ -47,21 +47,13 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
47
47
  return decision;
48
48
  });
49
49
  const onEditComplete = _onEditComplete != null ? handleOnEditComplete : void 0;
50
- const effectiveFileDiff = useMemo(() => {
51
- if (fileDiff != null) return fileDiff;
52
- const { current: accepted } = acceptedCache;
53
- const filePair = accepted?.filePair;
54
- if (accepted != null && filePair != null) {
55
- if (isSameFilePair(oldFile, newFile, filePair.stale) || isSameFilePair(oldFile, newFile, filePair.installed)) return filePair.fileDiff;
56
- accepted.filePair = null;
57
- }
58
- return parseDiffFromFile(oldFile ?? null, newFile ?? null, options?.parseDiffOptions);
59
- }, [
50
+ const effectiveFileDiff = useEffectiveFileDiff({
51
+ acceptedCache,
60
52
  fileDiff,
61
- oldFile,
62
53
  newFile,
63
- options?.parseDiffOptions
64
- ]);
54
+ oldFile,
55
+ parseDiffOptions: options?.parseDiffOptions
56
+ });
65
57
  const instanceRef = useRef(null);
66
58
  const disposeEditorRef = useRef(null);
67
59
  const getEditor = useStableCallback(() => {
@@ -137,6 +129,24 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
137
129
  getAnnotationSlotName: useCallback((annotation) => instanceRef.current?.getAnnotationSlotName(annotation) ?? getLineAnnotationName(annotation), [])
138
130
  };
139
131
  }
132
+ function useEffectiveFileDiff({ acceptedCache, fileDiff, newFile, oldFile, parseDiffOptions }) {
133
+ return useMemo(() => {
134
+ if (fileDiff != null) return fileDiff;
135
+ const { current: accepted } = acceptedCache;
136
+ const filePair = accepted?.filePair;
137
+ if (accepted != null && filePair != null) {
138
+ if (isSameFilePair(oldFile, newFile, filePair.stale) || isSameFilePair(oldFile, newFile, filePair.installed)) return filePair.fileDiff;
139
+ accepted.filePair = null;
140
+ }
141
+ return parseDiffFromFile(oldFile ?? null, newFile ?? null, parseDiffOptions);
142
+ }, [
143
+ acceptedCache,
144
+ fileDiff,
145
+ oldFile,
146
+ newFile,
147
+ parseDiffOptions
148
+ ]);
149
+ }
140
150
  function isSameFilePair(oldFile, newFile, filePair) {
141
151
  return areFileTargetsEqual(oldFile ?? void 0, filePair.oldFile ?? void 0) && areFileTargetsEqual(newFile ?? void 0, filePair.newFile ?? void 0);
142
152
  }
@@ -148,11 +158,15 @@ function resolveAcceptedValues(fileDiff, lineAnnotations, acceptedCache) {
148
158
  };
149
159
  const { fileDiff: acceptedDiff, annotations: acceptedAnnotations } = accepted;
150
160
  let resolvedFileDiff = fileDiff;
151
- if (acceptedDiff != null) if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) resolvedFileDiff = acceptedDiff.installed;
152
- else accepted.fileDiff = null;
161
+ if (acceptedDiff != null) {
162
+ if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) resolvedFileDiff = acceptedDiff.installed;
163
+ else accepted.fileDiff = null;
164
+ }
153
165
  let resolvedAnnotations = lineAnnotations;
154
- if (acceptedAnnotations != null) if (lineAnnotations === acceptedAnnotations.stale) resolvedAnnotations = acceptedAnnotations.installed;
155
- else accepted.annotations = null;
166
+ if (acceptedAnnotations != null) {
167
+ if (lineAnnotations === acceptedAnnotations.stale) resolvedAnnotations = acceptedAnnotations.installed;
168
+ else accepted.annotations = null;
169
+ }
156
170
  if (accepted.fileDiff == null && accepted.annotations == null && accepted.filePair == null) acceptedCache.current = null;
157
171
  return {
158
172
  fileDiff: resolvedFileDiff,
@@ -1 +1 @@
1
- {"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport {\n FileDiff,\n type FileDiffEditChangeHandler,\n type FileDiffEditCompleteEvent,\n type FileDiffEditCompleteHandler,\n type FileDiffOptions,\n} from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areDiffTargetsEqual } from '../../utils/areDiffTargetsEqual';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { parseDiffFromFile } from '../../utils/parseDiffFromFile';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedFilePair {\n oldFile: FileContents | null;\n newFile: FileContents | null;\n}\n\ninterface AcceptedCompletion<LAnnotation> {\n fileDiff: {\n installed: FileDiffMetadata;\n stale: FileDiffMetadata;\n } | null;\n filePair: {\n fileDiff: FileDiffMetadata;\n installed: AcceptedFilePair;\n stale: AcceptedFilePair;\n } | null;\n annotations: {\n installed: DiffLineAnnotation<LAnnotation>[] | undefined;\n stale: DiffLineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileDiffInstanceProps<LAnnotation, Caret> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents | null;\n newFile?: FileContents | null;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file-diff', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileDiffInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getAnnotationSlotName(annotation: DiffLineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileDiffInstance<LAnnotation, Caret>({\n fileDiff,\n oldFile,\n newFile,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileDiffInstanceProps<\n LAnnotation,\n Caret\n>): UseFileDiffInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file-diff', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its diff on the instance immediately,\n // but the fileDiff/lineAnnotations props stay pre-edit until the owner's\n // state update lands. This holds the accepted values so the renders in\n // between do not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileDiffEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n fileDiff: {\n installed: event.fileDiff,\n stale: event.originalFileDiff,\n },\n filePair:\n fileDiff == null\n ? {\n fileDiff: event.fileDiff,\n installed: { oldFile: event.oldFile, newFile: event.newFile },\n stale: { oldFile: oldFile ?? null, newFile: newFile ?? null },\n }\n : null,\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n // File-pair inputs parse here. While the file props still match the pair\n // from acceptance time (stale) or the completion event's files (installed),\n // the parse is the accepted diff itself; any other pair clears the record\n // and parses fresh.\n const effectiveFileDiff = useMemo(() => {\n if (fileDiff != null) {\n return fileDiff;\n }\n const { current: accepted } = acceptedCache;\n const filePair = accepted?.filePair;\n if (accepted != null && filePair != null) {\n if (\n isSameFilePair(oldFile, newFile, filePair.stale) ||\n isSameFilePair(oldFile, newFile, filePair.installed)\n ) {\n return filePair.fileDiff;\n }\n accepted.filePair = null;\n }\n return parseDiffFromFile(\n oldFile ?? null,\n newFile ?? null,\n options?.parseDiffOptions\n );\n }, [fileDiff, oldFile, newFile, options?.parseDiffOptions]);\n const instanceRef = useRef<\n | FileDiff<LAnnotation, Caret>\n | VirtualizedFileDiff<LAnnotation, Caret>\n | null\n >(null);\n const disposeEditorRef = useRef<() => void>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n return createEditor('file-diff', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instanceRef.current, getEditor);\n }\n void instanceRef.current.hydrate({\n fileDiff: effectiveFileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit && disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n const resolved = resolveAcceptedValues(\n effectiveFileDiff,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n forceRender,\n fileDiff: resolved.fileDiff,\n lineAnnotations: resolved.lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n // Attach editor after rendering if required\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instance, getEditor);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: DiffLineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n\n return {\n fileDiff: effectiveFileDiff,\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n };\n}\n\n// Whether the file props name the same files as a recorded pair.\nfunction isSameFilePair(\n oldFile: FileContents | null | undefined,\n newFile: FileContents | null | undefined,\n filePair: AcceptedFilePair\n): boolean {\n return (\n areFileTargetsEqual(oldFile ?? undefined, filePair.oldFile ?? undefined) &&\n areFileTargetsEqual(newFile ?? undefined, filePair.newFile ?? undefined)\n );\n}\n\n// Render the installed values in place of props that still match their stale\n// counterparts. Any other prop value clears its slot — filePair settles in\n// the parse memo instead — and the ref clears once all three have.\nfunction resolveAcceptedValues<LAnnotation>(\n fileDiff: FileDiffMetadata,\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): {\n fileDiff: FileDiffMetadata;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n} {\n const { current: accepted } = acceptedCache;\n if (accepted == null) {\n return { fileDiff, lineAnnotations };\n }\n const { fileDiff: acceptedDiff, annotations: acceptedAnnotations } = accepted;\n let resolvedFileDiff = fileDiff;\n if (acceptedDiff != null) {\n if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) {\n resolvedFileDiff = acceptedDiff.installed;\n } else {\n accepted.fileDiff = null;\n }\n }\n let resolvedAnnotations = lineAnnotations;\n if (acceptedAnnotations != null) {\n if (lineAnnotations === acceptedAnnotations.stale) {\n resolvedAnnotations = acceptedAnnotations.installed;\n } else {\n accepted.annotations = null;\n }\n }\n if (\n accepted.fileDiff == null &&\n accepted.annotations == null &&\n accepted.filePair == null\n ) {\n acceptedCache.current = null;\n }\n return { fileDiff: resolvedFileDiff, lineAnnotations: resolvedAnnotations };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation, Caret> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileDiffOptionsProps<LAnnotation, Caret>):\n | FileDiffOptions<LAnnotation, Caret>\n | undefined {\n const needsReactOverrides =\n controlledSelection ||\n hasGutterRenderUtility ||\n hasCustomHeader ||\n onEditChange != null ||\n onEditComplete != null;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: FileDiff<LAnnotation, Caret>,\n getEditor: () => Editor<'file-diff', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsCA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAiD9C,SAAgB,oBAAwC,EACtD,UACA,SACA,SACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBAIyB;CACzC,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAAoC;C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AQ;EACf,MAAM;CACR;AACF"}
1
+ {"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from 'react';\n\nimport {\n FileDiff,\n type FileDiffEditChangeHandler,\n type FileDiffEditCompleteEvent,\n type FileDiffEditCompleteHandler,\n type FileDiffOptions,\n} from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areDiffTargetsEqual } from '../../utils/areDiffTargetsEqual';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { parseDiffFromFile } from '../../utils/parseDiffFromFile';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedFilePair {\n oldFile: FileContents | null;\n newFile: FileContents | null;\n}\n\ninterface AcceptedCompletion<LAnnotation> {\n fileDiff: {\n installed: FileDiffMetadata;\n stale: FileDiffMetadata;\n } | null;\n filePair: {\n fileDiff: FileDiffMetadata;\n installed: AcceptedFilePair;\n stale: AcceptedFilePair;\n } | null;\n annotations: {\n installed: DiffLineAnnotation<LAnnotation>[] | undefined;\n stale: DiffLineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileDiffInstanceProps<LAnnotation, Caret> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents | null;\n newFile?: FileContents | null;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file-diff', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileDiffInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getAnnotationSlotName(annotation: DiffLineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileDiffInstance<LAnnotation, Caret>({\n fileDiff,\n oldFile,\n newFile,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileDiffInstanceProps<\n LAnnotation,\n Caret\n>): UseFileDiffInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file-diff', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its diff on the instance immediately,\n // but the fileDiff/lineAnnotations props stay pre-edit until the owner's\n // state update lands. This holds the accepted values so the renders in\n // between do not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileDiffEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n fileDiff: {\n installed: event.fileDiff,\n stale: event.originalFileDiff,\n },\n filePair:\n fileDiff == null\n ? {\n fileDiff: event.fileDiff,\n installed: { oldFile: event.oldFile, newFile: event.newFile },\n stale: { oldFile: oldFile ?? null, newFile: newFile ?? null },\n }\n : null,\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n // File-pair inputs parse here. While the file props still match the pair\n // from acceptance time (stale) or the completion event's files (installed),\n // the parse is the accepted diff itself; any other pair clears the record\n // and parses fresh.\n const effectiveFileDiff = useEffectiveFileDiff({\n acceptedCache,\n fileDiff,\n newFile,\n oldFile,\n parseDiffOptions: options?.parseDiffOptions,\n });\n const instanceRef = useRef<\n | FileDiff<LAnnotation, Caret>\n | VirtualizedFileDiff<LAnnotation, Caret>\n | null\n >(null);\n const disposeEditorRef = useRef<() => void>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n return createEditor('file-diff', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instanceRef.current, getEditor);\n }\n void instanceRef.current.hydrate({\n fileDiff: effectiveFileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit && disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n const resolved = resolveAcceptedValues(\n effectiveFileDiff,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n forceRender,\n fileDiff: resolved.fileDiff,\n lineAnnotations: resolved.lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n // Attach editor after rendering if required\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instance, getEditor);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: DiffLineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n\n return {\n fileDiff: effectiveFileDiff,\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n };\n}\n\ninterface UseEffectiveFileDiffProps<LAnnotation, Caret> {\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>;\n fileDiff: FileDiffMetadata | undefined;\n newFile: FileContents | null | undefined;\n oldFile: FileContents | null | undefined;\n parseDiffOptions: FileDiffOptions<LAnnotation, Caret>['parseDiffOptions'];\n}\n\n// Resolves the diff the instance renders: the `fileDiff` prop when given;\n// otherwise the accepted edit's cached diff while the file props still name the\n// pair it was accepted against; otherwise a fresh parse of the file props. A\n// cached pair that no longer matches is dropped on the way. Kept in its own hook\n// because the render-time ref read and write are deliberate; the boundary lets\n// the calling hook stay compilable.\nfunction useEffectiveFileDiff<LAnnotation, Caret>({\n acceptedCache,\n fileDiff,\n newFile,\n oldFile,\n parseDiffOptions,\n}: UseEffectiveFileDiffProps<LAnnotation, Caret>): FileDiffMetadata {\n /* oxlint-disable react/immutability react/refs -- accepted edit output must\n * replace stale file-pair props during render */\n const effectiveFileDiff = useMemo(() => {\n if (fileDiff != null) {\n return fileDiff;\n }\n const { current: accepted } = acceptedCache;\n const filePair = accepted?.filePair;\n if (accepted != null && filePair != null) {\n if (\n isSameFilePair(oldFile, newFile, filePair.stale) ||\n isSameFilePair(oldFile, newFile, filePair.installed)\n ) {\n return filePair.fileDiff;\n }\n accepted.filePair = null;\n }\n return parseDiffFromFile(\n oldFile ?? null,\n newFile ?? null,\n parseDiffOptions\n );\n }, [acceptedCache, fileDiff, oldFile, newFile, parseDiffOptions]);\n /* oxlint-enable react/immutability react/refs */\n\n return effectiveFileDiff;\n}\n\n// Whether the file props name the same files as a recorded pair.\nfunction isSameFilePair(\n oldFile: FileContents | null | undefined,\n newFile: FileContents | null | undefined,\n filePair: AcceptedFilePair\n): boolean {\n return (\n areFileTargetsEqual(oldFile ?? undefined, filePair.oldFile ?? undefined) &&\n areFileTargetsEqual(newFile ?? undefined, filePair.newFile ?? undefined)\n );\n}\n\n// Render the installed values in place of props that still match their stale\n// counterparts. Any other prop value clears its slot — filePair settles in\n// the parse memo instead — and the ref clears once all three have.\nfunction resolveAcceptedValues<LAnnotation>(\n fileDiff: FileDiffMetadata,\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): {\n fileDiff: FileDiffMetadata;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n} {\n const { current: accepted } = acceptedCache;\n if (accepted == null) {\n return { fileDiff, lineAnnotations };\n }\n const { fileDiff: acceptedDiff, annotations: acceptedAnnotations } = accepted;\n let resolvedFileDiff = fileDiff;\n if (acceptedDiff != null) {\n if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) {\n resolvedFileDiff = acceptedDiff.installed;\n } else {\n accepted.fileDiff = null;\n }\n }\n let resolvedAnnotations = lineAnnotations;\n if (acceptedAnnotations != null) {\n if (lineAnnotations === acceptedAnnotations.stale) {\n resolvedAnnotations = acceptedAnnotations.installed;\n } else {\n accepted.annotations = null;\n }\n }\n if (\n accepted.fileDiff == null &&\n accepted.annotations == null &&\n accepted.filePair == null\n ) {\n acceptedCache.current = null;\n }\n return { fileDiff: resolvedFileDiff, lineAnnotations: resolvedAnnotations };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation, Caret> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileDiffOptionsProps<LAnnotation, Caret>):\n | FileDiffOptions<LAnnotation, Caret>\n | undefined {\n const needsReactOverrides =\n controlledSelection ||\n hasGutterRenderUtility ||\n hasCustomHeader ||\n onEditChange != null ||\n onEditComplete != null;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: FileDiff<LAnnotation, Caret>,\n getEditor: () => Editor<'file-diff', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAsCA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAiD9C,SAAgB,oBAAwC,EACtD,UACA,SACA,SACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBAIyB;CACzC,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAAoC;CACzD,MAAM,qBAAqB,mBACxB,UACC,gBAAgB,KAAK,CACzB;CACA,MAAM,eAAe,iBAAiB,OAAO,qBAAqB,KAAA;CAKlE,MAAM,gBAAgB,OAA+C,IAAI;CACzE,MAAM,uBAAuB,mBAC1B,UAAyD;EACxD,MAAM,WAAW,kBAAkB,KAAK,KAAK;EAC7C,IAAI,aAAa,UACf,cAAc,UAAU;GACtB,UAAU;IACR,WAAW,MAAM;IACjB,OAAO,MAAM;GACf;GACA,UACE,YAAY,OACR;IACE,UAAU,MAAM;IAChB,WAAW;KAAE,SAAS,MAAM;KAAS,SAAS,MAAM;IAAQ;IAC5D,OAAO;KAAE,SAAS,WAAW;KAAM,SAAS,WAAW;IAAK;GAC9D,IACA;GACN,aAAa;IACX,WAAW,M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AAS,sBACP,UACA,iBACA,eAIA;CACA,MAAM,EAAE,SAAS,aAAa;CAC9B,IAAI,YAAY,MACd,OAAO;EAAE;EAAU;CAAgB;CAErC,MAAM,EAAE,UAAU,cAAc,aAAa,wBAAwB;CACrE,IAAI,mBAAmB;CACvB,IAAI,gBAAgB,MAAM;EACxB,IAAI,oBAAoB,UAAU,aAAa,KAAK,GAClD,mBAAmB,aAAa;OAEhC,SAAS,WAAW;CAExB;CACA,IAAI,sBAAsB;CAC1B,IAAI,uBAAuB,MAAM;EAC/B,IAAI,oBAAoB,oBAAoB,OAC1C,sBAAsB,oBAAoB;OAE1C,SAAS,cAAc;CAE3B;CACA,IACE,SAAS,YAAY,QACrB,SAAS,eAAe,QACxB,SAAS,YAAY,MAErB,cAAc,UAAU;CAE1B,OAAO;EAAE,UAAU;EAAkB,iBAAiB;CAAoB;AAC5E;AAWA,SAAS,qBAAyC,EAChD,SACA,qBACA,iBACA,wBACA,cACA,kBAGY;CAQZ,IAAI,EANF,uBACA,0BACA,mBACA,gBAAgB,QAChB,kBAAkB,OAGlB,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACb;EACA;CACF;AACF;AAEA,SAAS,UACP,UACA,WACY;CACZ,MAAM,SAAS,UAAU;CACzB,IAAI;EACF,OAAO,OAAO,KAAK,QAAQ;CAC7B,SAAS,OAAO;EACd,OAAO,QAAQ;EACf,MAAM;CACR;AACF"}
@@ -2,6 +2,7 @@ import { FileContents, LineAnnotation, SelectedLineRange, VirtualFileMetrics } f
2
2
  import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
3
  import { FileEditChangeHandler, FileEditCompleteHandler, FileOptions } from "../../components/File.js";
4
4
  import { EditorOptions } from "../../editor/editor.js";
5
+ import "../../edit/index.js";
5
6
  //#region src/react/utils/useFileInstance.d.ts
6
7
  interface UseFileInstanceProps<LAnnotation, Caret> {
7
8
  file: FileContents;
@@ -24,22 +25,7 @@ interface UseFileInstanceReturn<LAnnotation> {
24
25
  getHoveredLine(): GetHoveredLineResult<'file'> | undefined;
25
26
  getAnnotationSlotName(annotation: LineAnnotation<LAnnotation>): string;
26
27
  }
27
- declare function useFileInstance<LAnnotation, Caret>({
28
- file,
29
- options,
30
- editorOptions,
31
- editStateKey,
32
- lineAnnotations,
33
- selectedLines,
34
- prerenderedHTML,
35
- metrics,
36
- hasGutterRenderUtility,
37
- hasCustomHeader,
38
- disableWorkerPool,
39
- edit,
40
- onEditChange: _onEditChange,
41
- onEditComplete: _onEditComplete
42
- }: UseFileInstanceProps<LAnnotation, Caret>): UseFileInstanceReturn<LAnnotation>;
28
+ declare function useFileInstance<LAnnotation, Caret>({ file, options, editorOptions, editStateKey, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, edit, onEditChange: _onEditChange, onEditComplete: _onEditComplete }: UseFileInstanceProps<LAnnotation, Caret>): UseFileInstanceReturn<LAnnotation>;
43
29
  //#endregion
44
30
  export { useFileInstance };
45
31
  //# sourceMappingURL=useFileInstance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;UAgDU,oBAAA;EACR,IAAA,EAAM,YAAA;EACN,OAAA,EAAS,WAAA,CAAY,WAAA,EAAa,KAAA;EAClC,aAAA,EAAe,aAAA,SAAsB,WAAA,EAAa,KAAA;EAClD,YAAA;EACA,eAAA,EAAiB,cAAA,CAAe,WAAA;EAChC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,IAAA;EACA,YAAA,GAAe,qBAAA,CAAsB,WAAA,EAAa,KAAA;EAClD,cAAA,GAAiB,uBAAA,CAAwB,WAAA,EAAa,KAAA;AAAA;AAAA,UAG9C,qBAAA;EACR,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAA;EAClB,qBAAA,CAAsB,UAAA,EAAY,cAAA,CAAe,WAAA;AAAA;AAAA,iBAGnC,eAAA;EACd,IAAA;EACA,OAAA;EACA,aAAA;EACA,YAAA;EACA,eAAA;EACA,aAAA;EACA,eAAA;EACA,OAAA;EACA,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,IAAA;EACA,YAAA,EAAc,aAAA;EACd,cAAA,EAAgB;AAAA,GACf,oBAAA,CACD,WAAA,EACA,KAAA,IACE,qBAAA,CAAsB,WAAA"}
1
+ {"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;;UAgDU,qBAAqB,aAAa;EAC1C,MAAM;EACN,SAAS,YAAY,aAAa;EAClC,eAAe,sBAAsB,aAAa;EAClD;EACA,iBAAiB,eAAe;EAChC,eAAe;EACf;EACA,UAAU;EACV;EACA;EACA;EACA;EACA,eAAe,sBAAsB,aAAa;EAClD,iBAAiB,wBAAwB,aAAa;;UAG9C,sBAAsB;EAC9B,IAAI,MAAM;EACV,kBAAkB;EAClB,sBAAsB,YAAY,eAAe;;iBAGnC,gBAAgB,aAAa,SAC3C,MACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBACf,qBACD,aACA,SACE,sBAAsB"}
@@ -116,11 +116,15 @@ function resolveAcceptedValues(file, lineAnnotations, acceptedCache) {
116
116
  };
117
117
  const { file: acceptedFiles, annotations: acceptedAnnotations } = accepted;
118
118
  let resolvedFile = file;
119
- if (acceptedFiles != null) if (areFileTargetsEqual(file, acceptedFiles.stale)) resolvedFile = acceptedFiles.installed;
120
- else accepted.file = null;
119
+ if (acceptedFiles != null) {
120
+ if (areFileTargetsEqual(file, acceptedFiles.stale)) resolvedFile = acceptedFiles.installed;
121
+ else accepted.file = null;
122
+ }
121
123
  let resolvedAnnotations = lineAnnotations;
122
- if (acceptedAnnotations != null) if (lineAnnotations === acceptedAnnotations.stale) resolvedAnnotations = acceptedAnnotations.installed;
123
- else accepted.annotations = null;
124
+ if (acceptedAnnotations != null) {
125
+ if (lineAnnotations === acceptedAnnotations.stale) resolvedAnnotations = acceptedAnnotations.installed;
126
+ else accepted.annotations = null;
127
+ }
124
128
  if (accepted.file == null && accepted.annotations == null) acceptedCache.current = null;
125
129
  return {
126
130
  file: resolvedFile,
@@ -1 +1 @@
1
- {"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport {\n File,\n type FileEditChangeHandler,\n type FileEditCompleteEvent,\n type FileEditCompleteHandler,\n type FileOptions,\n} from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedCompletion<LAnnotation> {\n file: {\n installed: FileContents;\n stale: FileContents;\n } | null;\n annotations: {\n installed: LineAnnotation<LAnnotation>[] | undefined;\n stale: LineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileInstanceProps<LAnnotation, Caret> {\n file: FileContents;\n options: FileOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileInstanceReturn<LAnnotation> {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n getAnnotationSlotName(annotation: LineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileInstance<LAnnotation, Caret>({\n file,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileInstanceProps<\n LAnnotation,\n Caret\n>): UseFileInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its file on the instance immediately,\n // but the file/lineAnnotations props stay pre-edit until the owner's state\n // update lands. This holds the accepted values so the renders in between do\n // not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n file: { installed: event.file, stale: event.originalFile },\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n const instanceRef = useRef<\n File<LAnnotation, Caret> | VirtualizedFile<LAnnotation, Caret> | null\n >(null);\n const disposeEditorRef = useRef<() => void>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('File: EditContext is not attached');\n }\n return createEditor('file', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instanceRef.current, getEditor);\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit && disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n const resolved = resolveAcceptedValues(\n file,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n file: resolved.file,\n lineAnnotations: resolved.lineAnnotations,\n forceRender,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n // Attach editor after rendering if required\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instance, getEditor);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: LineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n return { ref, getHoveredLine, getAnnotationSlotName };\n}\n\n// Return the installed values in place of props that still match their stale\n// counterparts. Any other prop value clears its half, and the ref clears once\n// both halves have.\nfunction resolveAcceptedValues<LAnnotation>(\n file: FileContents,\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): {\n file: FileContents;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n} {\n const { current: accepted } = acceptedCache;\n if (accepted == null) {\n return { file, lineAnnotations };\n }\n const { file: acceptedFiles, annotations: acceptedAnnotations } = accepted;\n let resolvedFile = file;\n if (acceptedFiles != null) {\n if (areFileTargetsEqual(file, acceptedFiles.stale)) {\n resolvedFile = acceptedFiles.installed;\n } else {\n accepted.file = null;\n }\n }\n let resolvedAnnotations = lineAnnotations;\n if (acceptedAnnotations != null) {\n if (lineAnnotations === acceptedAnnotations.stale) {\n resolvedAnnotations = acceptedAnnotations.installed;\n } else {\n accepted.annotations = null;\n }\n }\n if (accepted.file == null && accepted.annotations == null) {\n acceptedCache.current = null;\n }\n return { file: resolvedFile, lineAnnotations: resolvedAnnotations };\n}\n\ninterface MergeFileOptionsProps<LAnnotation, Caret> {\n options: FileOptions<LAnnotation, Caret> | undefined;\n controlledSelection: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n onEditChange: FileEditChangeHandler<LAnnotation, Caret> | undefined;\n onEditComplete: FileEditCompleteHandler<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileOptionsProps<LAnnotation, Caret>):\n | FileOptions<LAnnotation, Caret>\n | undefined {\n const needsReactOverrides =\n controlledSelection ||\n hasGutterRenderUtility ||\n hasCustomHeader ||\n onEditChange != null ||\n onEditComplete != null;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: File<LAnnotation, Caret>,\n getEditor: () => Editor<'file', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAkCA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAoC9C,SAAgB,gBAAoC,EAClD,MACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBAIqB;CACrC,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAAoC;CACzD,MAAM,qBAAqB,m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AS,cAAc;CAG3B,IAAI,SAAS,QAAQ,QAAQ,SAAS,eAAe,MACnD,cAAc,UAAU;CAE1B,OAAO;EAAE,MAAM;EAAc,iBAAiB;CAAoB;AACpE;AAWA,SAAS,iBAAqC,EAC5C,SACA,qBACA,iBACA,wBACA,cACA,kBAGY;CAQZ,IAAI,EANF,uBACA,0BACA,mBACA,gBAAgB,QAChB,kBAAkB,OAGlB,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACb;EACA;CACF;AACF;AAEA,SAAS,UACP,UACA,WACY;CACZ,MAAM,SAAS,UAAU;CACzB,IAAI;EACF,OAAO,OAAO,KAAK,QAAQ;CAC7B,SAAS,OAAO;EACd,OAAO,QAAQ;EACf,MAAM;CACR;AACF"}
1
+ {"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport {\n File,\n type FileEditChangeHandler,\n type FileEditCompleteEvent,\n type FileEditCompleteHandler,\n type FileOptions,\n} from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedCompletion<LAnnotation> {\n file: {\n installed: FileContents;\n stale: FileContents;\n } | null;\n annotations: {\n installed: LineAnnotation<LAnnotation>[] | undefined;\n stale: LineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileInstanceProps<LAnnotation, Caret> {\n file: FileContents;\n options: FileOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileInstanceReturn<LAnnotation> {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n getAnnotationSlotName(annotation: LineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileInstance<LAnnotation, Caret>({\n file,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileInstanceProps<\n LAnnotation,\n Caret\n>): UseFileInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its file on the instance immediately,\n // but the file/lineAnnotations props stay pre-edit until the owner's state\n // update lands. This holds the accepted values so the renders in between do\n // not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n file: { installed: event.file, stale: event.originalFile },\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n const instanceRef = useRef<\n File<LAnnotation, Caret> | VirtualizedFile<LAnnotation, Caret> | null\n >(null);\n const disposeEditorRef = useRef<() => void>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('File: EditContext is not attached');\n }\n return createEditor('file', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instanceRef.current, getEditor);\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit && disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n const resolved = resolveAcceptedValues(\n file,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n file: resolved.file,\n lineAnnotations: resolved.lineAnnotations,\n forceRender,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n // Attach editor after rendering if required\n if (edit && disposeEditorRef.current == null) {\n disposeEditorRef.current = applyEdit(instance, getEditor);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: LineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n return { ref, getHoveredLine, getAnnotationSlotName };\n}\n\n// Return the installed values in place of props that still match their stale\n// counterparts. Any other prop value clears its half, and the ref clears once\n// both halves have.\nfunction resolveAcceptedValues<LAnnotation>(\n file: FileContents,\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): {\n file: FileContents;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n} {\n const { current: accepted } = acceptedCache;\n if (accepted == null) {\n return { file, lineAnnotations };\n }\n const { file: acceptedFiles, annotations: acceptedAnnotations } = accepted;\n let resolvedFile = file;\n if (acceptedFiles != null) {\n if (areFileTargetsEqual(file, acceptedFiles.stale)) {\n resolvedFile = acceptedFiles.installed;\n } else {\n accepted.file = null;\n }\n }\n let resolvedAnnotations = lineAnnotations;\n if (acceptedAnnotations != null) {\n if (lineAnnotations === acceptedAnnotations.stale) {\n resolvedAnnotations = acceptedAnnotations.installed;\n } else {\n accepted.annotations = null;\n }\n }\n if (accepted.file == null && accepted.annotations == null) {\n acceptedCache.current = null;\n }\n return { file: resolvedFile, lineAnnotations: resolvedAnnotations };\n}\n\ninterface MergeFileOptionsProps<LAnnotation, Caret> {\n options: FileOptions<LAnnotation, Caret> | undefined;\n controlledSelection: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n onEditChange: FileEditChangeHandler<LAnnotation, Caret> | undefined;\n onEditComplete: FileEditCompleteHandler<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileOptionsProps<LAnnotation, Caret>):\n | FileOptions<LAnnotation, Caret>\n | undefined {\n const needsReactOverrides =\n controlledSelection ||\n hasGutterRenderUtility ||\n hasCustomHeader ||\n onEditChange != null ||\n onEditComplete != null;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: File<LAnnotation, Caret>,\n getEditor: () => Editor<'file', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAkCA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAoC9C,SAAgB,gBAAoC,EAClD,M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Aa,wBAAwB;CAClE,IAAI,eAAe;CACnB,IAAI,iBAAiB,MAAM;EACzB,IAAI,oBAAoB,MAAM,cAAc,KAAK,GAC/C,eAAe,cAAc;OAE7B,SAAS,OAAO;CAEpB;CACA,IAAI,sBAAsB;CAC1B,IAAI,uBAAuB,MAAM;EAC/B,IAAI,oBAAoB,oBAAoB,OAC1C,sBAAsB,oBAAoB;OAE1C,SAAS,cAAc;CAE3B;CACA,IAAI,SAAS,QAAQ,QAAQ,SAAS,eAAe,MACnD,cAAc,UAAU;CAE1B,OAAO;EAAE,MAAM;EAAc,iBAAiB;CAAoB;AACpE;AAWA,SAAS,iBAAqC,EAC5C,SACA,qBACA,iBACA,wBACA,cACA,kBAGY;CAQZ,IAAI,EANF,uBACA,0BACA,mBACA,gBAAgB,QAChB,kBAAkB,OAGlB,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACb;EACA;CACF;AACF;AAEA,SAAS,UACP,UACA,WACY;CACZ,MAAM,SAAS,UAAU;CACzB,IAAI;EACF,OAAO,OAAO,KAAK,QAAQ;CAC7B,SAAS,OAAO;EACd,OAAO,QAAQ;EACf,MAAM;CACR;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStableCallback.d.ts","names":[],"sources":["../../../src/react/utils/useStableCallback.ts"],"mappings":";iBAGgB,iBAAA,eAAgC,IAAA,iBAC9C,QAAA,EAAU,CAAA,GACT,CAAC"}
1
+ {"version":3,"file":"useStableCallback.d.ts","names":[],"sources":["../../../src/react/utils/useStableCallback.ts"],"mappings":";iBAGgB,kBAAkB,cAAc,qBAC9C,UAAU,IACT"}
@@ -3,7 +3,6 @@ import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
3
  import { MergeConflictDiffAction } from "../../utils/parseMergeConflictDiffFromFile.js";
4
4
  import { UnresolvedFile } from "../../components/UnresolvedFile.js";
5
5
  import { UnresolvedFileReactOptions } from "../UnresolvedFile.js";
6
-
7
6
  //#region src/react/utils/useUnresolvedFileInstance.d.ts
8
7
  interface UseUnresolvedFileInstanceProps<LAnnotation> {
9
8
  file: FileContents;
@@ -24,17 +23,7 @@ interface UseUnresolvedFileInstanceReturn<LAnnotation> {
24
23
  getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;
25
24
  getInstance(): UnresolvedFile<LAnnotation> | undefined;
26
25
  }
27
- declare function useUnresolvedFileInstance<LAnnotation>({
28
- file,
29
- options,
30
- lineAnnotations,
31
- selectedLines,
32
- prerenderedHTML,
33
- hasConflictUtility,
34
- hasGutterRenderUtility,
35
- hasCustomHeader,
36
- disableWorkerPool
37
- }: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation>;
26
+ declare function useUnresolvedFileInstance<LAnnotation>({ file, options, lineAnnotations, selectedLines, prerenderedHTML, hasConflictUtility, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }: UseUnresolvedFileInstanceProps<LAnnotation>): UseUnresolvedFileInstanceReturn<LAnnotation>;
38
27
  //#endregion
39
28
  export { useUnresolvedFileInstance };
40
29
  //# sourceMappingURL=useUnresolvedFileInstance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useUnresolvedFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useUnresolvedFileInstance.ts"],"mappings":";;;;;;;UAoCU,8BAAA;EACR,IAAA,EAAM,YAAA;EACN,OAAA,GAAU,0BAAA,CAA2B,WAAA;EACrC,eAAA,EAAiB,kBAAA,CAAmB,WAAA;EACpC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,kBAAA;EACA,sBAAA;EACA,eAAA;EACA,iBAAA;AAAA;AAAA,UAGQ,+BAAA;EACR,QAAA,EAAU,gBAAA;EACV,OAAA,GAAU,uBAAA;EACV,UAAA,EAAY,sBAAA;EACZ,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAA;EAClB,WAAA,IAAe,cAAA,CAAe,WAAA;AAAA;AAAA,iBAGhB,yBAAA;EACd,IAAA;EACA,OAAA;EACA,eAAA;EACA,aAAA;EACA,eAAA;EACA,kBAAA;EACA,sBAAA;EACA,eAAA;EACA;AAAA,GACC,8BAAA,CAA+B,WAAA,IAAe,+BAAA,CAAgC,WAAA"}
1
+ {"version":3,"file":"useUnresolvedFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useUnresolvedFileInstance.ts"],"mappings":";;;;;;UAoCU,+BAA+B;EACvC,MAAM;EACN,UAAU,2BAA2B;EACrC,iBAAiB,mBAAmB;EACpC,eAAe;EACf;EACA;EACA;EACA;EACA;;UAGQ,gCAAgC;EACxC,UAAU;EACV,UAAU;EACV,YAAY;EACZ,IAAI,MAAM;EACV,kBAAkB;EAClB,eAAe,eAAe;;iBAGhB,0BAA0B,eACxC,MACA,SACA,iBACA,eACA,iBACA,oBACA,wBACA,iBACA,qBACC,+BAA+B,eAAe,gCAAgC"}
@@ -2,8 +2,8 @@ import { Element, ElementContent, Properties } from "../node_modules/.pnpm/@type
2
2
  import { BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, DiffsHighlighter, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HighlightedToken, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from "../types.js";
3
3
  import { TextDocument } from "../editor/textDocument.js";
4
4
  import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
5
+ import "../worker/index.js";
5
6
  import { DiffLineMetadata } from "../utils/iterateOverDiff.js";
6
-
7
7
  //#region src/renderers/DiffHunksRenderer.d.ts
8
8
  interface DiffHunksRendererOptions extends BaseDiffOptions {
9
9
  headerRenderMode?: FileHeaderRenderMode;
@@ -82,7 +82,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
82
82
  private expandedHunks;
83
83
  private deletionAnnotations;
84
84
  private additionAnnotations;
85
- private computedLang;
85
+ private computedLangs;
86
86
  private renderCache;
87
87
  private pendingHighlightResult;
88
88
  private pendingStructuralRows;
@@ -139,13 +139,8 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
139
139
  private applySessionDocumentChange;
140
140
  private applyRecomputePreservingSessionType;
141
141
  private markEditSessionPass;
142
- protected getUnifiedLineDecoration({
143
- lineType
144
- }: UnifiedLineDecorationProps): LineDecoration;
145
- protected getSplitLineDecoration({
146
- side,
147
- type
148
- }: SplitLineDecorationProps): LineDecoration;
142
+ protected getUnifiedLineDecoration({ lineType }: UnifiedLineDecorationProps): LineDecoration;
143
+ protected getSplitLineDecoration({ side, type }: SplitLineDecorationProps): LineDecoration;
149
144
  private createAnnotationElement;
150
145
  protected getUnifiedInjectedRowsForLine?: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;
151
146
  protected getSplitInjectedRowsForLine?: (ctx: RenderedLineContext) => SplitInjectedRowPlacement | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":";;;;;;;UAoJiB,wBAAA,SAAiC,eAAe;EAC/D,gBAAA,GAAmB,oBAAA;AAAA;AAAA,UAGJ,oCAAA,SAA6C,IAAA,CAC5D,2BAAA;EAGA,gBAAA,EAAkB,oBAAA;AAAA;AAAA,UAGH,0BAAA;EACf,IAAA;EACA,QAAA,EAAU,SAAS;EACnB,iBAAA;EACA,iBAAA;AAAA;AAAA,UAGe,wBAAA;EACf,IAAA;EACA,IAAA;EACA,SAAA;AAAA;AAAA,UAGe,cAAA;EACf,cAAA,EAAgB,SAAA;EAChB,gBAAA,GAAmB,UAAA;EACnB,iBAAA,GAAoB,UAAA;AAAA;AAAA,UAUL,mBAAA;EACf,IAAA;EACA,SAAA;EACA,SAAA;EACA,gBAAA;EACA,cAAA;EACA,YAAA,GAAe,gBAAA;EACf,YAAA,GAAe,gBAAgB;AAAA;AAAA,UAGhB,WAAA;EACf,OAAA,E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AuBA;EAaD,iBAAiB;UAIhB;UAIA;EAgjBD,cACL,6CACA,QAAQ,oBACP;EAyBI,cACL,QAAQ,mBACR,WAAU,mBACT;EAkDI,eACL,QAAQ,mBACR,eAAc;EAKT,kBACL,UAAU,kBACV;UAqBM;UAiEA;UA+DA;UASA"}
@@ -42,7 +42,7 @@ var DiffHunksRenderer = class {
42
42
  expandedHunks = /* @__PURE__ */ new Map();
43
43
  deletionAnnotations = {};
44
44
  additionAnnotations = {};
45
- computedLang = "text";
45
+ computedLangs = ["text"];
46
46
  renderCache;
47
47
  pendingHighlightResult;
48
48
  pendingStructuralRows;
@@ -279,18 +279,21 @@ var DiffHunksRenderer = class {
279
279
  else hastLines[line] = row;
280
280
  }
281
281
  let regionsChanged = false;
282
- if (changedAdditionLines.length > 0) if (this.editSessionActive) if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
283
- this.applyRecomputePreservingSessionType(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
284
- regionsChanged = true;
285
- } else if (shouldTopAlignAdditionRecompute(diff, diff.additionLines)) {
286
- this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, diff.additionLines, this.options.parseDiffOptions));
287
- regionsChanged = true;
288
- } else {
289
- const change = applySessionChangedLines(diff, changedAdditionLines, this.options.parseDiffOptions, previousAdditionLines);
290
- this.applyExpansionRemap(change);
291
- regionsChanged = change != null;
282
+ if (changedAdditionLines.length > 0) {
283
+ if (this.editSessionActive) {
284
+ if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
285
+ this.applyRecomputePreservingSessionType(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
286
+ regionsChanged = true;
287
+ } else if (shouldTopAlignAdditionRecompute(diff, diff.additionLines)) {
288
+ this.applyRecomputePreservingSessionType(diff, recomputeTopAlignedAdditionDiff(diff, diff.additionLines, this.options.parseDiffOptions));
289
+ regionsChanged = true;
290
+ } else {
291
+ const change = applySessionChangedLines(diff, changedAdditionLines, this.options.parseDiffOptions, previousAdditionLines);
292
+ this.applyExpansionRemap(change);
293
+ regionsChanged = change != null;
294
+ }
295
+ } else Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
292
296
  }
293
- else Object.assign(diff, updateDiffHunks(diff, changedAdditionLines, this.options.parseDiffOptions));
294
297
  result.baseThemeType = themeType;
295
298
  renderCache.isDirty = true;
296
299
  return regionsChanged;
@@ -380,7 +383,7 @@ var DiffHunksRenderer = class {
380
383
  };
381
384
  }
382
385
  async initializeHighlighter() {
383
- this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLang, {
386
+ this.highlighter = await getSharedHighlighter(getHighlighterOptions(this.computedLangs, {
384
387
  theme: this.getLocalHighlightTheme(),
385
388
  preferredHighlighter: this.workerManager?.getPreferredHighlighter() ?? this.options.preferredHighlighter
386
389
  }));
@@ -404,7 +407,7 @@ var DiffHunksRenderer = class {
404
407
  if (!this.editSessionActive && this.workerManager?.isWorkingPool() === true) {
405
408
  if (this.renderCache.result == null && !massiveDiff) this.workerManager.highlightDiffAST(this, this.diff);
406
409
  } else if (this.highlighter == null) {
407
- this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);
410
+ this.computedLangs = getDiffLanguages(diff);
408
411
  this.initializeHighlighter();
409
412
  }
410
413
  }
@@ -514,10 +517,10 @@ var DiffHunksRenderer = class {
514
517
  }
515
518
  if (!forcePlainText && hasContent && (!this.renderCache.highlighted || forceHighlight)) this.workerManager.highlightDiffAST(this, diff);
516
519
  } else {
517
- this.computedLang = diff.lang ?? getFiletypeFromFileName(diff.name);
520
+ this.computedLangs = getDiffLanguages(diff);
518
521
  this.highlighter ??= getHighlighterIfLoaded();
519
522
  const hasThemes = this.highlighter != null && areThemesAttached(options.theme);
520
- const hasLangs = this.highlighter != null && areLanguagesAttached(this.computedLang);
523
+ const hasLangs = this.highlighter != null && areLanguagesAttached(this.computedLangs);
521
524
  const canHighlight = !forcePlainText && hasLangs;
522
525
  if (canRenderDiff && this.highlighter != null && hasThemes && (forceHighlight || forcePlainText || !this.renderCache.highlighted && canHighlight || this.renderCache.result == null)) {
523
526
  const { result, options } = this.renderDiffWithHighlighter(diff, this.highlighter, forcePlainText || !hasLangs);
@@ -555,9 +558,9 @@ var DiffHunksRenderer = class {
555
558
  }
556
559
  async asyncHighlight(diff) {
557
560
  const forcePlainText = isDiffMassive(diff, this.getTokenizeMaxLength());
558
- this.computedLang = forcePlainText ? "text" : diff.lang ?? getFiletypeFromFileName(diff.name);
561
+ this.computedLangs = forcePlainText ? ["text"] : getDiffLanguages(diff);
559
562
  const hasThemes = this.highlighter != null && areThemesAttached(this.getLocalHighlightTheme());
560
- const hasLangs = forcePlainText || this.highlighter != null && areLanguagesAttached(this.computedLang);
563
+ const hasLangs = forcePlainText || this.highlighter != null && areLanguagesAttached(this.computedLangs);
561
564
  if (this.highlighter == null || !hasThemes || !hasLangs) this.highlighter = await this.initializeHighlighter();
562
565
  return this.renderDiffWithHighlighter(diff, this.highlighter, forcePlainText);
563
566
  }
@@ -666,9 +669,7 @@ var DiffHunksRenderer = class {
666
669
  case "deletions":
667
670
  context.deletionsGutterAST.children.push(element);
668
671
  break;
669
- case "additions":
670
- context.additionsGutterAST.children.push(element);
671
- break;
672
+ case "additions": context.additionsGutterAST.children.push(element);
672
673
  }
673
674
  }
674
675
  };
@@ -1250,6 +1251,12 @@ function getEditorDocumentLines(textDocument) {
1250
1251
  for (let line = 0; line < textDocument.lineCount; line++) lines.push(textDocument.getLineText(line, true));
1251
1252
  return lines;
1252
1253
  }
1254
+ function getDiffLanguages(diff) {
1255
+ if (diff.lang != null) return [diff.lang];
1256
+ const deletionLang = getFiletypeFromFileName(diff.prevName ?? diff.name);
1257
+ const additionLang = getFiletypeFromFileName(diff.name);
1258
+ return deletionLang === additionLang ? [additionLang] : [deletionLang, additionLang];
1259
+ }
1253
1260
  function isDiffMassive(diff, tokenizeMaxLength) {
1254
1261
  return Math.max(diff.additionLines.length, diff.deletionLines.length) > tokenizeMaxLength;
1255
1262
  }