@pierre/diffs 1.2.5 → 1.3.0-beta.1

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 (153) hide show
  1. package/dist/components/CodeView.d.ts +0 -1
  2. package/dist/components/CodeView.d.ts.map +1 -1
  3. package/dist/components/CodeView.js +0 -23
  4. package/dist/components/CodeView.js.map +1 -1
  5. package/dist/components/File.d.ts +7 -2
  6. package/dist/components/File.d.ts.map +1 -1
  7. package/dist/components/File.js +36 -2
  8. package/dist/components/File.js.map +1 -1
  9. package/dist/components/FileDiff.d.ts +8 -2
  10. package/dist/components/FileDiff.d.ts.map +1 -1
  11. package/dist/components/FileDiff.js +73 -1
  12. package/dist/components/FileDiff.js.map +1 -1
  13. package/dist/components/UnresolvedFile.js +2 -2
  14. package/dist/components/VirtualizedFile.d.ts +2 -1
  15. package/dist/components/VirtualizedFile.d.ts.map +1 -1
  16. package/dist/components/VirtualizedFile.js +48 -48
  17. package/dist/components/VirtualizedFile.js.map +1 -1
  18. package/dist/components/VirtualizedFileDiff.js +1 -6
  19. package/dist/components/VirtualizedFileDiff.js.map +1 -1
  20. package/dist/components/Virtualizer.d.ts +1 -1
  21. package/dist/components/Virtualizer.d.ts.map +1 -1
  22. package/dist/components/Virtualizer.js.map +1 -1
  23. package/dist/editor/command.d.ts +6 -0
  24. package/dist/editor/command.d.ts.map +1 -0
  25. package/dist/editor/command.js +31 -0
  26. package/dist/editor/command.js.map +1 -0
  27. package/dist/editor/css.d.ts +6 -0
  28. package/dist/editor/css.d.ts.map +1 -0
  29. package/dist/editor/css.js +218 -0
  30. package/dist/editor/css.js.map +1 -0
  31. package/dist/editor/editStack.d.ts +66 -0
  32. package/dist/editor/editStack.d.ts.map +1 -0
  33. package/dist/editor/editStack.js +218 -0
  34. package/dist/editor/editStack.js.map +1 -0
  35. package/dist/editor/editor.d.ts +22 -0
  36. package/dist/editor/editor.d.ts.map +1 -0
  37. package/dist/editor/editor.js +1323 -0
  38. package/dist/editor/editor.js.map +1 -0
  39. package/dist/editor/index.d.ts +3 -0
  40. package/dist/editor/index.js +4 -0
  41. package/dist/editor/lineAnnotations.d.ts +8 -0
  42. package/dist/editor/lineAnnotations.d.ts.map +1 -0
  43. package/dist/editor/lineAnnotations.js +32 -0
  44. package/dist/editor/lineAnnotations.js.map +1 -0
  45. package/dist/editor/pieceTable.d.ts +33 -0
  46. package/dist/editor/pieceTable.d.ts.map +1 -0
  47. package/dist/editor/pieceTable.js +590 -0
  48. package/dist/editor/pieceTable.js.map +1 -0
  49. package/dist/editor/platform.d.ts +12 -0
  50. package/dist/editor/platform.d.ts.map +1 -0
  51. package/dist/editor/platform.js +44 -0
  52. package/dist/editor/platform.js.map +1 -0
  53. package/dist/editor/quickEdit.d.ts +29 -0
  54. package/dist/editor/quickEdit.d.ts.map +1 -0
  55. package/dist/editor/quickEdit.js +81 -0
  56. package/dist/editor/quickEdit.js.map +1 -0
  57. package/dist/editor/searchPanel.d.ts +30 -0
  58. package/dist/editor/searchPanel.d.ts.map +1 -0
  59. package/dist/editor/searchPanel.js +219 -0
  60. package/dist/editor/searchPanel.js.map +1 -0
  61. package/dist/editor/selection.d.ts +126 -0
  62. package/dist/editor/selection.d.ts.map +1 -0
  63. package/dist/editor/selection.js +900 -0
  64. package/dist/editor/selection.js.map +1 -0
  65. package/dist/editor/textDocument.d.ts +139 -0
  66. package/dist/editor/textDocument.d.ts.map +1 -0
  67. package/dist/editor/textDocument.js +202 -0
  68. package/dist/editor/textDocument.js.map +1 -0
  69. package/dist/editor/textMeasure.d.ts +32 -0
  70. package/dist/editor/textMeasure.d.ts.map +1 -0
  71. package/dist/editor/textMeasure.js +108 -0
  72. package/dist/editor/textMeasure.js.map +1 -0
  73. package/dist/editor/tokenzier.d.ts +37 -0
  74. package/dist/editor/tokenzier.d.ts.map +1 -0
  75. package/dist/editor/tokenzier.js +348 -0
  76. package/dist/editor/tokenzier.js.map +1 -0
  77. package/dist/editor/utils.d.ts +16 -0
  78. package/dist/editor/utils.d.ts.map +1 -0
  79. package/dist/editor/utils.js +37 -0
  80. package/dist/editor/utils.js.map +1 -0
  81. package/dist/index.d.ts +2 -2
  82. package/dist/index.js +2 -2
  83. package/dist/react/EditorContext.d.ts +16 -0
  84. package/dist/react/EditorContext.d.ts.map +1 -0
  85. package/dist/react/EditorContext.js +26 -0
  86. package/dist/react/EditorContext.js.map +1 -0
  87. package/dist/react/File.d.ts +2 -1
  88. package/dist/react/File.d.ts.map +1 -1
  89. package/dist/react/File.js +3 -2
  90. package/dist/react/File.js.map +1 -1
  91. package/dist/react/FileDiff.d.ts +3 -1
  92. package/dist/react/FileDiff.d.ts.map +1 -1
  93. package/dist/react/FileDiff.js +3 -2
  94. package/dist/react/FileDiff.js.map +1 -1
  95. package/dist/react/MultiFileDiff.d.ts +3 -1
  96. package/dist/react/MultiFileDiff.d.ts.map +1 -1
  97. package/dist/react/MultiFileDiff.js +3 -2
  98. package/dist/react/MultiFileDiff.js.map +1 -1
  99. package/dist/react/PatchDiff.d.ts +3 -1
  100. package/dist/react/PatchDiff.d.ts.map +1 -1
  101. package/dist/react/PatchDiff.js +3 -2
  102. package/dist/react/PatchDiff.js.map +1 -1
  103. package/dist/react/index.d.ts +3 -2
  104. package/dist/react/index.js +2 -1
  105. package/dist/react/jsx.d.ts +0 -1
  106. package/dist/react/jsx.d.ts.map +1 -1
  107. package/dist/react/types.d.ts +1 -0
  108. package/dist/react/types.d.ts.map +1 -1
  109. package/dist/react/types.js +0 -1
  110. package/dist/react/utils/useFileDiffInstance.d.ts +3 -1
  111. package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
  112. package/dist/react/utils/useFileDiffInstance.js +31 -5
  113. package/dist/react/utils/useFileDiffInstance.js.map +1 -1
  114. package/dist/react/utils/useFileInstance.d.ts +4 -1
  115. package/dist/react/utils/useFileInstance.d.ts.map +1 -1
  116. package/dist/react/utils/useFileInstance.js +30 -5
  117. package/dist/react/utils/useFileInstance.js.map +1 -1
  118. package/dist/renderers/DiffHunksRenderer.d.ts +2 -2
  119. package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
  120. package/dist/renderers/DiffHunksRenderer.js.map +1 -1
  121. package/dist/renderers/FileRenderer.d.ts +5 -1
  122. package/dist/renderers/FileRenderer.d.ts.map +1 -1
  123. package/dist/renderers/FileRenderer.js +108 -41
  124. package/dist/renderers/FileRenderer.js.map +1 -1
  125. package/dist/ssr/index.d.ts +2 -2
  126. package/dist/style.js +1 -1
  127. package/dist/style.js.map +1 -1
  128. package/dist/types.d.ts +45 -1
  129. package/dist/types.d.ts.map +1 -1
  130. package/dist/utils/cleanLastNewline.js +6 -1
  131. package/dist/utils/cleanLastNewline.js.map +1 -1
  132. package/dist/utils/computeFileOffsets.d.ts +13 -0
  133. package/dist/utils/computeFileOffsets.d.ts.map +1 -0
  134. package/dist/utils/computeFileOffsets.js +33 -0
  135. package/dist/utils/computeFileOffsets.js.map +1 -0
  136. package/dist/utils/createTransformerWithState.js +9 -0
  137. package/dist/utils/createTransformerWithState.js.map +1 -1
  138. package/dist/utils/renderDiffWithHighlighter.js +1 -1
  139. package/dist/utils/renderFileWithHighlighter.js +5 -14
  140. package/dist/utils/renderFileWithHighlighter.js.map +1 -1
  141. package/dist/worker/WorkerPoolManager.js +1 -1
  142. package/dist/worker/{wasm-BaDzIkIn.js → wasm-D4DU5jgR.js} +2 -2
  143. package/dist/worker/wasm-D4DU5jgR.js.map +1 -0
  144. package/dist/worker/worker-portable.js +138 -153
  145. package/dist/worker/worker-portable.js.map +1 -1
  146. package/dist/worker/worker.js +41 -64
  147. package/dist/worker/worker.js.map +1 -1
  148. package/package.json +28 -20
  149. package/dist/utils/iterateOverFile.d.ts +0 -50
  150. package/dist/utils/iterateOverFile.d.ts.map +0 -1
  151. package/dist/utils/iterateOverFile.js +0 -49
  152. package/dist/utils/iterateOverFile.js.map +0 -1
  153. package/dist/worker/wasm-BaDzIkIn.js.map +0 -1
@@ -4,28 +4,34 @@ import { VirtualizedFileDiff } from "../../components/VirtualizedFileDiff.js";
4
4
  import { noopRender } from "../constants.js";
5
5
  import { useStableCallback } from "./useStableCallback.js";
6
6
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
7
+ import { useEditor } from "../EditorContext.js";
7
8
  import { useVirtualizer } from "../Virtualizer.js";
8
9
  import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
9
10
 
10
11
  //#region src/react/utils/useFileDiffInstance.ts
11
12
  const useIsometricEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
12
- function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }) {
13
+ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, contentEditable }) {
13
14
  const simpleVirtualizer = useVirtualizer();
14
15
  const controlledSelection = selectedLines !== void 0;
15
16
  const poolManager = useContext(WorkerPoolContext);
17
+ const editor = useEditor();
16
18
  const instanceRef = useRef(null);
17
19
  const ref = useStableCallback((fileContainer) => {
18
20
  if (fileContainer != null) {
19
21
  if (instanceRef.current != null) throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");
20
22
  if (simpleVirtualizer != null) instanceRef.current = new VirtualizedFileDiff(mergeFileDiffOptions({
21
23
  controlledSelection,
24
+ contentEditable,
22
25
  hasCustomHeader,
26
+ hasEditor: editor !== void 0,
23
27
  hasGutterRenderUtility,
24
28
  options
25
29
  }), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
26
30
  else instanceRef.current = new FileDiff(mergeFileDiffOptions({
27
31
  controlledSelection,
32
+ contentEditable,
28
33
  hasCustomHeader,
34
+ hasEditor: editor !== void 0,
29
35
  hasGutterRenderUtility,
30
36
  options
31
37
  }), !disableWorkerPool ? poolManager : void 0, true);
@@ -46,7 +52,9 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
46
52
  if (instance == null) return;
47
53
  const newOptions = mergeFileDiffOptions({
48
54
  controlledSelection,
55
+ contentEditable,
49
56
  hasCustomHeader,
57
+ hasEditor: editor !== void 0,
50
58
  hasGutterRenderUtility,
51
59
  options
52
60
  });
@@ -59,6 +67,12 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
59
67
  });
60
68
  if (selectedLines !== void 0) instance.setSelectedLines(selectedLines);
61
69
  });
70
+ useIsometricEffect(() => {
71
+ if (contentEditable && instanceRef.current != null) {
72
+ if (editor === void 0) throw new Error("FileDiff: Editor is not attached");
73
+ return editor.edit(instanceRef.current);
74
+ }
75
+ }, [contentEditable, editor]);
62
76
  return {
63
77
  ref,
64
78
  getHoveredLine: useCallback(() => {
@@ -66,14 +80,26 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
66
80
  }, [])
67
81
  };
68
82
  }
69
- function mergeFileDiffOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility }) {
70
- if (!controlledSelection && !hasGutterRenderUtility && !hasCustomHeader) return options;
71
- return {
72
- ...options,
83
+ function mergeFileDiffOptions({ options, controlledSelection, contentEditable, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
84
+ const needsEditorOptions = contentEditable && hasEditor;
85
+ const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
86
+ if (!needsReactOverrides && !needsEditorOptions) return options;
87
+ let merged = { ...options };
88
+ if (needsReactOverrides) merged = {
89
+ ...merged,
73
90
  controlledSelection,
74
91
  renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
75
92
  renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
76
93
  };
94
+ if (needsEditorOptions) merged = {
95
+ ...merged,
96
+ useTokenTransformer: true,
97
+ enableGutterUtility: false,
98
+ enableLineSelection: false,
99
+ expandUnchanged: true,
100
+ lineHoverHighlight: "disabled"
101
+ };
102
+ return merged;
77
103
  }
78
104
 
79
105
  //#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 { 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}\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}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\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 useIsometricEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\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 const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return { ref, getHoveredLine };\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 if (!controlledSelection && !hasGutterRenderUtility && !hasCustomHeader) {\n return options;\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":";;;;;;;;;;AAuBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAmB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,qBACmE;CACnE,MAAM,oBAAoB,gBAAgB;CAC1C,MAAM,sBAAsB,kBAAkB;CAC9C,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,cAAc,OAElB,KAAK;CACP,MAAM,MAAM,mBAAmB,kBAAsC;AACnE,MAAI,iBAAiB,MAAM;AACzB,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,mFACD;AAEH,OAAI,qBAAqB,KACvB,aAAY,UAAU,IAAI,oBACxB,qBAAqB;IACnB;IACA;IACA;IACA;IACD,CAAC,EACF,mBACA,SACA,CAAC,oBAAoB,cAAc,QACnC,KACD;OAED,aAAY,UAAU,IAAI,SACxB,qBAAqB;IACnB;IACA;IACA;IACA;IACD,CAAC,EACF,CAAC,oBAAoB,cAAc,QACnC,KACD;AAEH,GAAK,YAAY,QAAQ,QAAQ;IAC/B;IACA;IACA;IACA;IACD,CAAC;SACG;AACL,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,wEACD;AAEH,eAAY,QAAQ,SAAS;AAC7B,eAAY,UAAU;;GAExB;AAEF,0BAAyB;EACvB,MAAM,EAAE,SAAS,aAAa;AAC9B,MAAI,YAAY,KAAM;EACtB,MAAM,aAAa,qBAAqB;GACtC;GACA;GACA;GACA;GACD,CAAC;EACF,MAAM,cAAc,CAAC,gBAAgB,SAAS,SAAS,WAAW;AAClE,WAAS,WAAW,WAAW;AAC/B,EAAK,SAAS,OAAO;GACnB;GACA;GACA;GACD,CAAC;AACF,MAAI,kBAAkB,OACpB,UAAS,iBAAiB,cAAc;GAE1C;AAQF,QAAO;EAAE;EAAK,gBANS,kBAEN;AACf,UAAO,YAAY,SAAS,gBAAgB;KAC3C,EAAE,CAAC;EAEwB;;AAUhC,SAAS,qBAAkC,EACzC,SACA,qBACA,iBACA,0BAGY;AACZ,KAAI,CAAC,uBAAuB,CAAC,0BAA0B,CAAC,gBACtD,QAAO;AAET,QAAO;EACL,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACd"}
1
+ {"version":3,"file":"useFileDiffInstance.js","names":["merged: FileDiffOptions<LAnnotation>"],"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 { ref, getHoveredLine };\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 let merged: FileDiffOptions<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 expandUnchanged: true,\n lineHoverHighlight: 'disabled',\n };\n }\n\n return merged;\n}\n"],"mappings":";;;;;;;;;;;AAwB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AAClD,OAAI,WAAW,OACb,OAAM,IAAI,MAAM,mCAAmC;AAErD,UAAO,OAAO,KAAK,YAAY,QAAQ;;IAGxC,CAAC,iBAAiB,OAAO,CAAC;AAQ7B,QAAO;EAAE;EAAK,gBANS,kBAEN;AACf,UAAO,YAAY,SAAS,gBAAgB;KAC3C,EAAE,CAAC;EAEwB;;AAYhC,SAAS,qBAAkC,EACzC,SACA,qBACA,iBACA,iBACA,WACA,0BAGY;CACZ,MAAM,qBAAqB,mBAAmB;CAC9C,MAAM,sBACJ,uBAAuB,0BAA0B;AAEnD,KAAI,CAAC,uBAAuB,CAAC,mBAC3B,QAAO;CAGT,IAAIA,SAAuC,EAAE,GAAG,SAAS;AAEzD,KAAI,oBACF,UAAS;EACP,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACd;AAGH,KAAI,mBACF,UAAS;EACP,GAAG;EACH,qBAAqB;EACrB,qBAAqB;EACrB,qBAAqB;EACrB,iBAAiB;EACjB,oBAAoB;EACrB;AAGH,QAAO"}
@@ -13,6 +13,8 @@ interface UseFileInstanceProps<LAnnotation> {
13
13
  hasGutterRenderUtility: boolean;
14
14
  hasCustomHeader: boolean;
15
15
  disableWorkerPool: boolean;
16
+ contentEditable: boolean;
17
+ onChange?: (file: FileContents, lineAnnotations?: LineAnnotation<LAnnotation>[]) => void;
16
18
  }
17
19
  interface UseFileInstanceReturn {
18
20
  ref(node: HTMLElement | null): void;
@@ -27,7 +29,8 @@ declare function useFileInstance<LAnnotation>({
27
29
  metrics,
28
30
  hasGutterRenderUtility,
29
31
  hasCustomHeader,
30
- disableWorkerPool
32
+ disableWorkerPool,
33
+ contentEditable
31
34
  }: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn;
32
35
  //#endregion
33
36
  export { useFileInstance };
@@ -1 +1 @@
1
- {"version":3,"file":"useFileInstance.d.ts","names":["FileOptions","GetHoveredLineResult","FileContents","LineAnnotation","SelectedLineRange","VirtualFileMetrics","UseFileInstanceProps","LAnnotation","UseFileInstanceReturn","HTMLElement","useFileInstance","file","options","lineAnnotations","selectedLines","prerenderedHTML","metrics","hasGutterRenderUtility","hasCustomHeader","disableWorkerPool"],"sources":["../../../src/react/utils/useFileInstance.d.ts"],"sourcesContent":["import { type FileOptions } from '../../components/File';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { FileContents, LineAnnotation, SelectedLineRange, VirtualFileMetrics } from '../../types';\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}\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\nexport declare function useFileInstance<LAnnotation>({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn;\nexport {};\n//# sourceMappingURL=useFileInstance.d.ts.map"],"mappings":";;;;;UAGUM;QACAJ;EADAI,OAAAA,EAEGN,WAFHM,CAEeC,WAFKA,CAAAA,GAAAA,SAAAA;EACpBL,eAAAA,EAEWC,cAFXD,CAE0BK,WAF1BL,CAAAA,EAAAA,GAAAA,SAAAA;EACeK,aAAAA,EAENH,iBAFMG,GAAAA,IAAAA,GAAAA,SAAAA;EAAZP,eAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EACuBO,OAAAA,CAAAA,EAGtBF,kBAHsBE;EAAfJ,sBAAAA,EAAAA,OAAAA;EACFC,eAAAA,EAAAA,OAAAA;EAELC,iBAAAA,EAAAA,OAAAA;;AAAkB,UAKtBG,qBAAAA,CAAqB;EAIPE,GAAAA,CAAAA,IAAAA,EAHVD,WAGyB,GAAA,IAAAF,CAAAA,EAAAA,IAAAA;EAAgBI,cAAAA,EAAAA,EAFjCV,oBAEiCU,CAAAA,MAAAA,CAAAA,GAAAA,SAAAA;;AAAeE,iBAA9CH,eAA8CG,CAAAA,WAAAA,CAAAA,CAAAA;EAAAA,IAAAA;EAAAA,OAAAA;EAAAA,eAAAA;EAAAA,aAAAA;EAAAA,eAAAA;EAAAA,OAAAA;EAAAA,sBAAAA;EAAAA,eAAAA;EAAAA;AAAAA,CAAAA,EAAwHP,oBAAxHO,CAA6IN,WAA7IM,CAAAA,CAAAA,EAA4JL,qBAA5JK"}
1
+ {"version":3,"file":"useFileInstance.d.ts","names":["FileOptions","GetHoveredLineResult","FileContents","LineAnnotation","SelectedLineRange","VirtualFileMetrics","UseFileInstanceProps","LAnnotation","UseFileInstanceReturn","HTMLElement","useFileInstance","file","options","lineAnnotations","selectedLines","prerenderedHTML","metrics","hasGutterRenderUtility","hasCustomHeader","disableWorkerPool","contentEditable"],"sources":["../../../src/react/utils/useFileInstance.d.ts"],"sourcesContent":["import { type FileOptions } from '../../components/File';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { FileContents, LineAnnotation, SelectedLineRange, VirtualFileMetrics } from '../../types';\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?: (file: FileContents, lineAnnotations?: LineAnnotation<LAnnotation>[]) => void;\n}\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\nexport declare function useFileInstance<LAnnotation>({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, contentEditable }: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn;\nexport {};\n//# sourceMappingURL=useFileInstance.d.ts.map"],"mappings":";;;;;UAGUM;QACAJ;EADAI,OAAAA,EAEGN,WAFHM,CAEeC,WAFKA,CAAAA,GAAAA,SAAAA;EACpBL,eAAAA,EAEWC,cAFXD,CAE0BK,WAF1BL,CAAAA,EAAAA,GAAAA,SAAAA;EACeK,aAAAA,EAENH,iBAFMG,GAAAA,IAAAA,GAAAA,SAAAA;EAAZP,eAAAA,EAAAA,MAAAA,GAAAA,SAAAA;EACuBO,OAAAA,CAAAA,EAGtBF,kBAHsBE;EAAfJ,sBAAAA,EAAAA,OAAAA;EACFC,eAAAA,EAAAA,OAAAA;EAELC,iBAAAA,EAAAA,OAAAA;EAKQH,eAAAA,EAAAA,OAAAA;EAA+CK,QAAAA,CAAAA,EAAAA,CAAAA,IAAAA,EAA/CL,YAA+CK,EAAAA,eAAAA,CAAAA,EAAfJ,cAAeI,CAAAA,WAAAA,CAAAA,EAAAA,EAAAA,GAAAA,IAAAA;;UAE3DC,qBAAAA,CAF0D;EAE1DA,GAAAA,CAAAA,IAAAA,EACIC,WADJD,GAAqB,IAAA,CAAA,EAAA,IAAA;EAIPE,cAAAA,EAAAA,EAFFT,oBAEiBM,CAAAA,MAAA,CAAA,GAAA,SAAA;;AAAsBK,iBAArCF,eAAqCE,CAAAA,WAAAA,CAAAA,CAAAA;EAAAA,IAAAA;EAAAA,OAAAA;EAAAA,eAAAA;EAAAA,aAAAA;EAAAA,eAAAA;EAAAA,OAAAA;EAAAA,sBAAAA;EAAAA,eAAAA;EAAAA,iBAAAA;EAAAA;AAAAA,CAAAA,EAAkJN,oBAAlJM,CAAuKL,WAAvKK,CAAAA,CAAAA,EAAsLJ,qBAAtLI"}
@@ -4,28 +4,34 @@ import { VirtualizedFile } from "../../components/VirtualizedFile.js";
4
4
  import { noopRender } from "../constants.js";
5
5
  import { useStableCallback } from "./useStableCallback.js";
6
6
  import { WorkerPoolContext } from "../WorkerPoolContext.js";
7
+ import { useEditor } from "../EditorContext.js";
7
8
  import { useVirtualizer } from "../Virtualizer.js";
8
9
  import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
9
10
 
10
11
  //#region src/react/utils/useFileInstance.ts
11
12
  const useIsometricEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
12
- function useFileInstance({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }) {
13
+ function useFileInstance({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, contentEditable }) {
13
14
  const simpleVirtualizer = useVirtualizer();
14
15
  const controlledSelection = selectedLines !== void 0;
15
16
  const poolManager = useContext(WorkerPoolContext);
17
+ const editor = useEditor();
16
18
  const instanceRef = useRef(null);
17
19
  const ref = useStableCallback((node) => {
18
20
  if (node != null) {
19
21
  if (instanceRef.current != null) throw new Error("File: An instance should not already exist when a node is created");
20
22
  if (simpleVirtualizer != null) instanceRef.current = new VirtualizedFile(mergeFileOptions({
21
23
  controlledSelection,
24
+ contentEditable,
22
25
  hasCustomHeader,
26
+ hasEditor: editor !== void 0,
23
27
  hasGutterRenderUtility,
24
28
  options
25
29
  }), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
26
30
  else instanceRef.current = new File(mergeFileOptions({
27
31
  controlledSelection,
32
+ contentEditable,
28
33
  hasCustomHeader,
34
+ hasEditor: editor !== void 0,
29
35
  hasGutterRenderUtility,
30
36
  options
31
37
  }), !disableWorkerPool ? poolManager : void 0, true);
@@ -45,7 +51,9 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
45
51
  if (instanceRef.current == null) return;
46
52
  const newOptions = mergeFileOptions({
47
53
  controlledSelection,
54
+ contentEditable,
48
55
  hasCustomHeader,
56
+ hasEditor: editor !== void 0,
49
57
  hasGutterRenderUtility,
50
58
  options
51
59
  });
@@ -58,6 +66,12 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
58
66
  });
59
67
  if (selectedLines !== void 0) instanceRef.current.setSelectedLines(selectedLines);
60
68
  });
69
+ useIsometricEffect(() => {
70
+ if (contentEditable && instanceRef.current != null) {
71
+ if (editor === void 0) throw new Error("File: Editor is not attached");
72
+ return editor.edit(instanceRef.current);
73
+ }
74
+ }, [contentEditable, editor]);
61
75
  return {
62
76
  ref,
63
77
  getHoveredLine: useCallback(() => {
@@ -65,14 +79,25 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
65
79
  }, [])
66
80
  };
67
81
  }
68
- function mergeFileOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility }) {
69
- if (!controlledSelection && !hasGutterRenderUtility && !hasCustomHeader) return options;
70
- return {
71
- ...options,
82
+ function mergeFileOptions({ options, controlledSelection, contentEditable, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
83
+ const needsEditorOptions = contentEditable && hasEditor;
84
+ const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
85
+ if (!needsReactOverrides && !needsEditorOptions) return options;
86
+ let merged = { ...options };
87
+ if (needsReactOverrides) merged = {
88
+ ...merged,
72
89
  controlledSelection,
73
90
  renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
74
91
  renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
75
92
  };
93
+ if (needsEditorOptions) merged = {
94
+ ...merged,
95
+ useTokenTransformer: true,
96
+ enableGutterUtility: false,
97
+ enableLineSelection: false,
98
+ lineHoverHighlight: "disabled"
99
+ };
100
+ return merged;
76
101
  }
77
102
 
78
103
  //#endregion
@@ -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 { 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}\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}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\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 useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\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 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 if (!controlledSelection && !hasGutterRenderUtility && !hasCustomHeader) {\n return options;\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":";;;;;;;;;;AAuBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAmB9C,SAAgB,gBAA6B,EAC3C,MACA,SACA,iBACA,eAC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AG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACd"}
1
+ {"version":3,"file":"useFileInstance.js","names":["merged: FileOptions<LAnnotation>"],"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,gBAAgB;CAC1C,MAAM,sBAAsB,kBAAkB;CAC9C,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,SAAS,WAAwB;CACvC,MAAM,cAAc,OAElB,KAAK;CACP,MAAM,MAAM,mBAAmB,SAA6B;AAC1D,MAAI,QAAQ,MAAM;AAChB,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MACR,oEACD;AAEH,OAAI,qBAAqB,KACvB,aAAY,UAAU,IAAI,gBACxB,iBAA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AAS;AAErD,KAAI,oBACF,UAAS;EACP,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;EACd;AAGH,KAAI,mBACF,UAAS;EACP,GAAG;EACH,qBAAqB;EACrB,qBAAqB;EACrB,qBAAqB;EACrB,oBAAoB;EACrB;AAGH,QAAO"}
@@ -1,4 +1,4 @@
1
- import { AnnotationSpan, BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from "../types.js";
1
+ import { AnnotationSpan, BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, DiffsHighlighter, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from "../types.js";
2
2
  import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
3
3
  import "../worker/index.js";
4
4
  import { DiffLineMetadata } from "../utils/iterateOverDiff.js";
@@ -103,7 +103,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
103
103
  protected getUnifiedInjectedRowsForLine?: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;
104
104
  protected getSplitInjectedRowsForLine?: (ctx: RenderedLineContext) => SplitInjectedRowPlacement | undefined;
105
105
  protected getOptionsWithDefaults(): DiffHunksRendererOptionsWithDefaults;
106
- private initializeHighlighter;
106
+ initializeHighlighter(): Promise<DiffsHighlighter>;
107
107
  hydrate(diff: FileDiffMetadata | undefined): void;
108
108
  private getRenderOptions;
109
109
  renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"DiffHunksRenderer.d.ts","names":["ElementContent","Element","HASTElement","Properties","AnnotationSpan","BaseDiffOptions","BaseDiffOptionsWithDefaults","CustomPreProperties","DiffLineAnnotation","ExpansionDirections","FileDiffMetadata","FileHeaderRenderMode","HunkData","HunkExpansionRegion","LineTypes","RenderDiffOptions","RenderRange","ThemedDiffResult","DiffLineMetadata","WorkerPoolManager","DiffHunksRendererOptions","DiffHunksRendererOptionsWithDefaults","Omit","UnifiedLineDecorationProps","SplitLineDecorationProps","LineDecoration","RenderedLineContext","InjectedRow","SplitInjectedRow","UnifiedInjectedRowPlacement","SplitInjectedRowPlacement","HunksRenderResult","DiffHunksRenderer","LAnnotation","Partial","Map","lineType","side","type","Promise"],"sources":["../../src/renderers/DiffHunksRenderer.d.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement, Properties } from 'hast';\nimport type { AnnotationSpan, BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from '../types';\nimport type { DiffLineMetadata } from '../utils/iterateOverDiff';\nimport type { WorkerPoolManager } from '../worker';\nexport interface DiffHunksRendererOptions extends BaseDiffOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\nexport interface DiffHunksRendererOptionsWithDefaults extends Omit<BaseDiffOptionsWithDefaults, 'themeType'> {\n headerRenderMode: FileHeaderRenderMode;\n}\nexport interface UnifiedLineDecorationProps {\n type: 'context' | 'context-expanded' | 'change';\n lineType: LineTypes;\n additionLineIndex: number | undefined;\n deletionLineIndex: number | undefined;\n}\nexport interface SplitLineDecorationProps {\n side: 'deletions' | 'additions';\n type: 'context' | 'context-expanded' | 'change';\n lineIndex: number | undefined;\n}\nexport interface LineDecoration {\n gutterLineType: LineTypes;\n gutterProperties?: Properties;\n contentProperties?: Properties;\n}\nexport interface RenderedLineContext {\n type: 'context' | 'context-expanded' | 'change';\n hunkIndex: number;\n lineIndex: number;\n unifiedLineIndex: number;\n splitLineIndex: number;\n deletionLine?: DiffLineMetadata;\n additionLine?: DiffLineMetadata;\n}\nexport interface InjectedRow {\n content: HASTElement;\n gutter: HASTElement;\n}\nexport interface SplitInjectedRow {\n deletion: InjectedRow | undefined;\n addition: InjectedRow | undefined;\n}\nexport interface UnifiedInjectedRowPlacement {\n before?: InjectedRow[];\n after?: InjectedRow[];\n}\nexport interface SplitInjectedRowPlacement {\n before?: SplitInjectedRow[];\n after?: SplitInjectedRow[];\n}\nexport interface HunksRenderResult {\n unifiedGutterAST: ElementContent[] | undefined;\n unifiedContentAST: ElementContent[] | undefined;\n deletionsGutterAST: ElementContent[] | undefined;\n deletionsContentAST: ElementContent[] | undefined;\n additionsGutterAST: ElementContent[] | undefined;\n additionsContentAST: ElementContent[] | undefined;\n hunkData: HunkData[];\n css: string;\n preNode: HASTElement;\n headerElement: HASTElement | undefined;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\nexport declare class DiffHunksRenderer<LAnnotation = undefined> {\n options: DiffHunksRendererOptions;\n private onRenderUpdate?;\n private workerManager?;\n readonly __id: string;\n private highlighter;\n private diff;\n private expandedHunks;\n private deletionAnnotations;\n private additionAnnotations;\n private computedLang;\n private renderCache;\n constructor(options?: DiffHunksRendererOptions, onRenderUpdate?: (() => unknown) | undefined, workerManager?: WorkerPoolManager | undefined);\n cleanUp(): void;\n recycle(): void;\n clearRenderCache(): void;\n setOptions(options: DiffHunksRendererOptions): void;\n mergeOptions(options: Partial<DiffHunksRendererOptions>): void;\n expandHunk(index: number, direction: ExpansionDirections, expansionLineCount?: number): void;\n getExpandedHunk(hunkIndex: number): HunkExpansionRegion;\n getExpandedHunksMap(): Map<number, HunkExpansionRegion>;\n setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void;\n protected getUnifiedLineDecoration({ lineType }: UnifiedLineDecorationProps): LineDecoration;\n protected getSplitLineDecoration({ side, type }: SplitLineDecorationProps): LineDecoration;\n protected createAnnotationElement(span: AnnotationSpan): HASTElement;\n protected getUnifiedInjectedRowsForLine?: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;\n protected getSplitInjectedRowsForLine?: (ctx: RenderedLineContext) => SplitInjectedRowPlacement | undefined;\n protected getOptionsWithDefaults(): DiffHunksRendererOptionsWithDefaults;\n private initializeHighlighter;\n hydrate(diff: FileDiffMetadata | undefined): void;\n private getRenderOptions;\n renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;\n asyncRender(diff: FileDiffMetadata, renderRange?: RenderRange): Promise<HunksRenderResult>;\n protected createPreElement(split: boolean, totalLines: number, customProperties?: CustomPreProperties): HASTElement;\n private asyncHighlight;\n private renderDiffWithHighlighter;\n onHighlightSuccess(diff: FileDiffMetadata, result: ThemedDiffResult, options: RenderDiffOptions, highlighted?: boolean): void;\n private getMatchingWorkerResultCache;\n private hasHighlightedRenderCache;\n onHighlightError(error: unknown): void;\n private getTokenizeMaxLength;\n private processDiffResult;\n renderCodeAST(type: 'unified' | 'deletions' | 'additions', result: HunksRenderResult): ElementContent[] | undefined;\n renderFullAST(result: HunksRenderResult, children?: ElementContent[]): HASTElement;\n renderFullHTML(result: HunksRenderResult, tempChildren?: ElementContent[]): string;\n renderPartialHTML(children: ElementContent[], columnType?: 'unified' | 'deletions' | 'additions'): string;\n private getAnnotations;\n private renderHeader;\n}\n//# sourceMappingURL=DiffHunksRenderer.d.ts.map"],"mappings":";;;;;;;UAIiBoB,wBAAAA,SAAiCf;qBAC3BM;;AADNS,UAGAC,oCAAAA,SAA6CC,IAHZjB,CAGiBC,2BAHF,EAAA,WAAA,CAAA,CAAA;EAGhDe,gBAAAA,EACKV,oBADLU;;AACKV,UAELY,0BAAAA,CAFKZ;EADwCW,IAAAA,EAAAA,SAAAA,GAAAA,kBAAAA,GAAAA,QAAAA;EAAI,QAAA,EAKpDR,SALoD;EAGjDS,iBAAAA,EAAAA,MAAAA,GAAAA,S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AA,SAAAA;EAAkC/B,OAAAA,CAAAA,CAAAA,EAAAA,IAAAA;EAC7BA,OAAAA,CAAAA,CAAAA,EAAAA,IAAAA;EAAc,gBAAA,CAAA,CAAA,EAAA,IAAA;sBA7BtBoB;wBACEc,QAAQd;uCACOX;sCACDI;yBACbsB,YAAYtB;sCACCL,mBAAmByB;;;KACNV,6BAA6BE;;;;KAC7BD,2BAA2BC;0CACpCrB,iBAAiBF;kDACTwB,wBAAwBG;gDAC1BH,wBAAwBI;sCAClCT;;gBAEtBX;;oBAEIA,4CAA4CM,cAAce;oBAC1DrB,gCAAgCM,cAAcuB,QAAQR;oFACUxB,sBAAsBL;;;2BAG/EQ,0BAA0BO,2BAA2BF;;;;;;qEAMXgB,oBAAoB/B;wBACjE+B,8BAA8B/B,mBAAmBE;yBAChD6B,kCAAkC/B;8BAC7BA"}
1
+ {"version":3,"file":"DiffHunksRenderer.d.ts","names":["ElementContent","Element","HASTElement","Properties","AnnotationSpan","BaseDiffOptions","BaseDiffOptionsWithDefaults","CustomPreProperties","DiffLineAnnotation","DiffsHighlighter","ExpansionDirections","FileDiffMetadata","FileHeaderRenderMode","HunkData","HunkExpansionRegion","LineTypes","RenderDiffOptions","RenderRange","ThemedDiffResult","DiffLineMetadata","WorkerPoolManager","DiffHunksRendererOptions","DiffHunksRendererOptionsWithDefaults","Omit","UnifiedLineDecorationProps","SplitLineDecorationProps","LineDecoration","RenderedLineContext","InjectedRow","SplitInjectedRow","UnifiedInjectedRowPlacement","SplitInjectedRowPlacement","HunksRenderResult","DiffHunksRenderer","LAnnotation","Partial","Map","lineType","side","type","Promise"],"sources":["../../src/renderers/DiffHunksRenderer.d.ts"],"sourcesContent":["import type { ElementContent, Element as HASTElement, Properties } from 'hast';\nimport type { AnnotationSpan, BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, DiffsHighlighter, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from '../types';\nimport type { DiffLineMetadata } from '../utils/iterateOverDiff';\nimport type { WorkerPoolManager } from '../worker';\nexport interface DiffHunksRendererOptions extends BaseDiffOptions {\n headerRenderMode?: FileHeaderRenderMode;\n}\nexport interface DiffHunksRendererOptionsWithDefaults extends Omit<BaseDiffOptionsWithDefaults, 'themeType'> {\n headerRenderMode: FileHeaderRenderMode;\n}\nexport interface UnifiedLineDecorationProps {\n type: 'context' | 'context-expanded' | 'change';\n lineType: LineTypes;\n additionLineIndex: number | undefined;\n deletionLineIndex: number | undefined;\n}\nexport interface SplitLineDecorationProps {\n side: 'deletions' | 'additions';\n type: 'context' | 'context-expanded' | 'change';\n lineIndex: number | undefined;\n}\nexport interface LineDecoration {\n gutterLineType: LineTypes;\n gutterProperties?: Properties;\n contentProperties?: Properties;\n}\nexport interface RenderedLineContext {\n type: 'context' | 'context-expanded' | 'change';\n hunkIndex: number;\n lineIndex: number;\n unifiedLineIndex: number;\n splitLineIndex: number;\n deletionLine?: DiffLineMetadata;\n additionLine?: DiffLineMetadata;\n}\nexport interface InjectedRow {\n content: HASTElement;\n gutter: HASTElement;\n}\nexport interface SplitInjectedRow {\n deletion: InjectedRow | undefined;\n addition: InjectedRow | undefined;\n}\nexport interface UnifiedInjectedRowPlacement {\n before?: InjectedRow[];\n after?: InjectedRow[];\n}\nexport interface SplitInjectedRowPlacement {\n before?: SplitInjectedRow[];\n after?: SplitInjectedRow[];\n}\nexport interface HunksRenderResult {\n unifiedGutterAST: ElementContent[] | undefined;\n unifiedContentAST: ElementContent[] | undefined;\n deletionsGutterAST: ElementContent[] | undefined;\n deletionsContentAST: ElementContent[] | undefined;\n additionsGutterAST: ElementContent[] | undefined;\n additionsContentAST: ElementContent[] | undefined;\n hunkData: HunkData[];\n css: string;\n preNode: HASTElement;\n headerElement: HASTElement | undefined;\n totalLines: number;\n themeStyles: string;\n baseThemeType: 'light' | 'dark' | undefined;\n rowCount: number;\n bufferBefore: number;\n bufferAfter: number;\n}\nexport declare class DiffHunksRenderer<LAnnotation = undefined> {\n options: DiffHunksRendererOptions;\n private onRenderUpdate?;\n private workerManager?;\n readonly __id: string;\n private highlighter;\n private diff;\n private expandedHunks;\n private deletionAnnotations;\n private additionAnnotations;\n private computedLang;\n private renderCache;\n constructor(options?: DiffHunksRendererOptions, onRenderUpdate?: (() => unknown) | undefined, workerManager?: WorkerPoolManager | undefined);\n cleanUp(): void;\n recycle(): void;\n clearRenderCache(): void;\n setOptions(options: DiffHunksRendererOptions): void;\n mergeOptions(options: Partial<DiffHunksRendererOptions>): void;\n expandHunk(index: number, direction: ExpansionDirections, expansionLineCount?: number): void;\n getExpandedHunk(hunkIndex: number): HunkExpansionRegion;\n getExpandedHunksMap(): Map<number, HunkExpansionRegion>;\n setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void;\n protected getUnifiedLineDecoration({ lineType }: UnifiedLineDecorationProps): LineDecoration;\n protected getSplitLineDecoration({ side, type }: SplitLineDecorationProps): LineDecoration;\n protected createAnnotationElement(span: AnnotationSpan): HASTElement;\n protected getUnifiedInjectedRowsForLine?: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;\n protected getSplitInjectedRowsForLine?: (ctx: RenderedLineContext) => SplitInjectedRowPlacement | undefined;\n protected getOptionsWithDefaults(): DiffHunksRendererOptionsWithDefaults;\n initializeHighlighter(): Promise<DiffsHighlighter>;\n hydrate(diff: FileDiffMetadata | undefined): void;\n private getRenderOptions;\n renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;\n asyncRender(diff: FileDiffMetadata, renderRange?: RenderRange): Promise<HunksRenderResult>;\n protected createPreElement(split: boolean, totalLines: number, customProperties?: CustomPreProperties): HASTElement;\n private asyncHighlight;\n private renderDiffWithHighlighter;\n onHighlightSuccess(diff: FileDiffMetadata, result: ThemedDiffResult, options: RenderDiffOptions, highlighted?: boolean): void;\n private getMatchingWorkerResultCache;\n private hasHighlightedRenderCache;\n onHighlightError(error: unknown): void;\n private getTokenizeMaxLength;\n private processDiffResult;\n renderCodeAST(type: 'unified' | 'deletions' | 'additions', result: HunksRenderResult): ElementContent[] | undefined;\n renderFullAST(result: HunksRenderResult, children?: ElementContent[]): HASTElement;\n renderFullHTML(result: HunksRenderResult, tempChildren?: ElementContent[]): string;\n renderPartialHTML(children: ElementContent[], columnType?: 'unified' | 'deletions' | 'additions'): string;\n private getAnnotations;\n private renderHeader;\n}\n//# sourceMappingURL=DiffHunksRenderer.d.ts.map"],"mappings":";;;;;;;UAIiBqB,wBAAAA,SAAiChB;qBAC3BO;;AADNS,UAGAC,oCAAAA,SAA6CC,IAHZlB,CAGiBC,2BAHF,EAAA,WAAA,CAAA,CAAA;EAGhDgB,gBAAAA,EACKV,oBADLU;;AACKV,UAELY,0BAAAA,CAFKZ;EADwCW,IAAAA,EAAAA,SAAAA,GAAAA,kBAAAA,GAAAA,QAAAA;EAAI,QAAA,EAKpDR,SALoD;EAGjDS,iBAAAA,EAAAA,MAAAA,GAAAA,SAA0B;EAM1BC,iBAAAA,EAAAA,MAAAA,GAAwB,SAAA;AAKzC;AACoBV,UANHU,wBAAAA,CAMGV;EACGZ,IAAAA,EAAAA,WAAAA,GAAAA,WAAAA;EACCA,IAAAA,EAAAA,SAAAA,GAAAA,kBAAAA,GAAAA,QAAAA;EAAU,SAAA,EAAA,MAAA,GAAA,SAAA;AAElC;AASiByB,UAdAF,cAAAA,CAeJxB;EAGI2B,cAAAA,EAjBGd,SAiBa;EAIhBe,gBAAAA,CAAAA,EApBM3B,UAoBN2B;EAIAC,iBAAAA,CAAAA,EAvBO5B,UAuBkB;AAI1C;AACsBH,UA1BL2B,mBAAAA,CA0BK3B;EACCA,IAAAA,EAAAA,SAAAA,GAAAA,kBAAAA,GAAAA,QAAAA;EACCA,SAAAA,EAAAA,MAAAA;EACCA,SAAAA,EAAAA,MAAAA;EACDA,gBAAAA,EAAAA,MAAAA;EACCA,cAAAA,EA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