@pierre/diffs 1.3.6 → 1.4.0

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 (254) hide show
  1. package/dist/components/CodeView.d.ts +113 -68
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +153 -58
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +75 -15
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +223 -62
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +97 -21
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +400 -100
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/UnresolvedFile.d.ts +2 -2
  14. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  15. package/dist/components/UnresolvedFile.js +2 -2
  16. package/dist/components/UnresolvedFile.js.map +1 -1
  17. package/dist/components/VirtualizedFile.d.ts +16 -7
  18. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  19. package/dist/components/VirtualizedFile.js +140 -51
  20. package/dist/components/VirtualizedFile.js.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.d.ts +14 -8
  22. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  23. package/dist/components/VirtualizedFileDiff.js +183 -93
  24. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  25. package/dist/components/VirtulizerDevelopment.d.ts +1 -1
  26. package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
  27. package/dist/edit/index.d.ts +7 -4
  28. package/dist/edit/index.js +5 -1
  29. package/dist/editor/EditStateManager.d.ts +56 -0
  30. package/dist/editor/EditStateManager.d.ts.map +1 -0
  31. package/dist/editor/EditStateManager.js +135 -0
  32. package/dist/editor/EditStateManager.js.map +1 -0
  33. package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts +7 -0
  34. package/dist/editor/cloneRetainedDiffSessionSnapshot.d.ts.map +1 -0
  35. package/dist/editor/cloneRetainedDiffSessionSnapshot.js +16 -0
  36. package/dist/editor/cloneRetainedDiffSessionSnapshot.js.map +1 -0
  37. package/dist/editor/editPrediction.d.ts +76 -0
  38. package/dist/editor/editPrediction.d.ts.map +1 -0
  39. package/dist/editor/editPrediction.js +365 -0
  40. package/dist/editor/editPrediction.js.map +1 -0
  41. package/dist/editor/editStack.d.ts +19 -40
  42. package/dist/editor/editStack.d.ts.map +1 -1
  43. package/dist/editor/editStack.js +67 -4
  44. package/dist/editor/editStack.js.map +1 -1
  45. package/dist/editor/editor.d.ts +118 -29
  46. package/dist/editor/editor.d.ts.map +1 -1
  47. package/dist/editor/editor.js +1103 -383
  48. package/dist/editor/editor.js.map +1 -1
  49. package/dist/editor/editor2.js +1 -1
  50. package/dist/editor/languages.d.ts +3 -3
  51. package/dist/editor/languages.d.ts.map +1 -1
  52. package/dist/editor/languages.js.map +1 -1
  53. package/dist/editor/lineAnnotations.d.ts +3 -3
  54. package/dist/editor/lineAnnotations.d.ts.map +1 -1
  55. package/dist/editor/lineAnnotations.js +16 -7
  56. package/dist/editor/lineAnnotations.js.map +1 -1
  57. package/dist/editor/marker.d.ts +2 -2
  58. package/dist/editor/marker.d.ts.map +1 -1
  59. package/dist/editor/marker.js.map +1 -1
  60. package/dist/editor/matchBrackets.d.ts +2 -2
  61. package/dist/editor/matchBrackets.d.ts.map +1 -1
  62. package/dist/editor/matchBrackets.js.map +1 -1
  63. package/dist/editor/pieceTable.d.ts +1 -1
  64. package/dist/editor/pieceTable.js.map +1 -1
  65. package/dist/editor/searchPanel.d.ts +2 -2
  66. package/dist/editor/searchPanel.js +1 -1
  67. package/dist/editor/searchPanel.js.map +1 -1
  68. package/dist/editor/selection.d.ts +32 -23
  69. package/dist/editor/selection.d.ts.map +1 -1
  70. package/dist/editor/selection.js +3 -3
  71. package/dist/editor/selection.js.map +1 -1
  72. package/dist/editor/selectionAction.d.ts +3 -3
  73. package/dist/editor/selectionAction.d.ts.map +1 -1
  74. package/dist/editor/selectionAction.js.map +1 -1
  75. package/dist/editor/textDocument.d.ts +11 -8
  76. package/dist/editor/textDocument.d.ts.map +1 -1
  77. package/dist/editor/textDocument.js +28 -5
  78. package/dist/editor/textDocument.js.map +1 -1
  79. package/dist/editor/textDocumentChangeTransaction.d.ts +15 -0
  80. package/dist/editor/textDocumentChangeTransaction.d.ts.map +1 -0
  81. package/dist/editor/textDocumentChangeTransaction.js +12 -0
  82. package/dist/editor/textDocumentChangeTransaction.js.map +1 -0
  83. package/dist/editor/textMeasure.d.ts +5 -0
  84. package/dist/editor/textMeasure.d.ts.map +1 -1
  85. package/dist/editor/textMeasure.js +10 -0
  86. package/dist/editor/textMeasure.js.map +1 -1
  87. package/dist/editor/tokenizer.d.ts +1 -1
  88. package/dist/editor/tokenizer.js.map +1 -1
  89. package/dist/editor/types.d.ts +267 -0
  90. package/dist/editor/types.d.ts.map +1 -0
  91. package/dist/editor/types.js +0 -0
  92. package/dist/editor/utils.d.ts +2 -1
  93. package/dist/editor/utils.d.ts.map +1 -1
  94. package/dist/editor/utils.js +4 -1
  95. package/dist/editor/utils.js.map +1 -1
  96. package/dist/index.d.ts +8 -6
  97. package/dist/index.js +9 -8
  98. package/dist/managers/InteractionManager.d.ts.map +1 -1
  99. package/dist/managers/InteractionManager.js +7 -0
  100. package/dist/managers/InteractionManager.js.map +1 -1
  101. package/dist/react/CodeView.d.ts +36 -25
  102. package/dist/react/CodeView.d.ts.map +1 -1
  103. package/dist/react/CodeView.js +15 -14
  104. package/dist/react/CodeView.js.map +1 -1
  105. package/dist/react/EditContext.d.ts +8 -11
  106. package/dist/react/EditContext.d.ts.map +1 -1
  107. package/dist/react/EditContext.js +2 -9
  108. package/dist/react/EditContext.js.map +1 -1
  109. package/dist/react/File.d.ts +10 -6
  110. package/dist/react/File.d.ts.map +1 -1
  111. package/dist/react/File.js +8 -4
  112. package/dist/react/File.js.map +1 -1
  113. package/dist/react/FileDiff.d.ts +10 -5
  114. package/dist/react/FileDiff.d.ts.map +1 -1
  115. package/dist/react/FileDiff.js +8 -4
  116. package/dist/react/FileDiff.js.map +1 -1
  117. package/dist/react/MultiFileDiff.d.ts +8 -5
  118. package/dist/react/MultiFileDiff.d.ts.map +1 -1
  119. package/dist/react/MultiFileDiff.js +8 -12
  120. package/dist/react/MultiFileDiff.js.map +1 -1
  121. package/dist/react/PatchDiff.d.ts +7 -4
  122. package/dist/react/PatchDiff.d.ts.map +1 -1
  123. package/dist/react/PatchDiff.js +8 -4
  124. package/dist/react/PatchDiff.js.map +1 -1
  125. package/dist/react/UnresolvedFile.d.ts +3 -3
  126. package/dist/react/UnresolvedFile.d.ts.map +1 -1
  127. package/dist/react/UnresolvedFile.js.map +1 -1
  128. package/dist/react/index.d.ts +8 -5
  129. package/dist/react/types.d.ts +46 -9
  130. package/dist/react/types.d.ts.map +1 -1
  131. package/dist/react/utils/renderDiffChildren.d.ts +14 -12
  132. package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
  133. package/dist/react/utils/renderDiffChildren.js +2 -2
  134. package/dist/react/utils/renderDiffChildren.js.map +1 -1
  135. package/dist/react/utils/renderFileChildren.d.ts +14 -12
  136. package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
  137. package/dist/react/utils/renderFileChildren.js +2 -2
  138. package/dist/react/utils/renderFileChildren.js.map +1 -1
  139. package/dist/react/utils/useFileDiffInstance.d.ts +22 -10
  140. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  141. package/dist/react/utils/useFileDiffInstance.js +112 -22
  142. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  143. package/dist/react/utils/useFileInstance.d.ts +15 -9
  144. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  145. package/dist/react/utils/useFileInstance.js +84 -25
  146. package/dist/react/utils/useFileInstance.js.map +1 -1
  147. package/dist/renderers/DiffHunksRenderer.d.ts +30 -15
  148. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  149. package/dist/renderers/DiffHunksRenderer.js +172 -108
  150. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  151. package/dist/renderers/FileRenderer.d.ts +27 -11
  152. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  153. package/dist/renderers/FileRenderer.js +138 -64
  154. package/dist/renderers/FileRenderer.js.map +1 -1
  155. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +2 -2
  156. package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
  157. package/dist/renderers/UnresolvedFileHunksRenderer.js +2 -2
  158. package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
  159. package/dist/shiki-stream/tokenizer.d.ts.map +1 -1
  160. package/dist/shiki-stream/tokenizer.js +2 -1
  161. package/dist/shiki-stream/tokenizer.js.map +1 -1
  162. package/dist/ssr/index.d.ts +2 -2
  163. package/dist/ssr/preloadDiffs.d.ts +21 -21
  164. package/dist/ssr/preloadDiffs.d.ts.map +1 -1
  165. package/dist/ssr/preloadDiffs.js +1 -1
  166. package/dist/ssr/preloadDiffs.js.map +1 -1
  167. package/dist/ssr/preloadFile.d.ts +6 -6
  168. package/dist/ssr/preloadFile.d.ts.map +1 -1
  169. package/dist/ssr/preloadFile.js.map +1 -1
  170. package/dist/ssr/preloadPatchFile.d.ts +4 -4
  171. package/dist/ssr/preloadPatchFile.d.ts.map +1 -1
  172. package/dist/ssr/preloadPatchFile.js.map +1 -1
  173. package/dist/style.js +1 -1
  174. package/dist/types.d.ts +13 -263
  175. package/dist/types.d.ts.map +1 -1
  176. package/dist/utils/appendItems.d.ts +5 -0
  177. package/dist/utils/appendItems.d.ts.map +1 -0
  178. package/dist/utils/appendItems.js +8 -0
  179. package/dist/utils/appendItems.js.map +1 -0
  180. package/dist/utils/areDiffTargetsEqual.js +1 -1
  181. package/dist/utils/areDiffTargetsEqual.js.map +1 -1
  182. package/dist/utils/areFileTargetsEqual.d.ts +7 -0
  183. package/dist/utils/areFileTargetsEqual.d.ts.map +1 -0
  184. package/dist/utils/areFileTargetsEqual.js +8 -0
  185. package/dist/utils/areFileTargetsEqual.js.map +1 -0
  186. package/dist/utils/areManagedSnapshotsEqual.d.ts +1 -1
  187. package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
  188. package/dist/utils/areManagedSnapshotsEqual.js.map +1 -1
  189. package/dist/utils/areOptionsEqual.d.ts +3 -3
  190. package/dist/utils/areOptionsEqual.d.ts.map +1 -1
  191. package/dist/utils/areOptionsEqual.js.map +1 -1
  192. package/dist/utils/cloneFileDiffMetadata.d.ts +3 -2
  193. package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -1
  194. package/dist/utils/cloneFileDiffMetadata.js +8 -5
  195. package/dist/utils/cloneFileDiffMetadata.js.map +1 -1
  196. package/dist/utils/composeCacheKey.d.ts +6 -0
  197. package/dist/utils/composeCacheKey.d.ts.map +1 -0
  198. package/dist/utils/composeCacheKey.js +10 -0
  199. package/dist/utils/composeCacheKey.js.map +1 -0
  200. package/dist/utils/editSessionAnnotations.d.ts +69 -0
  201. package/dist/utils/editSessionAnnotations.d.ts.map +1 -0
  202. package/dist/utils/editSessionAnnotations.js +64 -0
  203. package/dist/utils/editSessionAnnotations.js.map +1 -0
  204. package/dist/utils/editSessionHunks.d.ts +5 -3
  205. package/dist/utils/editSessionHunks.d.ts.map +1 -1
  206. package/dist/utils/editSessionHunks.js +7 -5
  207. package/dist/utils/editSessionHunks.js.map +1 -1
  208. package/dist/utils/getDiffHunksRendererOptions.d.ts +1 -1
  209. package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
  210. package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
  211. package/dist/utils/getFileRendererOptions.d.ts +1 -1
  212. package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
  213. package/dist/utils/getFileRendererOptions.js.map +1 -1
  214. package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
  215. package/dist/utils/hydratePartialDiff.js +2 -1
  216. package/dist/utils/hydratePartialDiff.js.map +1 -1
  217. package/dist/utils/lineAnnotationIdentity.d.ts +16 -0
  218. package/dist/utils/lineAnnotationIdentity.d.ts.map +1 -0
  219. package/dist/utils/lineAnnotationIdentity.js +17 -0
  220. package/dist/utils/lineAnnotationIdentity.js.map +1 -0
  221. package/dist/utils/parseDiffFromFile.d.ts +2 -2
  222. package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
  223. package/dist/utils/parseDiffFromFile.js +6 -6
  224. package/dist/utils/parseDiffFromFile.js.map +1 -1
  225. package/dist/utils/parsePatchFiles.d.ts +6 -3
  226. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  227. package/dist/utils/parsePatchFiles.js +34 -9
  228. package/dist/utils/parsePatchFiles.js.map +1 -1
  229. package/dist/utils/renderDiffWithHighlighter.d.ts.map +1 -1
  230. package/dist/utils/renderDiffWithHighlighter.js +6 -5
  231. package/dist/utils/renderDiffWithHighlighter.js.map +1 -1
  232. package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
  233. package/dist/utils/renderFileWithHighlighter.js +7 -4
  234. package/dist/utils/renderFileWithHighlighter.js.map +1 -1
  235. package/dist/utils/trimPatchContext.d.ts.map +1 -1
  236. package/dist/utils/trimPatchContext.js +3 -2
  237. package/dist/utils/trimPatchContext.js.map +1 -1
  238. package/dist/utils/updateDiffHunks.js +1 -1
  239. package/dist/utils/virtualDiffLayout.js +1 -1
  240. package/dist/worker/WorkerPoolManager.d.ts +4 -3
  241. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  242. package/dist/worker/WorkerPoolManager.js +33 -4
  243. package/dist/worker/WorkerPoolManager.js.map +1 -1
  244. package/dist/worker/types.d.ts +5 -0
  245. package/dist/worker/types.d.ts.map +1 -1
  246. package/dist/worker/worker-portable.js +14 -6
  247. package/dist/worker/worker-portable.js.map +1 -1
  248. package/dist/worker/worker.js +14 -6
  249. package/dist/worker/worker.js.map +1 -1
  250. package/package.json +9 -1
  251. package/dist/editor/stateStorage.d.ts +0 -15
  252. package/dist/editor/stateStorage.d.ts.map +0 -1
  253. package/dist/editor/stateStorage.js +0 -65
  254. package/dist/editor/stateStorage.js.map +0 -1
@@ -1,21 +1,22 @@
1
- import { FileContents } from "../../types.js";
1
+ import { FileContents, LineAnnotation } from "../../types.js";
2
2
  import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
3
  import { FileProps } from "../types.js";
4
4
  import { ReactNode } from "react";
5
5
 
6
6
  //#region src/react/utils/renderFileChildren.d.ts
7
- interface RenderFileChildrenProps<LAnnotation> {
7
+ interface RenderFileChildrenProps<LAnnotation, Caret> {
8
8
  file: FileContents;
9
- renderCustomHeader: FileProps<LAnnotation>['renderCustomHeader'];
10
- renderHeaderPrefix: FileProps<LAnnotation>['renderHeaderPrefix'];
11
- renderHeaderFilenameSuffix?: FileProps<LAnnotation>['renderHeaderFilenameSuffix'];
12
- renderHeaderMetadata: FileProps<LAnnotation>['renderHeaderMetadata'];
13
- renderAnnotation: FileProps<LAnnotation>['renderAnnotation'];
14
- lineAnnotations: FileProps<LAnnotation>['lineAnnotations'];
15
- renderGutterUtility: FileProps<LAnnotation>['renderGutterUtility'];
9
+ renderCustomHeader: FileProps<LAnnotation, Caret>['renderCustomHeader'];
10
+ renderHeaderPrefix: FileProps<LAnnotation, Caret>['renderHeaderPrefix'];
11
+ renderHeaderFilenameSuffix?: FileProps<LAnnotation, Caret>['renderHeaderFilenameSuffix'];
12
+ renderHeaderMetadata: FileProps<LAnnotation, Caret>['renderHeaderMetadata'];
13
+ renderAnnotation: FileProps<LAnnotation, Caret>['renderAnnotation'];
14
+ lineAnnotations: FileProps<LAnnotation, Caret>['lineAnnotations'];
15
+ renderGutterUtility: FileProps<LAnnotation, Caret>['renderGutterUtility'];
16
16
  getHoveredLine(): GetHoveredLineResult<'file'> | undefined;
17
+ getAnnotationSlotName?(annotation: LineAnnotation<LAnnotation>): string;
17
18
  }
18
- declare function renderFileChildren<LAnnotation>({
19
+ declare function renderFileChildren<LAnnotation, Caret>({
19
20
  file,
20
21
  renderCustomHeader,
21
22
  renderHeaderPrefix,
@@ -24,8 +25,9 @@ declare function renderFileChildren<LAnnotation>({
24
25
  renderAnnotation,
25
26
  lineAnnotations,
26
27
  renderGutterUtility,
27
- getHoveredLine
28
- }: RenderFileChildrenProps<LAnnotation>): ReactNode;
28
+ getHoveredLine,
29
+ getAnnotationSlotName
30
+ }: RenderFileChildrenProps<LAnnotation, Caret>): ReactNode;
29
31
  //#endregion
30
32
  export { renderFileChildren };
31
33
  //# sourceMappingURL=renderFileChildren.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderFileChildren.d.ts","names":[],"sources":["../../../src/react/utils/renderFileChildren.tsx"],"mappings":";;;;;;UAcU,uBAAA;EACR,IAAA,EAAM,YAAA;EACN,kBAAA,EAAoB,SAAA,CAAU,WAAA;EAC9B,kBAAA,EAAoB,SAAA,CAAU,WAAA;EAC9B,0BAAA,GAA6B,SAAA,CAAU,WAAA;EACvC,oBAAA,EAAsB,SAAA,CAAU,WAAA;EAChC,gBAAA,EAAkB,SAAA,CAAU,WAAA;EAC5B,eAAA,EAAiB,SAAA,CAAU,WAAA;EAC3B,mBAAA,EAAqB,SAAA,CAAU,WAAA;EAC/B,cAAA,IAAkB,oBAAA;AAAA;AAAA,iBAGJ,kBAAA;EACd,IAAA;EACA,kBAAA;EACA,kBAAA;EACA,0BAAA;EACA,oBAAA;EACA,gBAAA;EACA,eAAA;EACA,mBAAA;EACA;AAAA,GACC,uBAAA,CAAwB,WAAA,IAAe,SAAA"}
1
+ {"version":3,"file":"renderFileChildren.d.ts","names":[],"sources":["../../../src/react/utils/renderFileChildren.tsx"],"mappings":";;;;;;UAcU,uBAAA;EACR,IAAA,EAAM,YAAA;EACN,kBAAA,EAAoB,SAAA,CAAU,WAAA,EAAa,KAAA;EAC3C,kBAAA,EAAoB,SAAA,CAAU,WAAA,EAAa,KAAA;EAC3C,0BAAA,GAA6B,SAAA,CAC3B,WAAA,EACA,KAAA;EAEF,oBAAA,EAAsB,SAAA,CAAU,WAAA,EAAa,KAAA;EAC7C,gBAAA,EAAkB,SAAA,CAAU,WAAA,EAAa,KAAA;EACzC,eAAA,EAAiB,SAAA,CAAU,WAAA,EAAa,KAAA;EACxC,mBAAA,EAAqB,SAAA,CAAU,WAAA,EAAa,KAAA;EAC5C,cAAA,IAAkB,oBAAA;EAClB,qBAAA,EAAuB,UAAA,EAAY,cAAA,CAAe,WAAA;AAAA;AAAA,iBAGpC,kBAAA;EACd,IAAA;EACA,kBAAA;EACA,kBAAA;EACA,0BAAA;EACA,oBAAA;EACA,gBAAA;EACA,eAAA;EACA,mBAAA;EACA,cAAA;EACA;AAAA,GACC,uBAAA,CAAwB,WAAA,EAAa,KAAA,IAAS,SAAA"}
@@ -3,7 +3,7 @@ import { getLineAnnotationName } from "../../utils/getLineAnnotationName.js";
3
3
  import { GutterUtilitySlotStyles } from "../constants.js";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  //#region src/react/utils/renderFileChildren.tsx
6
- function renderFileChildren({ file, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderAnnotation, lineAnnotations, renderGutterUtility, getHoveredLine }) {
6
+ function renderFileChildren({ file, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderAnnotation, lineAnnotations, renderGutterUtility, getHoveredLine, getAnnotationSlotName = getLineAnnotationName }) {
7
7
  const customHeader = renderCustomHeader?.(file);
8
8
  const prefix = renderHeaderPrefix?.(file);
9
9
  const suffix = renderHeaderFilenameSuffix?.(file);
@@ -27,7 +27,7 @@ function renderFileChildren({ file, renderCustomHeader, renderHeaderPrefix, rend
27
27
  })
28
28
  ] }),
29
29
  renderAnnotation != null && lineAnnotations?.map((annotation, index) => /* @__PURE__ */ jsx("div", {
30
- slot: getLineAnnotationName(annotation),
30
+ slot: getAnnotationSlotName(annotation),
31
31
  children: renderAnnotation(annotation)
32
32
  }, index)),
33
33
  renderGutterUtility != null && /* @__PURE__ */ jsx("div", {
@@ -1 +1 @@
1
- {"version":3,"file":"renderFileChildren.js","names":[],"sources":["../../../src/react/utils/renderFileChildren.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport {\n CUSTOM_HEADER_SLOT_ID,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n HEADER_METADATA_SLOT_ID,\n HEADER_PREFIX_SLOT_ID,\n} from '../../constants';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { FileContents } from '../../types';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { GutterUtilitySlotStyles } from '../constants';\nimport type { FileProps } from '../types';\n\ninterface RenderFileChildrenProps<LAnnotation> {\n file: FileContents;\n renderCustomHeader: FileProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: FileProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix?: FileProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: FileProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: FileProps<LAnnotation>['renderAnnotation'];\n lineAnnotations: FileProps<LAnnotation>['lineAnnotations'];\n renderGutterUtility: FileProps<LAnnotation>['renderGutterUtility'];\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function renderFileChildren<LAnnotation>({\n file,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n}: RenderFileChildrenProps<LAnnotation>): ReactNode {\n const customHeader = renderCustomHeader?.(file);\n const prefix = renderHeaderPrefix?.(file);\n const suffix = renderHeaderFilenameSuffix?.(file);\n const metadata = renderHeaderMetadata?.(file);\n return (\n <>\n {customHeader != null ? (\n <div slot={CUSTOM_HEADER_SLOT_ID}>{customHeader}</div>\n ) : (\n <>\n {prefix != null && <div slot={HEADER_PREFIX_SLOT_ID}>{prefix}</div>}\n {suffix != null && (\n <div slot={HEADER_FILENAME_SUFFIX_SLOT_ID}>{suffix}</div>\n )}\n {metadata != null && (\n <div slot={HEADER_METADATA_SLOT_ID}>{metadata}</div>\n )}\n </>\n )}\n {renderAnnotation != null &&\n lineAnnotations?.map((annotation, index) => (\n <div key={index} slot={getLineAnnotationName(annotation)}>\n {renderAnnotation(annotation)}\n </div>\n ))}\n {renderGutterUtility != null && (\n <div slot=\"gutter-utility-slot\" style={GutterUtilitySlotStyles}>\n {renderGutterUtility(getHoveredLine)}\n </div>\n )}\n </>\n );\n}\n"],"mappings":";;;;;AA0BA,SAAgB,mBAAgC,EAC9C,MACA,oBACA,oBACA,4BACA,sBACA,kBACA,iBACA,qBACA,kBACkD;CAClD,MAAM,eAAe,qBAAqB,IAAI;CAC9C,MAAM,SAAS,qBAAqB,IAAI;CACxC,MAAM,SAAS,6BAA6B,IAAI;CAChD,MAAM,WAAW,uBAAuB,IAAI;CAC5C,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,gBAAgB,OACf,oBAAC,OAAD;GAAK,MAAM;aAAwB;EAAkB,CAAA,IAErD,qBAAA,UAAA,EAAA,UAAA;GACG,UAAU,QAAQ,oBAAC,OAAD;IAAK,MAAA;cAA8B;GAAY,CAAA;GACjE,UAAU,QACT,oBAAC,OAAD;IAAK,MAAA;cAAuC;GAAY,CAAA;GAEzD,YAAY,QACX,oBAAC,OAAD;IAAK,MAAA;cAAgC;GAAc,CAAA;EAErD,EAAA,CAAA;EAEH,oBAAoB,QACnB,iBAAiB,KAAK,YAAY,UAChC,oBAAC,OAAD;GAAiB,MAAM,sBAAsB,UAAU;aACpD,iBAAiB,UAAU;EACzB,GAFK,KAEL,CACN;EACF,uBAAuB,QACtB,oBAAC,OAAD;GAAK,MAAK;GAAsB,OAAO;aACpC,oBAAoB,cAAc;EAChC,CAAA;CAEP,EAAA,CAAA;AAEN"}
1
+ {"version":3,"file":"renderFileChildren.js","names":[],"sources":["../../../src/react/utils/renderFileChildren.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport {\n CUSTOM_HEADER_SLOT_ID,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n HEADER_METADATA_SLOT_ID,\n HEADER_PREFIX_SLOT_ID,\n} from '../../constants';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { FileContents, LineAnnotation } from '../../types';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { GutterUtilitySlotStyles } from '../constants';\nimport type { FileProps } from '../types';\n\ninterface RenderFileChildrenProps<LAnnotation, Caret> {\n file: FileContents;\n renderCustomHeader: FileProps<LAnnotation, Caret>['renderCustomHeader'];\n renderHeaderPrefix: FileProps<LAnnotation, Caret>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix?: FileProps<\n LAnnotation,\n Caret\n >['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: FileProps<LAnnotation, Caret>['renderHeaderMetadata'];\n renderAnnotation: FileProps<LAnnotation, Caret>['renderAnnotation'];\n lineAnnotations: FileProps<LAnnotation, Caret>['lineAnnotations'];\n renderGutterUtility: FileProps<LAnnotation, Caret>['renderGutterUtility'];\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n getAnnotationSlotName?(annotation: LineAnnotation<LAnnotation>): string;\n}\n\nexport function renderFileChildren<LAnnotation, Caret>({\n file,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n getAnnotationSlotName = getLineAnnotationName,\n}: RenderFileChildrenProps<LAnnotation, Caret>): ReactNode {\n const customHeader = renderCustomHeader?.(file);\n const prefix = renderHeaderPrefix?.(file);\n const suffix = renderHeaderFilenameSuffix?.(file);\n const metadata = renderHeaderMetadata?.(file);\n return (\n <>\n {customHeader != null ? (\n <div slot={CUSTOM_HEADER_SLOT_ID}>{customHeader}</div>\n ) : (\n <>\n {prefix != null && <div slot={HEADER_PREFIX_SLOT_ID}>{prefix}</div>}\n {suffix != null && (\n <div slot={HEADER_FILENAME_SUFFIX_SLOT_ID}>{suffix}</div>\n )}\n {metadata != null && (\n <div slot={HEADER_METADATA_SLOT_ID}>{metadata}</div>\n )}\n </>\n )}\n {renderAnnotation != null &&\n lineAnnotations?.map((annotation, index) => (\n <div key={index} slot={getAnnotationSlotName(annotation)}>\n {renderAnnotation(annotation)}\n </div>\n ))}\n {renderGutterUtility != null && (\n <div slot=\"gutter-utility-slot\" style={GutterUtilitySlotStyles}>\n {renderGutterUtility(getHoveredLine)}\n </div>\n )}\n </>\n );\n}\n"],"mappings":";;;;;AA8BA,SAAgB,mBAAuC,EACrD,MACA,oBACA,oBACA,4BACA,sBACA,kBACA,iBACA,qBACA,gBACA,wBAAwB,yBACiC;CACzD,MAAM,eAAe,qBAAqB,IAAI;CAC9C,MAAM,SAAS,qBAAqB,IAAI;CACxC,MAAM,SAAS,6BAA6B,IAAI;CAChD,MAAM,WAAW,uBAAuB,IAAI;CAC5C,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,gBAAgB,OACf,oBAAC,OAAD;GAAK,MAAM;aAAwB;EAAkB,CAAA,IAErD,qBAAA,UAAA,EAAA,UAAA;GACG,UAAU,QAAQ,oBAAC,OAAD;IAAK,MAAA;cAA8B;GAAY,CAAA;GACjE,UAAU,QACT,oBAAC,OAAD;IAAK,MAAA;cAAuC;GAAY,CAAA;GAEzD,YAAY,QACX,oBAAC,OAAD;IAAK,MAAA;cAAgC;GAAc,CAAA;EAErD,EAAA,CAAA;EAEH,oBAAoB,QACnB,iBAAiB,KAAK,YAAY,UAChC,oBAAC,OAAD;GAAiB,MAAM,sBAAsB,UAAU;aACpD,iBAAiB,UAAU;EACzB,GAFK,KAEL,CACN;EACF,uBAAuB,QACtB,oBAAC,OAAD;GAAK,MAAK;GAAsB,OAAO;aACpC,oBAAoB,cAAc;EAChC,CAAA;CAEP,EAAA,CAAA;AAEN"}
@@ -1,12 +1,15 @@
1
- import { DiffLineAnnotation, FileDiffMetadata, SelectedLineRange, VirtualFileMetrics } from "../../types.js";
1
+ import { DiffLineAnnotation, FileContents, FileDiffMetadata, SelectedLineRange, VirtualFileMetrics } from "../../types.js";
2
2
  import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
- import { FileDiffOptions } from "../../components/FileDiff.js";
3
+ import { FileDiffEditChangeHandler, FileDiffEditCompleteHandler, FileDiffOptions } from "../../components/FileDiff.js";
4
4
  import { EditorOptions } from "../../editor/editor.js";
5
5
  //#region src/react/utils/useFileDiffInstance.d.ts
6
- interface UseFileDiffInstanceProps<LAnnotation> {
7
- fileDiff: FileDiffMetadata;
8
- options: FileDiffOptions<LAnnotation> | undefined;
9
- editorOptions: EditorOptions<LAnnotation> | undefined;
6
+ interface UseFileDiffInstanceProps<LAnnotation, Caret> {
7
+ fileDiff?: FileDiffMetadata;
8
+ oldFile?: FileContents | null;
9
+ newFile?: FileContents | null;
10
+ options: FileDiffOptions<LAnnotation, Caret> | undefined;
11
+ editorOptions: EditorOptions<'file-diff', LAnnotation, Caret> | undefined;
12
+ editStateKey: string | undefined;
10
13
  lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;
11
14
  selectedLines: SelectedLineRange | null | undefined;
12
15
  prerenderedHTML: string | undefined;
@@ -15,15 +18,22 @@ interface UseFileDiffInstanceProps<LAnnotation> {
15
18
  hasCustomHeader: boolean;
16
19
  disableWorkerPool: boolean;
17
20
  edit: boolean;
21
+ onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;
22
+ onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;
18
23
  }
19
- interface UseFileDiffInstanceReturn {
24
+ interface UseFileDiffInstanceReturn<LAnnotation> {
25
+ fileDiff: FileDiffMetadata;
20
26
  ref(node: HTMLElement | null): void;
21
27
  getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;
28
+ getAnnotationSlotName(annotation: DiffLineAnnotation<LAnnotation>): string;
22
29
  }
23
- declare function useFileDiffInstance<LAnnotation>({
30
+ declare function useFileDiffInstance<LAnnotation, Caret>({
24
31
  fileDiff,
32
+ oldFile,
33
+ newFile,
25
34
  options,
26
35
  editorOptions,
36
+ editStateKey,
27
37
  lineAnnotations,
28
38
  selectedLines,
29
39
  prerenderedHTML,
@@ -31,8 +41,10 @@ declare function useFileDiffInstance<LAnnotation>({
31
41
  hasGutterRenderUtility,
32
42
  hasCustomHeader,
33
43
  disableWorkerPool,
34
- edit
35
- }: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn;
44
+ edit,
45
+ onEditChange: _onEditChange,
46
+ onEditComplete: _onEditComplete
47
+ }: UseFileDiffInstanceProps<LAnnotation, Caret>): UseFileDiffInstanceReturn<LAnnotation>;
36
48
  //#endregion
37
49
  export { useFileDiffInstance };
38
50
  //# sourceMappingURL=useFileDiffInstance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFileDiffInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"mappings":";;;;;UA4BU,wBAAA;EACR,QAAA,EAAU,gBAAA;EACV,OAAA,EAAS,eAAA,CAAgB,WAAA;EACzB,aAAA,EAAe,aAAA,CAAc,WAAA;EAC7B,eAAA,EAAiB,kBAAA,CAAmB,WAAA;EACpC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,IAAA;AAAA;AAAA,UAGQ,yBAAA;EACR,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAoB;AAAA;AAAA,iBAGxB,mBAAA;EACd,QAAA;EACA,OAAA;EACA,aAAA;EACA,eAAA;EACA,aAAA;EACA,eAAA;EACA,OAAA;EACA,sBAAA;EACA,eAAA;EACA,iBAAA;EACA;AAAA,GACC,wBAAA,CAAyB,WAAA,IAAe,yBAAA"}
1
+ {"version":3,"file":"useFileDiffInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"mappings":";;;;;UA8DU,wBAAA;EACR,QAAA,GAAW,gBAAA;EACX,OAAA,GAAU,YAAA;EACV,OAAA,GAAU,YAAA;EACV,OAAA,EAAS,eAAA,CAAgB,WAAA,EAAa,KAAA;EACtC,aAAA,EAAe,aAAA,cAA2B,WAAA,EAAa,KAAA;EACvD,YAAA;EACA,eAAA,EAAiB,kBAAA,CAAmB,WAAA;EACpC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,IAAA;EACA,YAAA,GAAe,yBAAA,CAA0B,WAAA,EAAa,KAAA;EACtD,cAAA,GAAiB,2BAAA,CAA4B,WAAA,EAAa,KAAA;AAAA;AAAA,UAGlD,yBAAA;EACR,QAAA,EAAU,gBAAA;EACV,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAA;EAClB,qBAAA,CAAsB,UAAA,EAAY,kBAAA,CAAmB,WAAA;AAAA;AAAA,iBAGvC,mBAAA;EACd,QAAA;EACA,OAAA;EACA,OAAA;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,wBAAA,CACD,WAAA,EACA,KAAA,IACE,yBAAA,CAA0B,WAAA"}
@@ -1,4 +1,8 @@
1
1
  import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
2
+ import { areFileTargetsEqual } from "../../utils/areFileTargetsEqual.js";
3
+ import { getLineAnnotationName } from "../../utils/getLineAnnotationName.js";
4
+ import { areDiffTargetsEqual } from "../../utils/areDiffTargetsEqual.js";
5
+ import { parseDiffFromFile } from "../../utils/parseDiffFromFile.js";
2
6
  import { FileDiff } from "../../components/FileDiff.js";
3
7
  import { VirtualizedFileDiff } from "../../components/VirtualizedFileDiff.js";
4
8
  import { useStableCallback } from "./useStableCallback.js";
@@ -6,15 +10,64 @@ import { useCreateEditor } from "../EditContext.js";
6
10
  import { noopRender } from "../constants.js";
7
11
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
8
12
  import { useVirtualizer } from "../Virtualizer.js";
9
- import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
13
+ import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef } from "react";
10
14
  //#region src/react/utils/useFileDiffInstance.ts
11
15
  const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
12
- function useFileDiffInstance({ fileDiff, options, editorOptions, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, edit }) {
16
+ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOptions, editStateKey, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, edit, onEditChange: _onEditChange, onEditComplete: _onEditComplete }) {
13
17
  const simpleVirtualizer = useVirtualizer();
14
18
  const controlledSelection = selectedLines !== void 0;
15
19
  const poolManager = useContext(WorkerPoolContext);
16
20
  const createEditor = useCreateEditor();
21
+ const handleOnEditChange = useStableCallback((event) => _onEditChange?.(event));
22
+ const onEditChange = _onEditChange != null ? handleOnEditChange : void 0;
23
+ const acceptedCache = useRef(null);
24
+ const handleOnEditComplete = useStableCallback((event) => {
25
+ const decision = _onEditComplete?.(event) ?? "reject";
26
+ if (decision === "accept") acceptedCache.current = {
27
+ fileDiff: {
28
+ installed: event.fileDiff,
29
+ stale: event.originalFileDiff
30
+ },
31
+ filePair: fileDiff == null ? {
32
+ fileDiff: event.fileDiff,
33
+ installed: {
34
+ oldFile: event.oldFile,
35
+ newFile: event.newFile
36
+ },
37
+ stale: {
38
+ oldFile: oldFile ?? null,
39
+ newFile: newFile ?? null
40
+ }
41
+ } : null,
42
+ annotations: {
43
+ installed: event.lineAnnotations,
44
+ stale: event.originalLineAnnotations
45
+ }
46
+ };
47
+ return decision;
48
+ });
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
+ }, [
60
+ fileDiff,
61
+ oldFile,
62
+ newFile,
63
+ options?.parseDiffOptions
64
+ ]);
17
65
  const instanceRef = useRef(null);
66
+ const disposeEditorRef = useRef(null);
67
+ const getEditor = useStableCallback(() => {
68
+ if (createEditor == null) throw new Error("FileDiff: EditContext is not attached");
69
+ return createEditor("file-diff", editorOptions ?? {}, editStateKey);
70
+ });
18
71
  const ref = useStableCallback((fileContainer) => {
19
72
  if (fileContainer != null) {
20
73
  if (instanceRef.current != null) throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");
@@ -22,16 +75,21 @@ function useFileDiffInstance({ fileDiff, options, editorOptions, lineAnnotations
22
75
  controlledSelection,
23
76
  hasCustomHeader,
24
77
  hasGutterRenderUtility,
78
+ onEditChange,
79
+ onEditComplete,
25
80
  options
26
81
  }), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
27
82
  else instanceRef.current = new FileDiff(mergeFileDiffOptions({
28
83
  controlledSelection,
29
84
  hasCustomHeader,
30
85
  hasGutterRenderUtility,
86
+ onEditChange,
87
+ onEditComplete,
31
88
  options
32
89
  }), !disableWorkerPool ? poolManager : void 0, true);
90
+ if (edit && disposeEditorRef.current == null) disposeEditorRef.current = applyEdit(instanceRef.current, getEditor);
33
91
  instanceRef.current.hydrate({
34
- fileDiff,
92
+ fileDiff: effectiveFileDiff,
35
93
  fileContainer,
36
94
  lineAnnotations,
37
95
  prerenderedHTML
@@ -40,6 +98,7 @@ function useFileDiffInstance({ fileDiff, options, editorOptions, lineAnnotations
40
98
  if (instanceRef.current == null) throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");
41
99
  instanceRef.current.cleanUp();
42
100
  instanceRef.current = null;
101
+ disposeEditorRef.current = null;
43
102
  }
44
103
  });
45
104
  useIsomorphicLayoutEffect(() => {
@@ -49,46 +108,77 @@ function useFileDiffInstance({ fileDiff, options, editorOptions, lineAnnotations
49
108
  controlledSelection,
50
109
  hasCustomHeader,
51
110
  hasGutterRenderUtility,
111
+ onEditChange,
112
+ onEditComplete,
52
113
  options
53
114
  });
54
115
  const forceRender = newOptions !== void 0 && !areOptionsEqual(instance.options, newOptions);
55
116
  instance.setOptions(newOptions);
117
+ if (!edit && disposeEditorRef.current != null) {
118
+ const { current: disposeEditor } = disposeEditorRef;
119
+ disposeEditorRef.current = null;
120
+ disposeEditor();
121
+ }
122
+ const resolved = resolveAcceptedValues(effectiveFileDiff, lineAnnotations, acceptedCache);
56
123
  instance.render({
57
124
  forceRender,
58
- fileDiff,
59
- lineAnnotations
125
+ fileDiff: resolved.fileDiff,
126
+ lineAnnotations: resolved.lineAnnotations
60
127
  });
61
128
  if (selectedLines !== void 0) instance.setSelectedLines(selectedLines);
129
+ if (edit && disposeEditorRef.current == null) disposeEditorRef.current = applyEdit(instance, getEditor);
62
130
  });
63
- useIsomorphicLayoutEffect(() => {
64
- if (edit && instanceRef.current != null) {
65
- if (createEditor === void 0) throw new Error("FileDiff: EditContext is not attached");
66
- const editor = createEditor(editorOptions ?? {});
67
- if (editor == null) throw new Error("FileDiff: EditProvider.createEditor must return an editor instance");
68
- try {
69
- return editor.edit(instanceRef.current);
70
- } catch (error) {
71
- editor.cleanUp();
72
- throw error;
73
- }
74
- }
75
- }, [edit]);
76
131
  return {
132
+ fileDiff: effectiveFileDiff,
77
133
  ref,
78
134
  getHoveredLine: useCallback(() => {
79
135
  return instanceRef.current?.getHoveredLine();
80
- }, [])
136
+ }, []),
137
+ getAnnotationSlotName: useCallback((annotation) => instanceRef.current?.getAnnotationSlotName(annotation) ?? getLineAnnotationName(annotation), [])
81
138
  };
82
139
  }
83
- function mergeFileDiffOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility }) {
84
- if (!(controlledSelection || hasGutterRenderUtility || hasCustomHeader)) return options;
140
+ function isSameFilePair(oldFile, newFile, filePair) {
141
+ return areFileTargetsEqual(oldFile ?? void 0, filePair.oldFile ?? void 0) && areFileTargetsEqual(newFile ?? void 0, filePair.newFile ?? void 0);
142
+ }
143
+ function resolveAcceptedValues(fileDiff, lineAnnotations, acceptedCache) {
144
+ const { current: accepted } = acceptedCache;
145
+ if (accepted == null) return {
146
+ fileDiff,
147
+ lineAnnotations
148
+ };
149
+ const { fileDiff: acceptedDiff, annotations: acceptedAnnotations } = accepted;
150
+ let resolvedFileDiff = fileDiff;
151
+ if (acceptedDiff != null) if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) resolvedFileDiff = acceptedDiff.installed;
152
+ else accepted.fileDiff = null;
153
+ let resolvedAnnotations = lineAnnotations;
154
+ if (acceptedAnnotations != null) if (lineAnnotations === acceptedAnnotations.stale) resolvedAnnotations = acceptedAnnotations.installed;
155
+ else accepted.annotations = null;
156
+ if (accepted.fileDiff == null && accepted.annotations == null && accepted.filePair == null) acceptedCache.current = null;
157
+ return {
158
+ fileDiff: resolvedFileDiff,
159
+ lineAnnotations: resolvedAnnotations
160
+ };
161
+ }
162
+ function mergeFileDiffOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility, onEditChange, onEditComplete }) {
163
+ if (!(controlledSelection || hasGutterRenderUtility || hasCustomHeader || onEditChange != null || onEditComplete != null)) return options;
85
164
  return {
86
165
  ...options,
87
166
  controlledSelection,
88
167
  renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
89
- renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
168
+ renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility,
169
+ onEditChange,
170
+ onEditComplete
90
171
  };
91
172
  }
173
+ function applyEdit(instance, getEditor) {
174
+ const editor = getEditor();
175
+ try {
176
+ return editor.edit(instance);
177
+ } catch (error) {
178
+ editor.cleanUp();
179
+ throw error;
180
+ }
181
+ }
92
182
  //#endregion
93
183
  export { useFileDiffInstance };
94
184
 
@@ -1 +1 @@
1
- {"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { FileDiff, type FileDiffOptions } from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\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 UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n editorOptions: EditorOptions<LAnnotation> | 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}\n\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\n\nexport function useFileDiffInstance<LAnnotation>({\n fileDiff,\n options,\n editorOptions,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation>();\n const instanceRef = useRef<\n FileDiff<LAnnotation> | VirtualizedFileDiff<LAnnotation> | null\n >(null);\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 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 options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n fileDiff,\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 }\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 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 void instance.render({\n forceRender,\n fileDiff,\n lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (edit && instanceRef.current != null) {\n if (createEditor === undefined) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n const editor = createEditor(editorOptions ?? {});\n if (editor == null) {\n throw new Error(\n 'FileDiff: EditProvider.createEditor must return an editor instance'\n );\n }\n try {\n return editor.edit(instanceRef.current);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n }\n return undefined;\n }, [edit]);\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return {\n ref,\n getHoveredLine,\n };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n options: FileDiffOptions<LAnnotation> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeFileDiffOptionsProps<LAnnotation>):\n | FileDiffOptions<LAnnotation>\n | undefined {\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\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 };\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAqB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,eACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,QACmE;CACnE,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAA6B;CAClD,MAAM,cAAc,OAElB,IAAI;CACN,MAAM,MAAM,mBAAmB,kBAAsC;EACnE,IAAI,iBAAiB,MAAM;GACzB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,kFACF;GAEF,IAAI,qBAAqB,MACvB,YAAY,UAAU,IAAI,oBACxB,qBAAqB;IACnB;IACA;IACA;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,SACxB,qBAAqB;IACnB;IACA;IACA;IACA;GACF,CAAC,GACD,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;GAEF,YAAiB,QAAQ,QAAQ;IAC/B;IACA;IACA;IACA;GACF,CAAC;EACH,OAAO;GACL,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,uEACF;GAEF,YAAY,QAAQ,QAAQ;GAC5B,YAAY,UAAU;EACxB;CACF,CAAC;CAED,gCAAgC;EAC9B,MAAM,EAAE,SAAS,aAAa;EAC9B,IAAI,YAAY,MAAM;EACtB,MAAM,aAAa,qBAAqB;GACtC;GACA;GACA;GACA;EACF,CAAC;EAID,MAAM,cACJ,eAAe,KAAA,KACf,CAAC,gBAAgB,SAAS,SAAS,UAAU;EAC/C,SAAS,WAAW,UAAU;EAC9B,SAAc,OAAO;GACnB;GACA;GACA;EACF,CAAC;EACD,IAAI,kBAAkB,KAAA,GACpB,SAAS,iBAAiB,aAAa;CAE3C,CAAC;CAED,gCAAgC;EAC9B,IAAI,QAAQ,YAAY,WAAW,MAAM;GACvC,IAAI,iBAAiB,KAAA,GACnB,MAAM,IAAI,MAAM,uCAAuC;GAEzD,MAAM,SAAS,aAAa,iBAAiB,CAAC,CAAC;GAC/C,IAAI,UAAU,MACZ,MAAM,IAAI,MACR,oEACF;GAEF,IAAI;IACF,OAAO,OAAO,KAAK,YAAY,OAAO;GACxC,SAAS,OAAO;IACd,OAAO,QAAQ;IACf,MAAM;GACR;EACF;CAEF,GAAG,CAAC,IAAI,CAAC;CAQT,OAAO;EACL;EACA,gBARqB,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CAIW;CACf;AACF;AASA,SAAS,qBAAkC,EACzC,SACA,qBACA,iBACA,0BAGY;CAIZ,IAAI,EAFF,uBAAuB,0BAA0B,kBAGjD,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;CACf;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 = 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":"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"}
@@ -1,12 +1,13 @@
1
1
  import { FileContents, LineAnnotation, SelectedLineRange, VirtualFileMetrics } from "../../types.js";
2
2
  import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
- import { FileOptions } from "../../components/File.js";
3
+ import { FileEditChangeHandler, FileEditCompleteHandler, FileOptions } from "../../components/File.js";
4
4
  import { EditorOptions } from "../../editor/editor.js";
5
5
  //#region src/react/utils/useFileInstance.d.ts
6
- interface UseFileInstanceProps<LAnnotation> {
6
+ interface UseFileInstanceProps<LAnnotation, Caret> {
7
7
  file: FileContents;
8
- options: FileOptions<LAnnotation> | undefined;
9
- editorOptions: EditorOptions<LAnnotation> | undefined;
8
+ options: FileOptions<LAnnotation, Caret> | undefined;
9
+ editorOptions: EditorOptions<'file', LAnnotation, Caret> | undefined;
10
+ editStateKey: string | undefined;
10
11
  lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;
11
12
  selectedLines: SelectedLineRange | null | undefined;
12
13
  prerenderedHTML: string | undefined;
@@ -15,16 +16,19 @@ interface UseFileInstanceProps<LAnnotation> {
15
16
  hasCustomHeader: boolean;
16
17
  disableWorkerPool: boolean;
17
18
  edit: boolean;
18
- onChange?: (file: FileContents, lineAnnotations?: LineAnnotation<LAnnotation>[]) => void;
19
+ onEditChange?: FileEditChangeHandler<LAnnotation, Caret>;
20
+ onEditComplete?: FileEditCompleteHandler<LAnnotation, Caret>;
19
21
  }
20
- interface UseFileInstanceReturn {
22
+ interface UseFileInstanceReturn<LAnnotation> {
21
23
  ref(node: HTMLElement | null): void;
22
24
  getHoveredLine(): GetHoveredLineResult<'file'> | undefined;
25
+ getAnnotationSlotName(annotation: LineAnnotation<LAnnotation>): string;
23
26
  }
24
- declare function useFileInstance<LAnnotation>({
27
+ declare function useFileInstance<LAnnotation, Caret>({
25
28
  file,
26
29
  options,
27
30
  editorOptions,
31
+ editStateKey,
28
32
  lineAnnotations,
29
33
  selectedLines,
30
34
  prerenderedHTML,
@@ -32,8 +36,10 @@ declare function useFileInstance<LAnnotation>({
32
36
  hasGutterRenderUtility,
33
37
  hasCustomHeader,
34
38
  disableWorkerPool,
35
- edit
36
- }: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn;
39
+ edit,
40
+ onEditChange: _onEditChange,
41
+ onEditComplete: _onEditComplete
42
+ }: UseFileInstanceProps<LAnnotation, Caret>): UseFileInstanceReturn<LAnnotation>;
37
43
  //#endregion
38
44
  export { useFileInstance };
39
45
  //# sourceMappingURL=useFileInstance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;UA4BU,oBAAA;EACR,IAAA,EAAM,YAAA;EACN,OAAA,EAAS,WAAA,CAAY,WAAA;EACrB,aAAA,EAAe,aAAA,CAAc,WAAA;EAC7B,eAAA,EAAiB,cAAA,CAAe,WAAA;EAChC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,IAAA;EACA,QAAA,IACE,IAAA,EAAM,YAAA,EACN,eAAA,GAAkB,cAAA,CAAe,WAAA;AAAA;AAAA,UAI3B,qBAAA;EACR,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAoB;AAAA;AAAA,iBAGxB,eAAA;EACd,IAAA;EACA,OAAA;EACA,aAAA;EACA,eAAA;EACA,aAAA;EACA,eAAA;EACA,OAAA;EACA,sBAAA;EACA,eAAA;EACA,iBAAA;EACA;AAAA,GACC,oBAAA,CAAqB,WAAA,IAAe,qBAAA"}
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"}