@pierre/diffs 1.2.6 → 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.
- package/dist/components/CodeView.d.ts +0 -1
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +0 -23
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +7 -2
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +36 -2
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +8 -2
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +73 -1
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +2 -2
- package/dist/components/VirtualizedFile.d.ts +2 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +48 -48
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +42 -22
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/Virtualizer.d.ts +1 -1
- package/dist/components/Virtualizer.d.ts.map +1 -1
- package/dist/components/Virtualizer.js +3 -5
- package/dist/components/Virtualizer.js.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/editor/command.d.ts +6 -0
- package/dist/editor/command.d.ts.map +1 -0
- package/dist/editor/command.js +31 -0
- package/dist/editor/command.js.map +1 -0
- package/dist/editor/css.d.ts +6 -0
- package/dist/editor/css.d.ts.map +1 -0
- package/dist/editor/css.js +218 -0
- package/dist/editor/css.js.map +1 -0
- package/dist/editor/editStack.d.ts +66 -0
- package/dist/editor/editStack.d.ts.map +1 -0
- package/dist/editor/editStack.js +218 -0
- package/dist/editor/editStack.js.map +1 -0
- package/dist/editor/editor.d.ts +22 -0
- package/dist/editor/editor.d.ts.map +1 -0
- package/dist/editor/editor.js +1323 -0
- package/dist/editor/editor.js.map +1 -0
- package/dist/editor/index.d.ts +3 -0
- package/dist/editor/index.js +4 -0
- package/dist/editor/lineAnnotations.d.ts +8 -0
- package/dist/editor/lineAnnotations.d.ts.map +1 -0
- package/dist/editor/lineAnnotations.js +32 -0
- package/dist/editor/lineAnnotations.js.map +1 -0
- package/dist/editor/pieceTable.d.ts +33 -0
- package/dist/editor/pieceTable.d.ts.map +1 -0
- package/dist/editor/pieceTable.js +590 -0
- package/dist/editor/pieceTable.js.map +1 -0
- package/dist/editor/platform.d.ts +12 -0
- package/dist/editor/platform.d.ts.map +1 -0
- package/dist/editor/platform.js +44 -0
- package/dist/editor/platform.js.map +1 -0
- package/dist/editor/quickEdit.d.ts +29 -0
- package/dist/editor/quickEdit.d.ts.map +1 -0
- package/dist/editor/quickEdit.js +81 -0
- package/dist/editor/quickEdit.js.map +1 -0
- package/dist/editor/searchPanel.d.ts +30 -0
- package/dist/editor/searchPanel.d.ts.map +1 -0
- package/dist/editor/searchPanel.js +219 -0
- package/dist/editor/searchPanel.js.map +1 -0
- package/dist/editor/selection.d.ts +126 -0
- package/dist/editor/selection.d.ts.map +1 -0
- package/dist/editor/selection.js +900 -0
- package/dist/editor/selection.js.map +1 -0
- package/dist/editor/textDocument.d.ts +139 -0
- package/dist/editor/textDocument.d.ts.map +1 -0
- package/dist/editor/textDocument.js +202 -0
- package/dist/editor/textDocument.js.map +1 -0
- package/dist/editor/textMeasure.d.ts +32 -0
- package/dist/editor/textMeasure.d.ts.map +1 -0
- package/dist/editor/textMeasure.js +108 -0
- package/dist/editor/textMeasure.js.map +1 -0
- package/dist/editor/tokenzier.d.ts +37 -0
- package/dist/editor/tokenzier.d.ts.map +1 -0
- package/dist/editor/tokenzier.js +348 -0
- package/dist/editor/tokenzier.js.map +1 -0
- package/dist/editor/utils.d.ts +16 -0
- package/dist/editor/utils.d.ts.map +1 -0
- package/dist/editor/utils.js +37 -0
- package/dist/editor/utils.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/react/EditorContext.d.ts +16 -0
- package/dist/react/EditorContext.d.ts.map +1 -0
- package/dist/react/EditorContext.js +26 -0
- package/dist/react/EditorContext.js.map +1 -0
- package/dist/react/File.d.ts +2 -1
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +3 -2
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +3 -1
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +3 -2
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +3 -1
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +3 -2
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +3 -1
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +3 -2
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +2 -1
- package/dist/react/jsx.d.ts +0 -1
- package/dist/react/jsx.d.ts.map +1 -1
- package/dist/react/types.d.ts +1 -0
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/types.js +0 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +3 -1
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +31 -5
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +4 -1
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +30 -5
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +2 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +9 -5
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +5 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +108 -41
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +45 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/cleanLastNewline.js +6 -1
- package/dist/utils/cleanLastNewline.js.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.js +20 -9
- package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
- package/dist/utils/computeFileOffsets.d.ts +13 -0
- package/dist/utils/computeFileOffsets.d.ts.map +1 -0
- package/dist/utils/computeFileOffsets.js +33 -0
- package/dist/utils/computeFileOffsets.js.map +1 -0
- package/dist/utils/createTransformerWithState.js +9 -0
- package/dist/utils/createTransformerWithState.js.map +1 -1
- package/dist/utils/iterateOverDiff.js +182 -147
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/renderDiffWithHighlighter.js +1 -1
- package/dist/utils/renderFileWithHighlighter.js +5 -14
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/virtualDiffLayout.d.ts +2 -23
- package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
- package/dist/utils/virtualDiffLayout.js +1 -41
- package/dist/utils/virtualDiffLayout.js.map +1 -1
- package/dist/worker/WorkerPoolManager.js +1 -1
- package/dist/worker/{wasm-BaDzIkIn.js → wasm-D4DU5jgR.js} +2 -2
- package/dist/worker/wasm-D4DU5jgR.js.map +1 -0
- package/dist/worker/worker-portable.js +349 -363
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +222 -243
- package/dist/worker/worker.js.map +1 -1
- package/package.json +9 -1
- package/dist/utils/iterateOverFile.d.ts +0 -50
- package/dist/utils/iterateOverFile.d.ts.map +0 -1
- package/dist/utils/iterateOverFile.js +0 -49
- package/dist/utils/iterateOverFile.js.map +0 -1
- 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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
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":";;;;;;;;;;;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,gBAAgB;CAC1C,MAAM,sBAAsB,kBAAkB;CAC9C,MAAM,cAAc,WAAW,kBAAkB;CACjD,MAAM,SAAS,WAAwB;CACvC,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,WAAW,WAAW;IACtB;IACA;IACD,CAAC,EACF,mBACA,SACA,CAAC,oBAAoB,cAAc,QACnC,KACD;OAED,aAAY,UAAU,IAAI,SACxB,qBAAqB;IACnB;IACA;IACA;IACA,WAAW,WAAW;IACtB;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,WAAW,WAAW;GACtB;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;AAEF,0BAAyB;AACvB,MAAI,mBAAmB,YAAY,WAAW,MAAM;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
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
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,iBAAiB;IACf;IACA;IACA;IACA,WAAW,WAAW;IACtB;IACA;IACD,CAAC,EACF,mBACA,SACA,CAAC,oBAAoB,cAAc,QACnC,KACD;OAED,aAAY,UAAU,IAAI,KACxB,iBAAiB;IACf;IACA;IACA;IACA,WAAW,WAAW;IACtB;IACA;IACD,CAAC,EACF,CAAC,oBAAoB,cAAc,QACnC,KACD;AAEH,GAAK,YAAY,QAAQ,QAAQ;IAC/B;IACA,eAAe;IACf;IACA;IACD,CAAC;SACG;AACL,OAAI,YAAY,WAAW,KACzB,OAAM,IAAI,MAAM,qDAAqD;AAEvE,eAAY,QAAQ,SAAS;AAC7B,eAAY,UAAU;;GAExB;AAEF,0BAAyB;AACvB,MAAI,YAAY,WAAW,KAAM;EACjC,MAAM,aAAa,iBAAiB;GAClC;GACA;GACA;GACA,WAAW,WAAW;GACtB;GACA;GACD,CAAC;EACF,MAAM,cAAc,CAAC,gBACnB,YAAY,QAAQ,SACpB,WACD;AACD,cAAY,QAAQ,WAAW,WAAW;AAC1C,EAAK,YAAY,QAAQ,OAAO;GAAE;GAAM;GAAiB;GAAa,CAAC;AACvE,MAAI,kBAAkB,OACpB,aAAY,QAAQ,iBAAiB,cAAc;GAErD;AAEF,0BAAyB;AACvB,MAAI,mBAAmB,YAAY,WAAW,MAAM;AAClD,OAAI,WAAW,OACb,OAAM,IAAI,MAAM,+BAA+B;AAEjD,UAAO,OAAO,KAAK,YAAY,QAAQ;;IAGxC,CAAC,iBAAiB,OAAO,CAAC;AAO7B,QAAO;EAAE;EAAK,gBALS,kBAEN;AACf,UAAO,YAAY,SAAS,gBAAgB;KAC3C,EAAE,CAAC;EACwB;;AAYhC,SAAS,iBAA8B,EACrC,SACA,qBACA,iBACA,iBACA,WACA,0BAC2E;CAC3E,MAAM,qBAAqB,mBAAmB;CAC9C,MAAM,sBACJ,uBAAuB,0BAA0B;AAEnD,KAAI,CAAC,uBAAuB,CAAC,mBAC3B,QAAO;CAGT,IAAIA,SAAmC,EAAE,GAAG,SAAS;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
|
-
|
|
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
|
|
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":"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"}
|
|
@@ -13,7 +13,6 @@ import { getHighlighterOptions } from "../utils/getHighlighterOptions.js";
|
|
|
13
13
|
import { getLineAnnotationName } from "../utils/getLineAnnotationName.js";
|
|
14
14
|
import { shouldUseTokenTransformer } from "../utils/shouldUseTokenTransformer.js";
|
|
15
15
|
import { areDiffTargetsEqual } from "../utils/areDiffTargetsEqual.js";
|
|
16
|
-
import { getTrailingContextRangeSize } from "../utils/virtualDiffLayout.js";
|
|
17
16
|
import { iterateOverDiff } from "../utils/iterateOverDiff.js";
|
|
18
17
|
import { areDiffRenderOptionsEqual } from "../utils/areDiffRenderOptionsEqual.js";
|
|
19
18
|
import { createEmptyRowBuffer } from "../utils/createEmptyRowBuffer.js";
|
|
@@ -345,10 +344,7 @@ var DiffHunksRenderer = class {
|
|
|
345
344
|
}
|
|
346
345
|
}
|
|
347
346
|
};
|
|
348
|
-
const trailingRangeSize =
|
|
349
|
-
fileDiff,
|
|
350
|
-
errorPrefix: "DiffHunksRenderer.processDiffResult"
|
|
351
|
-
});
|
|
347
|
+
const trailingRangeSize = calculateTrailingRangeSize(fileDiff);
|
|
352
348
|
const pendingSplitContext = {
|
|
353
349
|
size: 0,
|
|
354
350
|
side: void 0,
|
|
@@ -819,6 +815,14 @@ function withContentProperties(lineNode, contentProperties) {
|
|
|
819
815
|
function isDiffMassive(diff, tokenizeMaxLength) {
|
|
820
816
|
return Math.max(diff.additionLines.length, diff.deletionLines.length) > tokenizeMaxLength;
|
|
821
817
|
}
|
|
818
|
+
function calculateTrailingRangeSize(fileDiff) {
|
|
819
|
+
const lastHunk = fileDiff.hunks.at(-1);
|
|
820
|
+
if (lastHunk == null || fileDiff.isPartial || fileDiff.additionLines.length === 0 || fileDiff.deletionLines.length === 0) return 0;
|
|
821
|
+
const additionRemaining = fileDiff.additionLines.length - (lastHunk.additionLineIndex + lastHunk.additionCount);
|
|
822
|
+
const deletionRemaining = fileDiff.deletionLines.length - (lastHunk.deletionLineIndex + lastHunk.deletionCount);
|
|
823
|
+
if (additionRemaining !== deletionRemaining) throw new Error(`DiffHunksRenderer.processDiffResult: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${fileDiff.name}`);
|
|
824
|
+
return Math.min(additionRemaining, deletionRemaining);
|
|
825
|
+
}
|
|
822
826
|
|
|
823
827
|
//#endregion
|
|
824
828
|
export { DiffHunksRenderer };
|