@pierre/diffs 1.3.0-beta.9 → 1.3.0-rc.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 (241) hide show
  1. package/README.md +9 -0
  2. package/dist/components/CodeView.d.ts +12 -13
  3. package/dist/components/CodeView.d.ts.map +1 -1
  4. package/dist/components/CodeView.js +50 -58
  5. package/dist/components/CodeView.js.map +1 -1
  6. package/dist/components/File.d.ts +10 -3
  7. package/dist/components/File.d.ts.map +1 -1
  8. package/dist/components/File.js +41 -10
  9. package/dist/components/File.js.map +1 -1
  10. package/dist/components/FileDiff.d.ts +37 -6
  11. package/dist/components/FileDiff.d.ts.map +1 -1
  12. package/dist/components/FileDiff.js +202 -19
  13. package/dist/components/FileDiff.js.map +1 -1
  14. package/dist/components/UnresolvedFile.d.ts.map +1 -1
  15. package/dist/components/UnresolvedFile.js +7 -2
  16. package/dist/components/UnresolvedFile.js.map +1 -1
  17. package/dist/components/VirtualizedFile.d.ts +2 -1
  18. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  19. package/dist/components/VirtualizedFile.js +9 -5
  20. package/dist/components/VirtualizedFile.js.map +1 -1
  21. package/dist/components/VirtualizedFileDiff.d.ts +14 -0
  22. package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
  23. package/dist/components/VirtualizedFileDiff.js +61 -3
  24. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  25. package/dist/components/Virtualizer.d.ts +14 -2
  26. package/dist/components/Virtualizer.d.ts.map +1 -1
  27. package/dist/components/Virtualizer.js +27 -2
  28. package/dist/components/Virtualizer.js.map +1 -1
  29. package/dist/edit/index.d.ts +5 -0
  30. package/dist/edit/index.js +3 -0
  31. package/dist/editor/command.d.ts +1 -1
  32. package/dist/editor/command.d.ts.map +1 -1
  33. package/dist/editor/command.js +11 -0
  34. package/dist/editor/command.js.map +1 -1
  35. package/dist/editor/editStack.d.ts +6 -2
  36. package/dist/editor/editStack.d.ts.map +1 -1
  37. package/dist/editor/editStack.js +53 -12
  38. package/dist/editor/editStack.js.map +1 -1
  39. package/dist/editor/editor.d.ts +51 -23
  40. package/dist/editor/editor.d.ts.map +1 -1
  41. package/dist/editor/editor.js +977 -241
  42. package/dist/editor/editor.js.map +1 -1
  43. package/dist/editor/editor2.js +1 -1
  44. package/dist/editor/languages.d.ts +26 -0
  45. package/dist/editor/languages.d.ts.map +1 -0
  46. package/dist/editor/languages.js +363 -0
  47. package/dist/editor/languages.js.map +1 -0
  48. package/dist/editor/lineAnnotations.d.ts.map +1 -1
  49. package/dist/editor/lineAnnotations.js +25 -26
  50. package/dist/editor/lineAnnotations.js.map +1 -1
  51. package/dist/editor/marker.d.ts +5 -3
  52. package/dist/editor/marker.d.ts.map +1 -1
  53. package/dist/editor/marker.js +111 -91
  54. package/dist/editor/marker.js.map +1 -1
  55. package/dist/editor/matchBrackets.d.ts +3 -2
  56. package/dist/editor/matchBrackets.d.ts.map +1 -1
  57. package/dist/editor/matchBrackets.js +2 -10
  58. package/dist/editor/matchBrackets.js.map +1 -1
  59. package/dist/editor/pieceTable.d.ts +2 -1
  60. package/dist/editor/pieceTable.d.ts.map +1 -1
  61. package/dist/editor/pieceTable.js +103 -39
  62. package/dist/editor/pieceTable.js.map +1 -1
  63. package/dist/editor/platform.js +2 -0
  64. package/dist/editor/platform.js.map +1 -1
  65. package/dist/editor/popover.d.ts +25 -5
  66. package/dist/editor/popover.d.ts.map +1 -1
  67. package/dist/editor/popover.js +60 -14
  68. package/dist/editor/popover.js.map +1 -1
  69. package/dist/editor/searchPanel.d.ts.map +1 -1
  70. package/dist/editor/searchPanel.js +9 -2
  71. package/dist/editor/searchPanel.js.map +1 -1
  72. package/dist/editor/selection.d.ts +31 -11
  73. package/dist/editor/selection.d.ts.map +1 -1
  74. package/dist/editor/selection.js +198 -70
  75. package/dist/editor/selection.js.map +1 -1
  76. package/dist/editor/selectionAction.d.ts +4 -3
  77. package/dist/editor/selectionAction.d.ts.map +1 -1
  78. package/dist/editor/selectionAction.js +9 -5
  79. package/dist/editor/selectionAction.js.map +1 -1
  80. package/dist/editor/stateStorage.d.ts +15 -0
  81. package/dist/editor/stateStorage.d.ts.map +1 -0
  82. package/dist/editor/stateStorage.js +65 -0
  83. package/dist/editor/stateStorage.js.map +1 -0
  84. package/dist/editor/textDocument.d.ts +12 -77
  85. package/dist/editor/textDocument.d.ts.map +1 -1
  86. package/dist/editor/textDocument.js +76 -34
  87. package/dist/editor/textDocument.js.map +1 -1
  88. package/dist/editor/textMeasure.d.ts +7 -12
  89. package/dist/editor/textMeasure.d.ts.map +1 -1
  90. package/dist/editor/textMeasure.js +40 -32
  91. package/dist/editor/textMeasure.js.map +1 -1
  92. package/dist/editor/{tokenzier.d.ts → tokenizer.d.ts} +3 -3
  93. package/dist/editor/tokenizer.d.ts.map +1 -0
  94. package/dist/editor/{tokenzier.js → tokenizer.js} +170 -50
  95. package/dist/editor/tokenizer.js.map +1 -0
  96. package/dist/editor/utils.js +1 -1
  97. package/dist/editor/utils.js.map +1 -1
  98. package/dist/index.d.ts +4 -3
  99. package/dist/index.js +6 -5
  100. package/dist/managers/InteractionManager.d.ts +18 -7
  101. package/dist/managers/InteractionManager.d.ts.map +1 -1
  102. package/dist/managers/InteractionManager.js +154 -99
  103. package/dist/managers/InteractionManager.js.map +1 -1
  104. package/dist/managers/UniversalRenderingManager.d.ts.map +1 -1
  105. package/dist/managers/UniversalRenderingManager.js +1 -2
  106. package/dist/managers/UniversalRenderingManager.js.map +1 -1
  107. package/dist/react/CodeView.d.ts +13 -13
  108. package/dist/react/CodeView.d.ts.map +1 -1
  109. package/dist/react/CodeView.js +37 -28
  110. package/dist/react/CodeView.js.map +1 -1
  111. package/dist/react/EditContext.d.ts +20 -0
  112. package/dist/react/EditContext.d.ts.map +1 -0
  113. package/dist/react/EditContext.js +20 -0
  114. package/dist/react/EditContext.js.map +1 -0
  115. package/dist/react/File.d.ts +2 -1
  116. package/dist/react/File.d.ts.map +1 -1
  117. package/dist/react/File.js +3 -2
  118. package/dist/react/File.js.map +1 -1
  119. package/dist/react/FileDiff.d.ts +2 -2
  120. package/dist/react/FileDiff.d.ts.map +1 -1
  121. package/dist/react/FileDiff.js +3 -2
  122. package/dist/react/FileDiff.js.map +1 -1
  123. package/dist/react/MultiFileDiff.d.ts +2 -2
  124. package/dist/react/MultiFileDiff.d.ts.map +1 -1
  125. package/dist/react/MultiFileDiff.js +3 -2
  126. package/dist/react/MultiFileDiff.js.map +1 -1
  127. package/dist/react/PatchDiff.d.ts +2 -2
  128. package/dist/react/PatchDiff.d.ts.map +1 -1
  129. package/dist/react/PatchDiff.js +3 -2
  130. package/dist/react/PatchDiff.js.map +1 -1
  131. package/dist/react/UnresolvedFile.d.ts +1 -1
  132. package/dist/react/UnresolvedFile.js.map +1 -1
  133. package/dist/react/index.d.ts +4 -4
  134. package/dist/react/index.js +3 -3
  135. package/dist/react/types.d.ts +9 -1
  136. package/dist/react/types.d.ts.map +1 -1
  137. package/dist/react/utils/useFileDiffInstance.d.ts +5 -3
  138. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  139. package/dist/react/utils/useFileDiffInstance.js +24 -34
  140. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  141. package/dist/react/utils/useFileInstance.d.ts +5 -3
  142. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  143. package/dist/react/utils/useFileInstance.js +23 -33
  144. package/dist/react/utils/useFileInstance.js.map +1 -1
  145. package/dist/react/utils/useUnresolvedFileInstance.js +4 -4
  146. package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
  147. package/dist/renderers/DiffHunksRenderer.d.ts +41 -1
  148. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  149. package/dist/renderers/DiffHunksRenderer.js +167 -29
  150. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  151. package/dist/renderers/FileRenderer.d.ts +20 -1
  152. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  153. package/dist/renderers/FileRenderer.js +119 -29
  154. package/dist/renderers/FileRenderer.js.map +1 -1
  155. package/dist/ssr/index.d.ts +2 -2
  156. package/dist/ssr/preloadDiffs.d.ts.map +1 -1
  157. package/dist/ssr/preloadDiffs.js +3 -1
  158. package/dist/ssr/preloadDiffs.js.map +1 -1
  159. package/dist/ssr/preloadFile.d.ts.map +1 -1
  160. package/dist/ssr/preloadFile.js +2 -0
  161. package/dist/ssr/preloadFile.js.map +1 -1
  162. package/dist/style.js +1 -1
  163. package/dist/types.d.ts +192 -42
  164. package/dist/types.d.ts.map +1 -1
  165. package/dist/utils/annotationHelpers.d.ts +20 -0
  166. package/dist/utils/annotationHelpers.d.ts.map +1 -0
  167. package/dist/utils/annotationHelpers.js +29 -0
  168. package/dist/utils/annotationHelpers.js.map +1 -0
  169. package/dist/utils/computeFileOffsets.d.ts.map +1 -1
  170. package/dist/utils/computeFileOffsets.js +34 -5
  171. package/dist/utils/computeFileOffsets.js.map +1 -1
  172. package/dist/utils/editSessionHunks.d.ts +66 -0
  173. package/dist/utils/editSessionHunks.d.ts.map +1 -0
  174. package/dist/utils/editSessionHunks.js +437 -0
  175. package/dist/utils/editSessionHunks.js.map +1 -0
  176. package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -1
  177. package/dist/utils/getDiffHunksRendererOptions.js +2 -1
  178. package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
  179. package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
  180. package/dist/utils/getFileRendererOptions.js +2 -1
  181. package/dist/utils/getFileRendererOptions.js.map +1 -1
  182. package/dist/utils/getHunkSideBoundaries.d.ts +7 -0
  183. package/dist/utils/getHunkSideBoundaries.d.ts.map +1 -0
  184. package/dist/utils/getHunkSideBoundaries.js +12 -0
  185. package/dist/utils/getHunkSideBoundaries.js.map +1 -0
  186. package/dist/utils/getTotalLineCountFromHunks.d.ts.map +1 -1
  187. package/dist/utils/getTotalLineCountFromHunks.js +2 -1
  188. package/dist/utils/getTotalLineCountFromHunks.js.map +1 -1
  189. package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
  190. package/dist/utils/hydratePartialDiff.js +4 -3
  191. package/dist/utils/hydratePartialDiff.js.map +1 -1
  192. package/dist/utils/isGutterUtilityPath.d.ts +5 -0
  193. package/dist/utils/isGutterUtilityPath.d.ts.map +1 -0
  194. package/dist/utils/isGutterUtilityPath.js +12 -0
  195. package/dist/utils/isGutterUtilityPath.js.map +1 -0
  196. package/dist/utils/iterateOverDiff.d.ts.map +1 -1
  197. package/dist/utils/iterateOverDiff.js +17 -12
  198. package/dist/utils/iterateOverDiff.js.map +1 -1
  199. package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
  200. package/dist/utils/parseMergeConflictDiffFromFile.js +9 -6
  201. package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
  202. package/dist/utils/parsePatchFiles.d.ts.map +1 -1
  203. package/dist/utils/parsePatchFiles.js +6 -3
  204. package/dist/utils/parsePatchFiles.js.map +1 -1
  205. package/dist/utils/realignChangeContent.d.ts +33 -0
  206. package/dist/utils/realignChangeContent.d.ts.map +1 -0
  207. package/dist/utils/realignChangeContent.js +148 -0
  208. package/dist/utils/realignChangeContent.js.map +1 -0
  209. package/dist/utils/renderDiffWithHighlighter.js +1 -1
  210. package/dist/utils/resolveRegion.d.ts.map +1 -1
  211. package/dist/utils/resolveRegion.js +18 -2
  212. package/dist/utils/resolveRegion.js.map +1 -1
  213. package/dist/utils/shouldUseTokenTransformer.d.ts +7 -3
  214. package/dist/utils/shouldUseTokenTransformer.d.ts.map +1 -1
  215. package/dist/utils/shouldUseTokenTransformer.js +1 -1
  216. package/dist/utils/shouldUseTokenTransformer.js.map +1 -1
  217. package/dist/utils/updateDiffHunks.d.ts +8 -2
  218. package/dist/utils/updateDiffHunks.d.ts.map +1 -1
  219. package/dist/utils/updateDiffHunks.js +9 -7
  220. package/dist/utils/updateDiffHunks.js.map +1 -1
  221. package/dist/utils/virtualDiffLayout.d.ts +42 -2
  222. package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
  223. package/dist/utils/virtualDiffLayout.js +101 -7
  224. package/dist/utils/virtualDiffLayout.js.map +1 -1
  225. package/dist/worker/WorkerPoolManager.d.ts +2 -1
  226. package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
  227. package/dist/worker/WorkerPoolManager.js +3 -0
  228. package/dist/worker/WorkerPoolManager.js.map +1 -1
  229. package/dist/worker/worker-portable.js +60 -20
  230. package/dist/worker/worker-portable.js.map +1 -1
  231. package/dist/worker/worker.js +61 -19
  232. package/dist/worker/worker.js.map +1 -1
  233. package/package.json +10 -7
  234. package/dist/editor/index.d.ts +0 -3
  235. package/dist/editor/index.js +0 -3
  236. package/dist/editor/tokenzier.d.ts.map +0 -1
  237. package/dist/editor/tokenzier.js.map +0 -1
  238. package/dist/react/EditorContext.d.ts +0 -15
  239. package/dist/react/EditorContext.d.ts.map +0 -1
  240. package/dist/react/EditorContext.js +0 -23
  241. package/dist/react/EditorContext.js.map +0 -1
@@ -7,11 +7,12 @@ import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
7
7
  import { useMemo } from "react";
8
8
  import { jsx } from "react/jsx-runtime";
9
9
  //#region src/react/PatchDiff.tsx
10
- function PatchDiff({ patch, options, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false, contentEditable = false }) {
10
+ function PatchDiff({ patch, options, editorOptions, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false, edit = false }) {
11
11
  const fileDiff = usePatch(patch);
12
12
  const { ref, getHoveredLine } = useFileDiffInstance({
13
13
  fileDiff,
14
14
  options,
15
+ editorOptions,
15
16
  metrics,
16
17
  lineAnnotations,
17
18
  selectedLines,
@@ -19,7 +20,7 @@ function PatchDiff({ patch, options, metrics, lineAnnotations, selectedLines, cl
19
20
  hasGutterRenderUtility: renderGutterUtility != null,
20
21
  hasCustomHeader: renderCustomHeader != null,
21
22
  disableWorkerPool,
22
- contentEditable
23
+ edit
23
24
  });
24
25
  return /* @__PURE__ */ jsx(DIFFS_TAG_NAME, {
25
26
  ref,
@@ -1 +1 @@
1
- {"version":3,"file":"PatchDiff.js","names":[],"sources":["../../src/react/PatchDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport { getSingularPatch } from '../utils/getSingularPatch';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport interface PatchDiffProps<\n LAnnotation,\n> extends DiffBasePropsReact<LAnnotation> {\n patch: string;\n disableWorkerPool?: boolean;\n contentEditable?: boolean;\n}\n\nexport function PatchDiff<LAnnotation = undefined>({\n patch,\n options,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n contentEditable = false,\n}: PatchDiffProps<LAnnotation>): React.JSX.Element {\n const fileDiff = usePatch(patch);\n const { ref, getHoveredLine } = useFileDiffInstance({\n fileDiff,\n options,\n metrics,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n contentEditable,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n\nfunction usePatch(patch: string): FileDiffMetadata {\n return useMemo<FileDiffMetadata>(() => getSingularPatch(patch), [patch]);\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAgB,UAAmC,EACjD,OACA,SACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,oBAAoB,OACpB,kBAAkB,SAC+B;CACjD,MAAM,WAAW,SAAS,KAAK;CAC/B,MAAM,EAAE,KAAK,mBAAmB,oBAAoB;EAClD;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;EACA;CACF,CAAC;CAYD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;YACpD,eAbY,mBAAmB;GAClC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAG2B,GAAG,eAAe;CAC3B,CAAA;AAEpB;AAEA,SAAS,SAAS,OAAiC;CACjD,OAAO,cAAgC,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;AACzE"}
1
+ {"version":3,"file":"PatchDiff.js","names":[],"sources":["../../src/react/PatchDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport { getSingularPatch } from '../utils/getSingularPatch';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport interface PatchDiffProps<\n LAnnotation,\n> extends DiffBasePropsReact<LAnnotation> {\n patch: string;\n disableWorkerPool?: boolean;\n}\n\nexport function PatchDiff<LAnnotation = undefined>({\n patch,\n options,\n editorOptions,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n}: PatchDiffProps<LAnnotation>): React.JSX.Element {\n const fileDiff = usePatch(patch);\n const { ref, getHoveredLine } = useFileDiffInstance({\n fileDiff,\n options,\n editorOptions,\n metrics,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n edit,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n\nfunction usePatch(patch: string): FileDiffMetadata {\n return useMemo<FileDiffMetadata>(() => getSingularPatch(patch), [patch]);\n}\n"],"mappings":";;;;;;;;;AAmBA,SAAgB,UAAmC,EACjD,OACA,SACA,eACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,oBAAoB,OACpB,OAAO,SAC0C;CACjD,MAAM,WAAW,SAAS,KAAK;CAC/B,MAAM,EAAE,KAAK,mBAAmB,oBAAoB;EAClD;EACA;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;EACA;CACF,CAAC;CAYD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;YACpD,eAbY,mBAAmB;GAClC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAG2B,GAAG,eAAe;CAC3B,CAAA;AAEpB;AAEA,SAAS,SAAS,OAAiC;CACjD,OAAO,cAAgC,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;AACzE"}
@@ -17,7 +17,7 @@ interface UnresolvedFileReactOptions<LAnnotation> extends Omit<FileDiffOptions<L
17
17
  onPostRender?(node: HTMLElement, instance: UnresolvedFile$1<LAnnotation>, phase: PostRenderPhase): unknown;
18
18
  maxContextLines?: number;
19
19
  }
20
- interface UnresolvedFileProps<LAnnotation> extends Omit<FileDiffProps<LAnnotation>, 'fileDiff' | 'options'> {
20
+ interface UnresolvedFileProps<LAnnotation> extends Omit<FileDiffProps<LAnnotation>, 'fileDiff' | 'options' | 'edit' | 'editorOptions'> {
21
21
  file: FileContents;
22
22
  options?: UnresolvedFileReactOptions<LAnnotation>;
23
23
  renderMergeConflictUtility?(action: MergeConflictDiffAction, getInstance: () => UnresolvedFile$1<LAnnotation> | undefined): ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"UnresolvedFile.js","names":[],"sources":["../../src/react/UnresolvedFile.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\n\nimport type { FileDiffOptions } from '../components/FileDiff';\nimport type { UnresolvedFile as UnresolvedFileClass } from '../components/UnresolvedFile';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { UnresolvedFileHunksRendererOptions } from '../renderers/UnresolvedFileHunksRenderer';\nimport type {\n FileContents,\n HunkSeparators,\n MergeConflictResolution,\n PostRenderPhase,\n} from '../types';\nimport { type MergeConflictDiffAction } from '../utils/parseMergeConflictDiffFromFile';\nimport type { FileDiffProps } from './FileDiff';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useUnresolvedFileInstance } from './utils/useUnresolvedFileInstance';\n\nexport interface RenderMergeConflictActionContext {\n resolveConflict(resolution: MergeConflictResolution): void;\n}\n\nexport type RenderMergeConflictActions = (\n action: MergeConflictDiffAction,\n context: RenderMergeConflictActionContext\n) => ReactNode;\n\nexport type MergeConflictActionsTypeOption =\n | 'none'\n | 'default'\n | RenderMergeConflictActions;\n\nexport interface UnresolvedFileReactOptions<LAnnotation>\n extends\n Omit<\n FileDiffOptions<LAnnotation>,\n 'hunkSeparators' | 'diffStyle' | 'onMergeConflictAction' | 'onPostRender'\n >,\n UnresolvedFileHunksRendererOptions {\n hunkSeparators?: HunkSeparators;\n onPostRender?(\n node: HTMLElement,\n instance: UnresolvedFileClass<LAnnotation>,\n phase: PostRenderPhase\n ): unknown;\n maxContextLines?: number;\n}\n\nexport interface UnresolvedFileProps<LAnnotation> extends Omit<\n FileDiffProps<LAnnotation>,\n 'fileDiff' | 'options'\n> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n renderMergeConflictUtility?(\n action: MergeConflictDiffAction,\n getInstance: () => UnresolvedFileClass<LAnnotation> | undefined\n ): ReactNode;\n disableWorkerPool?: boolean;\n}\n\nexport function UnresolvedFile<LAnnotation = undefined>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n renderMergeConflictUtility,\n disableWorkerPool = false,\n}: UnresolvedFileProps<LAnnotation>): React.JSX.Element {\n const { ref, getHoveredLine, fileDiff, actions, getInstance } =\n useUnresolvedFileInstance({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasConflictUtility: renderMergeConflictUtility != null,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n lineAnnotations,\n getHoveredLine,\n actions,\n renderMergeConflictUtility,\n getInstance,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;AA+DA,SAAgB,eAAwC,EACtD,MACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,4BACA,oBAAoB,SACkC;CACtD,MAAM,EAAE,KAAK,gBAAgB,UAAU,SAAS,gBAC9C,0BAA0B;EACxB;EACA;EACA;EACA;EACA;EACA,oBAAoB,8BAA8B;EAClD,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;CACF,CAAC;CAeH,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;YACpD,eAhBY,mBAAmB;GAClC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAG2B,GAAG,eAAe;CAC3B,CAAA;AAEpB"}
1
+ {"version":3,"file":"UnresolvedFile.js","names":[],"sources":["../../src/react/UnresolvedFile.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\n\nimport type { FileDiffOptions } from '../components/FileDiff';\nimport type { UnresolvedFile as UnresolvedFileClass } from '../components/UnresolvedFile';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { UnresolvedFileHunksRendererOptions } from '../renderers/UnresolvedFileHunksRenderer';\nimport type {\n FileContents,\n HunkSeparators,\n MergeConflictResolution,\n PostRenderPhase,\n} from '../types';\nimport { type MergeConflictDiffAction } from '../utils/parseMergeConflictDiffFromFile';\nimport type { FileDiffProps } from './FileDiff';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useUnresolvedFileInstance } from './utils/useUnresolvedFileInstance';\n\nexport interface RenderMergeConflictActionContext {\n resolveConflict(resolution: MergeConflictResolution): void;\n}\n\nexport type RenderMergeConflictActions = (\n action: MergeConflictDiffAction,\n context: RenderMergeConflictActionContext\n) => ReactNode;\n\nexport type MergeConflictActionsTypeOption =\n | 'none'\n | 'default'\n | RenderMergeConflictActions;\n\nexport interface UnresolvedFileReactOptions<LAnnotation>\n extends\n Omit<\n FileDiffOptions<LAnnotation>,\n 'hunkSeparators' | 'diffStyle' | 'onMergeConflictAction' | 'onPostRender'\n >,\n UnresolvedFileHunksRendererOptions {\n hunkSeparators?: HunkSeparators;\n onPostRender?(\n node: HTMLElement,\n instance: UnresolvedFileClass<LAnnotation>,\n phase: PostRenderPhase\n ): unknown;\n maxContextLines?: number;\n}\n\nexport interface UnresolvedFileProps<LAnnotation> extends Omit<\n FileDiffProps<LAnnotation>,\n 'fileDiff' | 'options' | 'edit' | 'editorOptions'\n> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n renderMergeConflictUtility?(\n action: MergeConflictDiffAction,\n getInstance: () => UnresolvedFileClass<LAnnotation> | undefined\n ): ReactNode;\n disableWorkerPool?: boolean;\n}\n\nexport function UnresolvedFile<LAnnotation = undefined>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n renderMergeConflictUtility,\n disableWorkerPool = false,\n}: UnresolvedFileProps<LAnnotation>): React.JSX.Element {\n const { ref, getHoveredLine, fileDiff, actions, getInstance } =\n useUnresolvedFileInstance({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasConflictUtility: renderMergeConflictUtility != null,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n lineAnnotations,\n getHoveredLine,\n actions,\n renderMergeConflictUtility,\n getInstance,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;AA+DA,SAAgB,eAAwC,EACtD,MACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,4BACA,oBAAoB,SACkC;CACtD,MAAM,EAAE,KAAK,gBAAgB,UAAU,SAAS,gBAC9C,0BAA0B;EACxB;EACA;EACA;EACA;EACA;EACA,oBAAoB,8BAA8B;EAClD,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;CACF,CAAC;CAeH,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;YACpD,eAhBY,mBAAmB;GAClC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAG2B,GAAG,eAAe;CAC3B,CAAA;AAEpB"}
@@ -1,7 +1,7 @@
1
- import { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsEditorHost, DiffsEditorSelection, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileHeaderRenderMode, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PendingCodeViewLayoutReset, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, ThemeRegistration, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, TokenEventBase, VirtualFileMetrics, VirtualWindowSpecs } from "../types.js";
1
+ import { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, EditableInstance, EditorActiveLineOptions, EditorSelection, EditorState, EditorViewState, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileHeaderRenderMode, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PendingCodeViewLayoutReset, Position, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, Range, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionDirection, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, TextEdit, ThemeRegistration, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, TokenEventBase, VirtualFileMetrics, VirtualWindowSpecs } from "../types.js";
2
2
  import { WorkerInitializationRenderOptions, WorkerPoolOptions } from "../worker/types.js";
3
3
  import { FileOptions } from "../components/File.js";
4
- import { CodeView, CodeViewHandle, CodeViewProps, ControlledCodeViewProps, UncontrolledCodeViewProps } from "./CodeView.js";
4
+ import { CodeView, CodeViewHandle, CodeViewProps, CodeViewReactOptions, ControlledCodeViewProps, UncontrolledCodeViewProps } from "./CodeView.js";
5
5
  import { DiffBasePropsReact, FileProps } from "./types.js";
6
6
  import { File } from "./File.js";
7
7
  import { FileDiff, FileDiffProps } from "./FileDiff.js";
@@ -10,7 +10,7 @@ import { MultiFileDiff, MultiFileDiffProps } from "./MultiFileDiff.js";
10
10
  import { PatchDiff, PatchDiffProps } from "./PatchDiff.js";
11
11
  import { Virtualizer, VirtualizerContext, useVirtualizer } from "./Virtualizer.js";
12
12
  import { WorkerPoolContext, WorkerPoolContextProvider, useWorkerPool } from "./WorkerPoolContext.js";
13
- import { EditorContext, EditorProvider, useEditor } from "./EditorContext.js";
13
+ import { CreateEditor, EditContext, EditProvider, EditProviderProps, useCreateEditor } from "./EditContext.js";
14
14
  import { GutterUtilitySlotStyles, MergeConflictSlotStyles, noopRender } from "./constants.js";
15
15
  import { renderDiffChildren } from "./utils/renderDiffChildren.js";
16
16
  import { renderFileChildren } from "./utils/renderFileChildren.js";
@@ -18,4 +18,4 @@ import { templateRender } from "./utils/templateRender.js";
18
18
  import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
19
19
  import { useFileInstance } from "./utils/useFileInstance.js";
20
20
  import { useStableCallback } from "./utils/useStableCallback.js";
21
- export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, type BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, type CodeToHastOptions, CodeView, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewHandle, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewProps, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, ControlledCodeViewProps, type CreatePatchOptionsNonabortable, CustomPreProperties, type DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffBasePropsReact, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsEditorHost, DiffsEditorSelection, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, EditorContext, EditorProvider, ExpansionDirections, ExtensionFormatMap, File, FileContents, FileDiff, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileDiffProps, FileHeaderRenderMode, type FileOptions, FileProps, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, GutterUtilitySlotStyles, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, type LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictActionsTypeOption, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, MergeConflictSlotStyles, MultiFileDiff, MultiFileDiffProps, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PatchDiff, PatchDiffProps, PendingCodeViewLayoutReset, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderMergeConflictActionContext, RenderMergeConflictActions, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionPoint, SelectionSide, SharedRenderState, type ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, type ThemeRegistration, type ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, type ThemedToken, ThemesType, TokenEventBase, UncontrolledCodeViewProps, UnresolvedFile, UnresolvedFileProps, UnresolvedFileReactOptions, VirtualFileMetrics, VirtualWindowSpecs, Virtualizer, VirtualizerContext, type WorkerInitializationRenderOptions, WorkerPoolContext, WorkerPoolContextProvider, type WorkerPoolOptions, noopRender, renderDiffChildren, renderFileChildren, templateRender, useEditor, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
21
+ export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, type BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, type CodeToHastOptions, CodeView, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewHandle, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewProps, CodeViewRangeScrollTarget, CodeViewReactOptions, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, ControlledCodeViewProps, CreateEditor, type CreatePatchOptionsNonabortable, CustomPreProperties, type DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffBasePropsReact, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, EditContext, EditProvider, EditProviderProps, EditableInstance, EditorActiveLineOptions, EditorSelection, EditorState, EditorViewState, ExpansionDirections, ExtensionFormatMap, File, FileContents, FileDiff, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileDiffProps, FileHeaderRenderMode, type FileOptions, FileProps, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, GutterUtilitySlotStyles, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, type LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictActionsTypeOption, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, MergeConflictSlotStyles, MultiFileDiff, MultiFileDiffProps, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PatchDiff, PatchDiffProps, PendingCodeViewLayoutReset, Position, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, Range, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderMergeConflictActionContext, RenderMergeConflictActions, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionDirection, SelectionPoint, SelectionSide, SharedRenderState, type ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, TextEdit, type ThemeRegistration, type ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, type ThemedToken, ThemesType, TokenEventBase, UncontrolledCodeViewProps, UnresolvedFile, UnresolvedFileProps, UnresolvedFileReactOptions, VirtualFileMetrics, VirtualWindowSpecs, Virtualizer, VirtualizerContext, type WorkerInitializationRenderOptions, WorkerPoolContext, WorkerPoolContextProvider, type WorkerPoolOptions, noopRender, renderDiffChildren, renderFileChildren, templateRender, useCreateEditor, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
@@ -1,10 +1,10 @@
1
+ import { useStableCallback } from "./utils/useStableCallback.js";
2
+ import { EditContext, EditProvider, useCreateEditor } from "./EditContext.js";
1
3
  import { GutterUtilitySlotStyles, MergeConflictSlotStyles, noopRender } from "./constants.js";
2
4
  import { renderDiffChildren } from "./utils/renderDiffChildren.js";
3
5
  import { renderFileChildren } from "./utils/renderFileChildren.js";
4
- import { useStableCallback } from "./utils/useStableCallback.js";
5
6
  import { WorkerPoolContext, WorkerPoolContextProvider, useWorkerPool } from "./WorkerPoolContext.js";
6
7
  import { CodeView } from "./CodeView.js";
7
- import { EditorContext, EditorProvider, useEditor } from "./EditorContext.js";
8
8
  import { templateRender } from "./utils/templateRender.js";
9
9
  import { Virtualizer, VirtualizerContext, useVirtualizer } from "./Virtualizer.js";
10
10
  import { useFileInstance } from "./utils/useFileInstance.js";
@@ -14,4 +14,4 @@ import { FileDiff } from "./FileDiff.js";
14
14
  import { MultiFileDiff } from "./MultiFileDiff.js";
15
15
  import { PatchDiff } from "./PatchDiff.js";
16
16
  import { UnresolvedFile } from "./UnresolvedFile.js";
17
- export { CodeView, EditorContext, EditorProvider, File, FileDiff, GutterUtilitySlotStyles, MergeConflictSlotStyles, MultiFileDiff, PatchDiff, UnresolvedFile, Virtualizer, VirtualizerContext, WorkerPoolContext, WorkerPoolContextProvider, noopRender, renderDiffChildren, renderFileChildren, templateRender, useEditor, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
17
+ export { CodeView, EditContext, EditProvider, File, FileDiff, GutterUtilitySlotStyles, MergeConflictSlotStyles, MultiFileDiff, PatchDiff, UnresolvedFile, Virtualizer, VirtualizerContext, WorkerPoolContext, WorkerPoolContextProvider, noopRender, renderDiffChildren, renderFileChildren, templateRender, useCreateEditor, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
@@ -2,11 +2,16 @@ import { DiffLineAnnotation, FileContents, FileDiffMetadata, LineAnnotation, Sel
2
2
  import { GetHoveredLineResult } from "../managers/InteractionManager.js";
3
3
  import { FileOptions } from "../components/File.js";
4
4
  import { FileDiffOptions } from "../components/FileDiff.js";
5
+ import { EditorOptions } from "../editor/editor.js";
5
6
  import { CSSProperties, ReactNode } from "react";
6
7
 
7
8
  //#region src/react/types.d.ts
8
9
  interface DiffBasePropsReact<LAnnotation> {
9
10
  options?: FileDiffOptions<LAnnotation>;
11
+ /** Whether this surface has an active edit session. */
12
+ edit?: boolean;
13
+ /** Creation-time options passed to the nearest EditProvider factory. */
14
+ editorOptions?: EditorOptions<LAnnotation>;
10
15
  metrics?: VirtualFileMetrics;
11
16
  lineAnnotations?: DiffLineAnnotation<LAnnotation>[];
12
17
  selectedLines?: SelectedLineRange | null;
@@ -23,6 +28,10 @@ interface DiffBasePropsReact<LAnnotation> {
23
28
  interface FileProps<LAnnotation> {
24
29
  file: FileContents;
25
30
  options?: FileOptions<LAnnotation>;
31
+ /** Whether this surface has an active edit session. */
32
+ edit?: boolean;
33
+ /** Creation-time options passed to the nearest EditProvider factory. */
34
+ editorOptions?: EditorOptions<LAnnotation>;
26
35
  metrics?: VirtualFileMetrics;
27
36
  lineAnnotations?: LineAnnotation<LAnnotation>[];
28
37
  selectedLines?: SelectedLineRange | null;
@@ -36,7 +45,6 @@ interface FileProps<LAnnotation> {
36
45
  style?: CSSProperties;
37
46
  prerenderedHTML?: string;
38
47
  disableWorkerPool?: boolean;
39
- contentEditable?: boolean;
40
48
  }
41
49
  //#endregion
42
50
  export { DiffBasePropsReact, FileProps };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/react/types.ts"],"mappings":";;;;;;;UAciB,kBAAA;EACf,OAAA,GAAU,eAAA,CAAgB,WAAA;EAC1B,OAAA,GAAU,kBAAA;EACV,eAAA,GAAkB,kBAAA,CAAmB,WAAA;EACrC,aAAA,GAAgB,iBAAA;EAChB,gBAAA,EAAkB,WAAA,EAAa,kBAAA,CAAmB,WAAA,IAAe,SAAA;EACjE,kBAAA,EAAoB,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACjD,kBAAA,EAAoB,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACjD,0BAAA,EAA4B,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACzD,oBAAA,EAAsB,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACnD,mBAAA,EACE,cAAA,QAAsB,oBAAA,uBACrB,SAAA;EACH,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,eAAA;AAAA;AAAA,UAGe,SAAA;EACf,IAAA,EAAM,YAAA;EACN,OAAA,GAAU,WAAA,CAAY,WAAA;EACtB,OAAA,GAAU,kBAAA;EACV,eAAA,GAAkB,cAAA,CAAe,WAAA;EACjC,aAAA,GAAgB,iBAAA;EAChB,gBAAA,EAAkB,WAAA,EAAa,cAAA,CAAe,WAAA,IAAe,SAAA;EAC7D,kBAAA,EAAoB,IAAA,EAAM,YAAA,GAAe,SAAA;EACzC,kBAAA,EAAoB,IAAA,EAAM,YAAA,GAAe,SAAA;EACzC,0BAAA,EAA4B,IAAA,EAAM,YAAA,GAAe,SAAA;EACjD,oBAAA,EAAsB,IAAA,EAAM,YAAA,GAAe,SAAA;EAC3C,mBAAA,EACE,cAAA,QAAsB,oBAAA,uBACrB,SAAA;EACH,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,eAAA;EACA,iBAAA;EACA,eAAA;AAAA"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/react/types.ts"],"mappings":";;;;;;;;UAeiB,kBAAA;EACf,OAAA,GAAU,eAAA,CAAgB,WAAA;;EAE1B,IAAA;EAHiC;EAKjC,aAAA,GAAgB,aAAA,CAAc,WAAA;EAC9B,OAAA,GAAU,kBAAA;EACV,eAAA,GAAkB,kBAAA,CAAmB,WAAA;EACrC,aAAA,GAAgB,iBAAA;EAChB,gBAAA,EAAkB,WAAA,EAAa,kBAAA,CAAmB,WAAA,IAAe,SAAA;EACjE,kBAAA,EAAoB,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACjD,kBAAA,EAAoB,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACjD,0BAAA,EAA4B,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACzD,oBAAA,EAAsB,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACnD,mBAAA,EACE,cAAA,QAAsB,oBAAA,uBACrB,SAAA;EACH,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,eAAA;AAAA;AAAA,UAGe,SAAA;EACf,IAAA,EAAM,YAAA;EACN,OAAA,GAAU,WAAA,CAAY,WAAA;EAZmC;EAczD,IAAA;EAbmD;EAenD,aAAA,GAAgB,aAAA,CAAc,WAAA;EAC9B,OAAA,GAAU,kBAAA;EACV,eAAA,GAAkB,cAAA,CAAe,WAAA;EACjC,aAAA,GAAgB,iBAAA;EAChB,gBAAA,EAAkB,WAAA,EAAa,cAAA,CAAe,WAAA,IAAe,SAAA;EAC7D,kBAAA,EAAoB,IAAA,EAAM,YAAA,GAAe,SAAA;EACzC,kBAAA,EAAoB,IAAA,EAAM,YAAA,GAAe,SAAA;EACzC,0BAAA,EAA4B,IAAA,EAAM,YAAA,GAAe,SAAA;EACjD,oBAAA,EAAsB,IAAA,EAAM,YAAA,GAAe,SAAA;EAC3C,mBAAA,EACE,cAAA,QAAsB,oBAAA,uBACrB,SAAA;EACH,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,eAAA;EACA,iBAAA;AAAA"}
@@ -1,11 +1,12 @@
1
1
  import { DiffLineAnnotation, FileDiffMetadata, SelectedLineRange, VirtualFileMetrics } from "../../types.js";
2
2
  import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
3
  import { FileDiffOptions } from "../../components/FileDiff.js";
4
-
4
+ import { EditorOptions } from "../../editor/editor.js";
5
5
  //#region src/react/utils/useFileDiffInstance.d.ts
6
6
  interface UseFileDiffInstanceProps<LAnnotation> {
7
7
  fileDiff: FileDiffMetadata;
8
8
  options: FileDiffOptions<LAnnotation> | undefined;
9
+ editorOptions: EditorOptions<LAnnotation> | undefined;
9
10
  lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;
10
11
  selectedLines: SelectedLineRange | null | undefined;
11
12
  prerenderedHTML: string | undefined;
@@ -13,7 +14,7 @@ interface UseFileDiffInstanceProps<LAnnotation> {
13
14
  hasGutterRenderUtility: boolean;
14
15
  hasCustomHeader: boolean;
15
16
  disableWorkerPool: boolean;
16
- contentEditable: boolean;
17
+ edit: boolean;
17
18
  }
18
19
  interface UseFileDiffInstanceReturn {
19
20
  ref(node: HTMLElement | null): void;
@@ -22,6 +23,7 @@ interface UseFileDiffInstanceReturn {
22
23
  declare function useFileDiffInstance<LAnnotation>({
23
24
  fileDiff,
24
25
  options,
26
+ editorOptions,
25
27
  lineAnnotations,
26
28
  selectedLines,
27
29
  prerenderedHTML,
@@ -29,7 +31,7 @@ declare function useFileDiffInstance<LAnnotation>({
29
31
  hasGutterRenderUtility,
30
32
  hasCustomHeader,
31
33
  disableWorkerPool,
32
- contentEditable
34
+ edit
33
35
  }: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn;
34
36
  //#endregion
35
37
  export { useFileDiffInstance };
@@ -1 +1 @@
1
- {"version":3,"file":"useFileDiffInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"mappings":";;;;;UA2BU,wBAAA;EACR,QAAA,EAAU,gBAAA;EACV,OAAA,EAAS,eAAA,CAAgB,WAAA;EACzB,eAAA,EAAiB,kBAAA,CAAmB,WAAA;EACpC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,eAAA;AAAA;AAAA,UAGQ,yBAAA;EACR,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAoB;AAAA;AAAA,iBAGxB,mBAAA;EACd,QAAA;EACA,OAAA;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":";;;;;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,36 +1,32 @@
1
1
  import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
2
2
  import { FileDiff } from "../../components/FileDiff.js";
3
3
  import { VirtualizedFileDiff } from "../../components/VirtualizedFileDiff.js";
4
- import { noopRender } from "../constants.js";
5
4
  import { useStableCallback } from "./useStableCallback.js";
5
+ import { useCreateEditor } from "../EditContext.js";
6
+ import { noopRender } from "../constants.js";
6
7
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
7
- import { useEditor } from "../EditorContext.js";
8
8
  import { useVirtualizer } from "../Virtualizer.js";
9
9
  import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
10
10
  //#region src/react/utils/useFileDiffInstance.ts
11
- const useIsometricEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
12
- function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, contentEditable }) {
11
+ const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
12
+ function useFileDiffInstance({ fileDiff, options, editorOptions, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, edit }) {
13
13
  const simpleVirtualizer = useVirtualizer();
14
14
  const controlledSelection = selectedLines !== void 0;
15
15
  const poolManager = useContext(WorkerPoolContext);
16
- const editor = useEditor();
16
+ const createEditor = useCreateEditor();
17
17
  const instanceRef = useRef(null);
18
18
  const ref = useStableCallback((fileContainer) => {
19
19
  if (fileContainer != null) {
20
20
  if (instanceRef.current != null) throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");
21
21
  if (simpleVirtualizer != null) instanceRef.current = new VirtualizedFileDiff(mergeFileDiffOptions({
22
22
  controlledSelection,
23
- contentEditable,
24
23
  hasCustomHeader,
25
- hasEditor: editor !== void 0,
26
24
  hasGutterRenderUtility,
27
25
  options
28
26
  }), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
29
27
  else instanceRef.current = new FileDiff(mergeFileDiffOptions({
30
28
  controlledSelection,
31
- contentEditable,
32
29
  hasCustomHeader,
33
- hasEditor: editor !== void 0,
34
30
  hasGutterRenderUtility,
35
31
  options
36
32
  }), !disableWorkerPool ? poolManager : void 0, true);
@@ -46,18 +42,16 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
46
42
  instanceRef.current = null;
47
43
  }
48
44
  });
49
- useIsometricEffect(() => {
45
+ useIsomorphicLayoutEffect(() => {
50
46
  const { current: instance } = instanceRef;
51
47
  if (instance == null) return;
52
48
  const newOptions = mergeFileDiffOptions({
53
49
  controlledSelection,
54
- contentEditable,
55
50
  hasCustomHeader,
56
- hasEditor: editor !== void 0,
57
51
  hasGutterRenderUtility,
58
52
  options
59
53
  });
60
- const forceRender = !areOptionsEqual(instance.options, newOptions);
54
+ const forceRender = newOptions !== void 0 && !areOptionsEqual(instance.options, newOptions);
61
55
  instance.setOptions(newOptions);
62
56
  instance.render({
63
57
  forceRender,
@@ -66,12 +60,19 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
66
60
  });
67
61
  if (selectedLines !== void 0) instance.setSelectedLines(selectedLines);
68
62
  });
69
- useIsometricEffect(() => {
70
- if (contentEditable && instanceRef.current != null) {
71
- if (editor === void 0) throw new Error("FileDiff: Editor is not attached");
72
- return editor.edit(instanceRef.current);
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
+ }
73
74
  }
74
- }, [contentEditable, editor]);
75
+ }, [edit]);
75
76
  return {
76
77
  ref,
77
78
  getHoveredLine: useCallback(() => {
@@ -79,24 +80,13 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
79
80
  }, [])
80
81
  };
81
82
  }
82
- function mergeFileDiffOptions({ options, controlledSelection, contentEditable, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
83
- const needsEditorOptions = contentEditable && hasEditor;
84
- const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
85
- if (!needsReactOverrides && !needsEditorOptions) return options;
83
+ function mergeFileDiffOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility }) {
84
+ if (!(controlledSelection || hasGutterRenderUtility || hasCustomHeader)) return options;
86
85
  return {
87
86
  ...options,
88
- ...needsReactOverrides ? {
89
- controlledSelection,
90
- renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
91
- renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
92
- } : null,
93
- ...needsEditorOptions ? {
94
- useTokenTransformer: true,
95
- enableGutterUtility: false,
96
- enableLineSelection: false,
97
- expandUnchanged: true,
98
- lineHoverHighlight: "disabled"
99
- } : null
87
+ controlledSelection,
88
+ renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
89
+ renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
100
90
  };
101
91
  }
102
92
  //#endregion
@@ -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 { 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 { useEditor } from '../EditorContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<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 contentEditable: 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 lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n contentEditable,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const editor = useEditor<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 contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\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 contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\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 useIsometricEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !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 useIsometricEffect(() => {\n if (contentEditable && instanceRef.current != null) {\n if (editor === undefined) {\n throw new Error('FileDiff: Editor is not attached');\n }\n return editor.edit(instanceRef.current);\n }\n return undefined;\n }, [contentEditable, editor]);\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 contentEditable: boolean;\n hasEditor: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n options: FileDiffOptions<LAnnotation> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation>({\n options,\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor,\n hasGutterRenderUtility,\n}: MergeFileDiffOptionsProps<LAnnotation>):\n | FileDiffOptions<LAnnotation>\n | undefined {\n const needsEditorOptions = contentEditable && hasEditor;\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides && !needsEditorOptions) {\n return options;\n }\n\n return {\n ...options,\n ...(needsReactOverrides\n ? {\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n }\n : null),\n ...(needsEditorOptions\n ? {\n useTokenTransformer: true,\n enableGutterUtility: false,\n enableLineSelection: false,\n expandUnchanged: true,\n lineHoverHighlight: 'disabled',\n }\n : null),\n };\n}\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAoB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,mBACmE;CACnE,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,SAAS,UAAuB;CACtC,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,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,SACxB,qBAAqB;IACnB;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;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,yBAAyB;EACvB,MAAM,EAAE,SAAS,aAAa;EAC9B,IAAI,YAAY,MAAM;EACtB,MAAM,aAAa,qBAAqB;GACtC;GACA;GACA;GACA,WAAW,WAAW,KAAA;GACtB;GACA;EACF,CAAC;EACD,MAAM,cAAc,CAAC,gBAAgB,SAAS,SAAS,UAAU;EACjE,SAAS,WAAW,UAAU;EAC9B,SAAc,OAAO;GACnB;GACA;GACA;EACF,CAAC;EACD,IAAI,kBAAkB,KAAA,GACpB,SAAS,iBAAiB,aAAa;CAE3C,CAAC;CAED,yBAAyB;EACvB,IAAI,mBAAmB,YAAY,WAAW,MAAM;GAClD,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,kCAAkC;GAEpD,OAAO,OAAO,KAAK,YAAY,OAAO;EACxC;CAEF,GAAG,CAAC,iBAAiB,MAAM,CAAC;CAQ5B,OAAO;EACL;EACA,gBARqB,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CAIW;CACf;AACF;AAWA,SAAS,qBAAkC,EACzC,SACA,qBACA,iBACA,iBACA,WACA,0BAGY;CACZ,MAAM,qBAAqB,mBAAmB;CAC9C,MAAM,sBACJ,uBAAuB,0BAA0B;CAEnD,IAAI,CAAC,uBAAuB,CAAC,oBAC3B,OAAO;CAGT,OAAO;EACL,GAAG;EACH,GAAI,sBACA;GACE;GACA,oBAAoB,kBAChB,aACA,SAAS;GACb,qBAAqB,yBACjB,aACA,SAAS;EACf,IACA;EACJ,GAAI,qBACA;GACE,qBAAqB;GACrB,qBAAqB;GACrB,qBAAqB;GACrB,iBAAiB;GACjB,oBAAoB;EACtB,IACA;CACN;AACF"}
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,11 +1,12 @@
1
1
  import { FileContents, LineAnnotation, SelectedLineRange, VirtualFileMetrics } from "../../types.js";
2
2
  import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
3
3
  import { FileOptions } from "../../components/File.js";
4
-
4
+ import { EditorOptions } from "../../editor/editor.js";
5
5
  //#region src/react/utils/useFileInstance.d.ts
6
6
  interface UseFileInstanceProps<LAnnotation> {
7
7
  file: FileContents;
8
8
  options: FileOptions<LAnnotation> | undefined;
9
+ editorOptions: EditorOptions<LAnnotation> | undefined;
9
10
  lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;
10
11
  selectedLines: SelectedLineRange | null | undefined;
11
12
  prerenderedHTML: string | undefined;
@@ -13,7 +14,7 @@ interface UseFileInstanceProps<LAnnotation> {
13
14
  hasGutterRenderUtility: boolean;
14
15
  hasCustomHeader: boolean;
15
16
  disableWorkerPool: boolean;
16
- contentEditable: boolean;
17
+ edit: boolean;
17
18
  onChange?: (file: FileContents, lineAnnotations?: LineAnnotation<LAnnotation>[]) => void;
18
19
  }
19
20
  interface UseFileInstanceReturn {
@@ -23,6 +24,7 @@ interface UseFileInstanceReturn {
23
24
  declare function useFileInstance<LAnnotation>({
24
25
  file,
25
26
  options,
27
+ editorOptions,
26
28
  lineAnnotations,
27
29
  selectedLines,
28
30
  prerenderedHTML,
@@ -30,7 +32,7 @@ declare function useFileInstance<LAnnotation>({
30
32
  hasGutterRenderUtility,
31
33
  hasCustomHeader,
32
34
  disableWorkerPool,
33
- contentEditable
35
+ edit
34
36
  }: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn;
35
37
  //#endregion
36
38
  export { useFileInstance };
@@ -1 +1 @@
1
- {"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;UA2BU,oBAAA;EACR,IAAA,EAAM,YAAA;EACN,OAAA,EAAS,WAAA,CAAY,WAAA;EACrB,eAAA,EAAiB,cAAA,CAAe,WAAA;EAChC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,eAAA;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,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":";;;;;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,36 +1,32 @@
1
1
  import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
2
2
  import { File } from "../../components/File.js";
3
3
  import { VirtualizedFile } from "../../components/VirtualizedFile.js";
4
- import { noopRender } from "../constants.js";
5
4
  import { useStableCallback } from "./useStableCallback.js";
5
+ import { useCreateEditor } from "../EditContext.js";
6
+ import { noopRender } from "../constants.js";
6
7
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
7
- import { useEditor } from "../EditorContext.js";
8
8
  import { useVirtualizer } from "../Virtualizer.js";
9
9
  import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
10
10
  //#region src/react/utils/useFileInstance.ts
11
- const useIsometricEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
12
- function useFileInstance({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, contentEditable }) {
11
+ const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
12
+ function useFileInstance({ file, options, editorOptions, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, edit }) {
13
13
  const simpleVirtualizer = useVirtualizer();
14
14
  const controlledSelection = selectedLines !== void 0;
15
15
  const poolManager = useContext(WorkerPoolContext);
16
- const editor = useEditor();
16
+ const createEditor = useCreateEditor();
17
17
  const instanceRef = useRef(null);
18
18
  const ref = useStableCallback((node) => {
19
19
  if (node != null) {
20
20
  if (instanceRef.current != null) throw new Error("File: An instance should not already exist when a node is created");
21
21
  if (simpleVirtualizer != null) instanceRef.current = new VirtualizedFile(mergeFileOptions({
22
22
  controlledSelection,
23
- contentEditable,
24
23
  hasCustomHeader,
25
- hasEditor: editor !== void 0,
26
24
  hasGutterRenderUtility,
27
25
  options
28
26
  }), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
29
27
  else instanceRef.current = new File(mergeFileOptions({
30
28
  controlledSelection,
31
- contentEditable,
32
29
  hasCustomHeader,
33
- hasEditor: editor !== void 0,
34
30
  hasGutterRenderUtility,
35
31
  options
36
32
  }), !disableWorkerPool ? poolManager : void 0, true);
@@ -46,17 +42,15 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
46
42
  instanceRef.current = null;
47
43
  }
48
44
  });
49
- useIsometricEffect(() => {
45
+ useIsomorphicLayoutEffect(() => {
50
46
  if (instanceRef.current == null) return;
51
47
  const newOptions = mergeFileOptions({
52
48
  controlledSelection,
53
- contentEditable,
54
49
  hasCustomHeader,
55
- hasEditor: editor !== void 0,
56
50
  hasGutterRenderUtility,
57
51
  options
58
52
  });
59
- const forceRender = !areOptionsEqual(instanceRef.current.options, newOptions);
53
+ const forceRender = newOptions !== void 0 && !areOptionsEqual(instanceRef.current.options, newOptions);
60
54
  instanceRef.current.setOptions(newOptions);
61
55
  instanceRef.current.render({
62
56
  file,
@@ -65,12 +59,19 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
65
59
  });
66
60
  if (selectedLines !== void 0) instanceRef.current.setSelectedLines(selectedLines);
67
61
  });
68
- useIsometricEffect(() => {
69
- if (contentEditable && instanceRef.current != null) {
70
- if (editor === void 0) throw new Error("File: Editor is not attached");
71
- return editor.edit(instanceRef.current);
62
+ useIsomorphicLayoutEffect(() => {
63
+ if (edit && instanceRef.current != null) {
64
+ if (createEditor === void 0) throw new Error("File: EditContext is not attached");
65
+ const editor = createEditor(editorOptions ?? {});
66
+ if (editor == null) throw new Error("File: EditProvider.createEditor must return an editor instance");
67
+ try {
68
+ return editor.edit(instanceRef.current);
69
+ } catch (error) {
70
+ editor.cleanUp();
71
+ throw error;
72
+ }
72
73
  }
73
- }, [contentEditable, editor]);
74
+ }, [edit]);
74
75
  return {
75
76
  ref,
76
77
  getHoveredLine: useCallback(() => {
@@ -78,25 +79,14 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
78
79
  }, [])
79
80
  };
80
81
  }
81
- function mergeFileOptions({ options, controlledSelection, contentEditable, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
82
- const needsEditorOptions = contentEditable && hasEditor;
83
- const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
84
- if (!needsReactOverrides && !needsEditorOptions) return options;
85
- let merged = { ...options };
86
- if (needsReactOverrides) merged = {
87
- ...merged,
82
+ function mergeFileOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility }) {
83
+ if (!(controlledSelection || hasGutterRenderUtility || hasCustomHeader)) return options;
84
+ return {
85
+ ...options,
88
86
  controlledSelection,
89
87
  renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
90
88
  renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
91
89
  };
92
- if (needsEditorOptions) merged = {
93
- ...merged,
94
- useTokenTransformer: true,
95
- enableGutterUtility: false,
96
- enableLineSelection: false,
97
- lineHoverHighlight: "disabled"
98
- };
99
- return merged;
100
90
  }
101
91
  //#endregion
102
92
  export { useFileInstance };
@@ -1 +1 @@
1
- {"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { File, type FileOptions } from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useEditor } from '../EditorContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | 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 contentEditable: boolean;\n onChange?: (\n file: FileContents,\n lineAnnotations?: LineAnnotation<LAnnotation>[]\n ) => void;\n}\n\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function useFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n contentEditable,\n}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const editor = useEditor<LAnnotation>();\n const instanceRef = useRef<\n File<LAnnotation> | VirtualizedFile<LAnnotation> | null\n >(null);\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 contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\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 contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\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 }\n });\n\n useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(\n instanceRef.current.options,\n newOptions\n );\n instanceRef.current.setOptions(newOptions);\n void instanceRef.current.render({ file, lineAnnotations, forceRender });\n if (selectedLines !== undefined) {\n instanceRef.current.setSelectedLines(selectedLines);\n }\n });\n\n useIsometricEffect(() => {\n if (contentEditable && instanceRef.current != null) {\n if (editor === undefined) {\n throw new Error('File: Editor is not attached');\n }\n return editor.edit(instanceRef.current);\n }\n return undefined;\n }, [contentEditable, editor]);\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileOptionsProps<LAnnotation> {\n options: FileOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n contentEditable: boolean;\n hasEditor: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeFileOptions<LAnnotation>({\n options,\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor,\n hasGutterRenderUtility,\n}: MergeFileOptionsProps<LAnnotation>): FileOptions<LAnnotation> | undefined {\n const needsEditorOptions = contentEditable && hasEditor;\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides && !needsEditorOptions) {\n return options;\n }\n\n let merged: FileOptions<LAnnotation> = { ...options };\n\n if (needsReactOverrides) {\n merged = {\n ...merged,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\n }\n\n if (needsEditorOptions) {\n merged = {\n ...merged,\n useTokenTransformer: true,\n enableGutterUtility: false,\n enableLineSelection: false,\n lineHoverHighlight: 'disabled',\n };\n }\n\n return merged;\n}\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAwB9C,SAAgB,gBAA6B,EAC3C,MACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,mBAC2D;CAC3D,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,SAAS,UAAuB;CACtC,MAAM,cAAc,OAElB,IAAI;CACN,MAAM,MAAM,mBAAmB,SAA6B;EAC1D,IAAI,QAAQ,MAAM;GAChB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,mEACF;GAEF,IAAI,qBAAqB,MACvB,YAAY,UAAU,IAAI,gBACxB,iBAAiB;IACf;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,KACxB,iBAAiB;IACf;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;GAEF,YAAiB,QAAQ,QAAQ;IAC/B;IACA,eAAe;IACf;IACA;GACF,CAAC;EACH,OAAO;GACL,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MAAM,oDAAoD;GAEtE,YAAY,QAAQ,QAAQ;GAC5B,YAAY,UAAU;EACxB;CACF,CAAC;CAED,yBAAyB;EACvB,IAAI,YAAY,WAAW,MAAM;EACjC,MAAM,aAAa,iBAAiB;GAClC;GACA;GACA;GACA,WAAW,WAAW,KAAA;GACtB;GACA;EACF,CAAC;EACD,MAAM,cAAc,CAAC,gBACnB,YAAY,QAAQ,SACpB,UACF;EACA,YAAY,QAAQ,WAAW,UAAU;EACzC,YAAiB,QAAQ,OAAO;GAAE;GAAM;GAAiB;EAAY,CAAC;EACtE,IAAI,kBAAkB,KAAA,GACpB,YAAY,QAAQ,iBAAiB,aAAa;CAEtD,CAAC;CAED,yBAAyB;EACvB,IAAI,mBAAmB,YAAY,WAAW,MAAM;GAClD,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,8BAA8B;GAEhD,OAAO,OAAO,KAAK,YAAY,OAAO;EACxC;CAEF,GAAG,CAAC,iBAAiB,MAAM,CAAC;CAO5B,OAAO;EAAE;EAAK,gBALS,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CACuB;CAAE;AAC/B;AAWA,SAAS,iBAA8B,EACrC,SACA,qBACA,iBACA,iBACA,WACA,0BAC2E;CAC3E,MAAM,qBAAqB,mBAAmB;CAC9C,MAAM,sBACJ,uBAAuB,0BAA0B;CAEnD,IAAI,CAAC,uBAAuB,CAAC,oBAC3B,OAAO;CAGT,IAAI,SAAmC,EAAE,GAAG,QAAQ;CAEpD,IAAI,qBACF,SAAS;EACP,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;CACf;CAGF,IAAI,oBACF,SAAS;EACP,GAAG;EACH,qBAAqB;EACrB,qBAAqB;EACrB,qBAAqB;EACrB,oBAAoB;CACtB;CAGF,OAAO;AACT"}
1
+ {"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { File, type FileOptions } from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\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 UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | undefined;\n editorOptions: EditorOptions<LAnnotation> | 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 onChange?: (\n file: FileContents,\n lineAnnotations?: LineAnnotation<LAnnotation>[]\n ) => void;\n}\n\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function useFileInstance<LAnnotation>({\n file,\n options,\n editorOptions,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation>();\n const instanceRef = useRef<\n File<LAnnotation> | VirtualizedFile<LAnnotation> | null\n >(null);\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 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 options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\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 }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (instanceRef.current == null) return;\n const newOptions = mergeFileOptions({\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(instanceRef.current.options, newOptions);\n instanceRef.current.setOptions(newOptions);\n void instanceRef.current.render({ file, lineAnnotations, forceRender });\n if (selectedLines !== undefined) {\n instanceRef.current.setSelectedLines(selectedLines);\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (edit && instanceRef.current != null) {\n if (createEditor === undefined) {\n throw new Error('File: EditContext is not attached');\n }\n const editor = createEditor(editorOptions ?? {});\n if (editor == null) {\n throw new Error(\n 'File: 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<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileOptionsProps<LAnnotation> {\n options: FileOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeFileOptions<LAnnotation>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeFileOptionsProps<LAnnotation>): FileOptions<LAnnotation> | 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;AAyB9C,SAAgB,gBAA6B,EAC3C,MACA,SACA,eACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,QAC2D;CAC3D,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,SAA6B;EAC1D,IAAI,QAAQ,MAAM;GAChB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,mEACF;GAEF,IAAI,qBAAqB,MACvB,YAAY,UAAU,IAAI,gBACxB,iBAAiB;IACf;IACA;IACA;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,KACxB,iBAAiB;IACf;IACA;IACA;IACA;GACF,CAAC,GACD,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;GAEF,YAAiB,QAAQ,QAAQ;IAC/B;IACA,eAAe;IACf;IACA;GACF,CAAC;EACH,OAAO;GACL,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MAAM,oDAAoD;GAEtE,YAAY,QAAQ,QAAQ;GAC5B,YAAY,UAAU;EACxB;CACF,CAAC;CAED,gCAAgC;EAC9B,IAAI,YAAY,WAAW,MAAM;EACjC,MAAM,aAAa,iBAAiB;GAClC;GACA;GACA;GACA;EACF,CAAC;EAID,MAAM,cACJ,eAAe,KAAA,KACf,CAAC,gBAAgB,YAAY,QAAQ,SAAS,UAAU;EAC1D,YAAY,QAAQ,WAAW,UAAU;EACzC,YAAiB,QAAQ,OAAO;GAAE;GAAM;GAAiB;EAAY,CAAC;EACtE,IAAI,kBAAkB,KAAA,GACpB,YAAY,QAAQ,iBAAiB,aAAa;CAEtD,CAAC;CAED,gCAAgC;EAC9B,IAAI,QAAQ,YAAY,WAAW,MAAM;GACvC,IAAI,iBAAiB,KAAA,GACnB,MAAM,IAAI,MAAM,mCAAmC;GAErD,MAAM,SAAS,aAAa,iBAAiB,CAAC,CAAC;GAC/C,IAAI,UAAU,MACZ,MAAM,IAAI,MACR,gEACF;GAEF,IAAI;IACF,OAAO,OAAO,KAAK,YAAY,OAAO;GACxC,SAAS,OAAO;IACd,OAAO,QAAQ;IACf,MAAM;GACR;EACF;CAEF,GAAG,CAAC,IAAI,CAAC;CAOT,OAAO;EAAE;EAAK,gBALS,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CACuB;CAAE;AAC/B;AASA,SAAS,iBAA8B,EACrC,SACA,qBACA,iBACA,0BAC2E;CAI3E,IAAI,EAFF,uBAAuB,0BAA0B,kBAGjD,OAAO;CAGT,OAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;CACf;AACF"}