@pierre/diffs 1.6.0-beta.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeView.d.ts +3 -2
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +18 -14
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +31 -9
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +165 -84
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +32 -9
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +213 -124
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +14 -4
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +35 -16
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +3 -2
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +28 -20
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +3 -2
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +31 -24
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -1
- package/dist/constants.js.map +1 -1
- package/dist/editor/platform.d.ts +1 -1
- package/dist/editor/platform.js +5 -4
- package/dist/editor/platform.js.map +1 -1
- package/dist/editor/selection.d.ts +2 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +31 -6
- package/dist/editor/selection.js.map +1 -1
- package/dist/highlighter/shared_highlighter.d.ts +2 -1
- package/dist/highlighter/shared_highlighter.d.ts.map +1 -1
- package/dist/highlighter/shared_highlighter.js +2 -2
- package/dist/highlighter/shared_highlighter.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.js +8 -3
- package/dist/react/CodeView.d.ts +4 -3
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +48 -39
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/File.js +3 -3
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.js +3 -3
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.js +2 -2
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.js +3 -3
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.js +2 -2
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/types.d.ts +4 -2
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +1 -1
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.js +1 -1
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +1 -0
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +29 -24
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +2 -0
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +38 -28
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useForceUpdate.d.ts +5 -0
- package/dist/react/utils/useForceUpdate.d.ts.map +1 -0
- package/dist/react/utils/useForceUpdate.js +27 -0
- package/dist/react/utils/useForceUpdate.js.map +1 -0
- package/dist/react/utils/useNextRenderData.d.ts +9 -0
- package/dist/react/utils/useNextRenderData.d.ts.map +1 -0
- package/dist/react/utils/useNextRenderData.js +9 -0
- package/dist/react/utils/useNextRenderData.js.map +1 -0
- package/dist/react/utils/useUnresolvedFileInstance.d.ts +1 -0
- package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +26 -11
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +2 -1
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +62 -32
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +4 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +55 -30
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/ssr/FileDiffReact.js +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/canUseWASM.d.ts +13 -0
- package/dist/utils/canUseWASM.d.ts.map +1 -0
- package/dist/utils/canUseWASM.js +59 -0
- package/dist/utils/canUseWASM.js.map +1 -0
- package/dist/utils/getCodeViewItemRenderData.d.ts +10 -0
- package/dist/utils/getCodeViewItemRenderData.d.ts.map +1 -0
- package/dist/utils/getCodeViewItemRenderData.js +19 -0
- package/dist/utils/getCodeViewItemRenderData.js.map +1 -0
- package/dist/utils/hastToHtml.d.ts +2 -2
- package/dist/utils/hastToHtml.js +2 -2
- package/dist/utils/hastToHtml.js.map +1 -1
- package/dist/utils/hydratePartialDiff.js +4 -0
- package/dist/utils/hydratePartialDiff.js.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.js +2 -0
- package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +24 -4
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/renderTokenLines.d.ts +6 -1
- package/dist/utils/renderTokenLines.d.ts.map +1 -1
- package/dist/utils/renderTokenLines.js +4 -0
- package/dist/utils/renderTokenLines.js.map +1 -1
- package/dist/utils/resolveRegion.js +20 -10
- package/dist/utils/resolveRegion.js.map +1 -1
- package/dist/utils/tokenStyle.d.ts +5 -1
- package/dist/utils/tokenStyle.d.ts.map +1 -1
- package/dist/utils/tokenStyle.js +5 -1
- package/dist/utils/tokenStyle.js.map +1 -1
- package/dist/utils/tokensToHtml.d.ts +5 -2
- package/dist/utils/tokensToHtml.d.ts.map +1 -1
- package/dist/utils/tokensToHtml.js +5 -2
- package/dist/utils/tokensToHtml.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +2 -2
- package/dist/utils/updateDiffHunks.d.ts.map +1 -1
- package/dist/utils/updateDiffHunks.js +7 -3
- package/dist/utils/updateDiffHunks.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +12 -0
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +99 -21
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/{highlights-sAHlxqlf.js → highlights-CpZm9DAR.js} +2 -2
- package/dist/worker/{highlights-sAHlxqlf.js.map → highlights-CpZm9DAR.js.map} +1 -1
- package/dist/worker/{shiki-Bx2JpdqZ.js → shiki-Ci4cdHsM.js} +2 -2
- package/dist/worker/{shiki-Bx2JpdqZ.js.map → shiki-Ci4cdHsM.js.map} +1 -1
- package/dist/worker/{stream-tokenizer-YZ6M1qSx.js → stream-tokenizer-DK9xp5M5.js} +8 -5
- package/dist/worker/stream-tokenizer-DK9xp5M5.js.map +1 -0
- package/dist/worker/types.d.ts +11 -0
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +2 -2
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +12 -3
- package/dist/worker/worker.js.map +1 -1
- package/package.json +28 -30
- package/dist/worker/stream-tokenizer-YZ6M1qSx.js.map +0 -1
package/dist/react/File.js
CHANGED
|
@@ -6,7 +6,7 @@ import { useFileInstance } from "./utils/useFileInstance.js";
|
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/react/File.tsx
|
|
8
8
|
function File({ file, lineAnnotations, selectedLines, options, editorOptions, editStateKey, metrics, className, style, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, prerenderedHTML, renderGutterUtility, disableWorkerPool = false, edit = false, onEditChange, onEditComplete }) {
|
|
9
|
-
const { ref, getHoveredLine, getAnnotationSlotName } = useFileInstance({
|
|
9
|
+
const { ref, getHoveredLine, getAnnotationSlotName, file: renderedFile, lineAnnotations: renderedAnnotations } = useFileInstance({
|
|
10
10
|
file,
|
|
11
11
|
options,
|
|
12
12
|
editorOptions,
|
|
@@ -23,14 +23,14 @@ function File({ file, lineAnnotations, selectedLines, options, editorOptions, ed
|
|
|
23
23
|
onEditComplete
|
|
24
24
|
});
|
|
25
25
|
const children = renderFileChildren({
|
|
26
|
-
file,
|
|
26
|
+
file: renderedFile,
|
|
27
27
|
renderAnnotation,
|
|
28
28
|
renderCustomHeader,
|
|
29
29
|
renderHeaderPrefix,
|
|
30
30
|
renderHeaderFilenameSuffix,
|
|
31
31
|
renderHeaderMetadata,
|
|
32
32
|
renderGutterUtility,
|
|
33
|
-
lineAnnotations,
|
|
33
|
+
lineAnnotations: renderedAnnotations,
|
|
34
34
|
getHoveredLine,
|
|
35
35
|
getAnnotationSlotName
|
|
36
36
|
});
|
package/dist/react/File.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.js","names":[],"sources":["../../src/react/File.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FileEditChangeHandler,\n type FileEditCompleteEvent,\n type FileEditCompleteHandler,\n} from '../components/File';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileProps } from './types';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileInstance } from './utils/useFileInstance';\n\nexport type {\n FileEditChangeHandler,\n FileEditCompleteEvent,\n FileEditCompleteHandler,\n};\nexport type { FileOptions } from './types';\n\nexport function File<LAnnotation = undefined, Caret = undefined>({\n file,\n lineAnnotations,\n selectedLines,\n options,\n editorOptions,\n editStateKey,\n metrics,\n className,\n style,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n prerenderedHTML,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n onEditChange,\n onEditComplete,\n}: FileProps<LAnnotation, Caret>): React.JSX.Element {\n const {
|
|
1
|
+
{"version":3,"file":"File.js","names":[],"sources":["../../src/react/File.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FileEditChangeHandler,\n type FileEditCompleteEvent,\n type FileEditCompleteHandler,\n} from '../components/File';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileProps } from './types';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileInstance } from './utils/useFileInstance';\n\nexport type {\n FileEditChangeHandler,\n FileEditCompleteEvent,\n FileEditCompleteHandler,\n};\nexport type { FileOptions } from './types';\n\nexport function File<LAnnotation = undefined, Caret = undefined>({\n file,\n lineAnnotations,\n selectedLines,\n options,\n editorOptions,\n editStateKey,\n metrics,\n className,\n style,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n prerenderedHTML,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n onEditChange,\n onEditComplete,\n}: FileProps<LAnnotation, Caret>): React.JSX.Element {\n const {\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n file: renderedFile,\n lineAnnotations: renderedAnnotations,\n } = useFileInstance({\n file,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n edit,\n onEditChange,\n onEditComplete,\n });\n const children = renderFileChildren({\n file: renderedFile,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n lineAnnotations: renderedAnnotations,\n getHoveredLine,\n getAnnotationSlotName,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;AAoBA,SAAgB,KAAiD,EAC/D,MACA,iBACA,eACA,SACA,eACA,cACA,SACA,WACA,OACA,kBACA,oBACA,oBACA,4BACA,sBACA,iBACA,qBACA,oBAAoB,OACpB,OAAO,OACP,cACA,kBACmD;CACnD,MAAM,EACJ,KACA,gBACA,uBACA,MAAM,cACN,iBAAiB,wBACf,gBAAgB;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;EACA;EACA;EACA;CACF,CAAC;CACD,MAAM,WAAW,mBAAmB;EAClC,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA;CACF,CAAC;CACD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;EACpD,UAAA,eAAe,UAAU,eAAe;CAC3B,CAAA;AAEpB"}
|
package/dist/react/FileDiff.js
CHANGED
|
@@ -6,7 +6,7 @@ import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
|
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/react/FileDiff.tsx
|
|
8
8
|
function FileDiff({ fileDiff, options, editorOptions, editStateKey, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false, edit = false, onEditChange, onEditComplete }) {
|
|
9
|
-
const { ref, getHoveredLine, getAnnotationSlotName } = useFileDiffInstance({
|
|
9
|
+
const { ref, getHoveredLine, getAnnotationSlotName, fileDiff: renderedDiff, lineAnnotations: renderedAnnotations } = useFileDiffInstance({
|
|
10
10
|
fileDiff,
|
|
11
11
|
options,
|
|
12
12
|
editorOptions,
|
|
@@ -23,14 +23,14 @@ function FileDiff({ fileDiff, options, editorOptions, editStateKey, metrics, lin
|
|
|
23
23
|
onEditComplete
|
|
24
24
|
});
|
|
25
25
|
const children = renderDiffChildren({
|
|
26
|
-
fileDiff,
|
|
26
|
+
fileDiff: renderedDiff,
|
|
27
27
|
renderCustomHeader,
|
|
28
28
|
renderHeaderPrefix,
|
|
29
29
|
renderHeaderFilenameSuffix,
|
|
30
30
|
renderHeaderMetadata,
|
|
31
31
|
renderAnnotation,
|
|
32
32
|
renderGutterUtility,
|
|
33
|
-
lineAnnotations,
|
|
33
|
+
lineAnnotations: renderedAnnotations,
|
|
34
34
|
getHoveredLine,
|
|
35
35
|
getAnnotationSlotName
|
|
36
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDiff.js","names":[],"sources":["../../src/react/FileDiff.tsx"],"sourcesContent":["'use client';\n\nimport type {\n FileDiffEditChangeHandler,\n FileDiffEditCompleteEvent,\n FileDiffEditCompleteHandler,\n} from '../components/FileDiff';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport type {\n FileDiffEditChangeHandler,\n FileDiffEditCompleteEvent,\n FileDiffEditCompleteHandler,\n FileDiffMetadata,\n};\n\nexport interface FileDiffProps<LAnnotation, Caret> extends DiffBasePropsReact<\n LAnnotation,\n Caret\n> {\n fileDiff: FileDiffMetadata;\n disableWorkerPool?: boolean;\n}\n\nexport function FileDiff<LAnnotation = undefined, Caret = undefined>({\n fileDiff,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n onEditChange,\n onEditComplete,\n}: FileDiffProps<LAnnotation, Caret>): React.JSX.Element {\n const {
|
|
1
|
+
{"version":3,"file":"FileDiff.js","names":[],"sources":["../../src/react/FileDiff.tsx"],"sourcesContent":["'use client';\n\nimport type {\n FileDiffEditChangeHandler,\n FileDiffEditCompleteEvent,\n FileDiffEditCompleteHandler,\n} from '../components/FileDiff';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport type {\n FileDiffEditChangeHandler,\n FileDiffEditCompleteEvent,\n FileDiffEditCompleteHandler,\n FileDiffMetadata,\n};\n\nexport interface FileDiffProps<LAnnotation, Caret> extends DiffBasePropsReact<\n LAnnotation,\n Caret\n> {\n fileDiff: FileDiffMetadata;\n disableWorkerPool?: boolean;\n}\n\nexport function FileDiff<LAnnotation = undefined, Caret = undefined>({\n fileDiff,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n onEditChange,\n onEditComplete,\n}: FileDiffProps<LAnnotation, Caret>): React.JSX.Element {\n const {\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n fileDiff: renderedDiff,\n lineAnnotations: renderedAnnotations,\n } = useFileDiffInstance({\n fileDiff,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n edit,\n onEditChange,\n onEditComplete,\n });\n const children = renderDiffChildren({\n fileDiff: renderedDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n lineAnnotations: renderedAnnotations,\n getHoveredLine,\n getAnnotationSlotName,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;AA6BA,SAAgB,SAAqD,EACnE,UACA,SACA,eACA,cACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,oBAAoB,OACpB,OAAO,OACP,cACA,kBACuD;CACvD,MAAM,EACJ,KACA,gBACA,uBACA,UAAU,cACV,iBAAiB,wBACf,oBAAoB;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;EACA;EACA;EACA;CACF,CAAC;CACD,MAAM,WAAW,mBAAmB;EAClC,UAAU;EACV;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA;CACF,CAAC;CACD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;EACpD,UAAA,eAAe,UAAU,eAAe;CAC3B,CAAA;AAEpB"}
|
|
@@ -6,7 +6,7 @@ import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
|
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/react/MultiFileDiff.tsx
|
|
8
8
|
function MultiFileDiff({ oldFile, newFile, options, editorOptions, editStateKey, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false, edit = false, onEditChange, onEditComplete }) {
|
|
9
|
-
const { fileDiff, ref, getHoveredLine, getAnnotationSlotName } = useFileDiffInstance({
|
|
9
|
+
const { fileDiff, ref, getHoveredLine, getAnnotationSlotName, lineAnnotations: renderedAnnotations } = useFileDiffInstance({
|
|
10
10
|
oldFile,
|
|
11
11
|
newFile,
|
|
12
12
|
options,
|
|
@@ -30,7 +30,7 @@ function MultiFileDiff({ oldFile, newFile, options, editorOptions, editStateKey,
|
|
|
30
30
|
renderHeaderFilenameSuffix,
|
|
31
31
|
renderHeaderMetadata,
|
|
32
32
|
renderAnnotation,
|
|
33
|
-
lineAnnotations,
|
|
33
|
+
lineAnnotations: renderedAnnotations,
|
|
34
34
|
renderGutterUtility,
|
|
35
35
|
getHoveredLine,
|
|
36
36
|
getAnnotationSlotName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiFileDiff.js","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"sourcesContent":["'use client';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { DiffFileInput, FileContents } from '../types';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport type { FileContents };\n\ninterface MultiFileDiffBaseProps<LAnnotation, Caret> extends DiffBasePropsReact<\n LAnnotation,\n Caret\n> {\n disableWorkerPool?: boolean;\n}\n\nexport type MultiFileDiffProps<LAnnotation, Caret> = MultiFileDiffBaseProps<\n LAnnotation,\n Caret\n> &\n DiffFileInput;\n\nexport function MultiFileDiff<LAnnotation = undefined, Caret = undefined>({\n oldFile,\n newFile,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n onEditChange,\n onEditComplete,\n}: MultiFileDiffProps<LAnnotation, Caret>): React.JSX.Element {\n const {
|
|
1
|
+
{"version":3,"file":"MultiFileDiff.js","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"sourcesContent":["'use client';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { DiffFileInput, FileContents } from '../types';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport type { FileContents };\n\ninterface MultiFileDiffBaseProps<LAnnotation, Caret> extends DiffBasePropsReact<\n LAnnotation,\n Caret\n> {\n disableWorkerPool?: boolean;\n}\n\nexport type MultiFileDiffProps<LAnnotation, Caret> = MultiFileDiffBaseProps<\n LAnnotation,\n Caret\n> &\n DiffFileInput;\n\nexport function MultiFileDiff<LAnnotation = undefined, Caret = undefined>({\n oldFile,\n newFile,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n onEditChange,\n onEditComplete,\n}: MultiFileDiffProps<LAnnotation, Caret>): React.JSX.Element {\n const {\n fileDiff,\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n lineAnnotations: renderedAnnotations,\n } = useFileDiffInstance({\n oldFile,\n newFile,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n edit,\n onEditChange,\n onEditComplete,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations: renderedAnnotations,\n renderGutterUtility,\n getHoveredLine,\n getAnnotationSlotName,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,cAA0D,EACxE,SACA,SACA,SACA,eACA,cACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,oBAAoB,OACpB,OAAO,OACP,cACA,kBAC4D;CAC5D,MAAM,EACJ,UACA,KACA,gBACA,uBACA,iBAAiB,wBACf,oBAAoB;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;EACA;EACA;EACA;CACF,CAAC;CACD,MAAM,WAAW,mBAAmB;EAClC;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;EACpD,UAAA,eAAe,UAAU,eAAe;CAC3B,CAAA;AAEpB"}
|
package/dist/react/PatchDiff.js
CHANGED
|
@@ -9,7 +9,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
9
9
|
//#region src/react/PatchDiff.tsx
|
|
10
10
|
function PatchDiff({ patch, options, editorOptions, editStateKey, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false, edit = false, onEditChange, onEditComplete }) {
|
|
11
11
|
const fileDiff = usePatch(patch);
|
|
12
|
-
const { ref, getHoveredLine, getAnnotationSlotName } = useFileDiffInstance({
|
|
12
|
+
const { ref, getHoveredLine, getAnnotationSlotName, fileDiff: renderedDiff, lineAnnotations: renderedAnnotations } = useFileDiffInstance({
|
|
13
13
|
fileDiff,
|
|
14
14
|
options,
|
|
15
15
|
editorOptions,
|
|
@@ -26,13 +26,13 @@ function PatchDiff({ patch, options, editorOptions, editStateKey, metrics, lineA
|
|
|
26
26
|
onEditComplete
|
|
27
27
|
});
|
|
28
28
|
const children = renderDiffChildren({
|
|
29
|
-
fileDiff,
|
|
29
|
+
fileDiff: renderedDiff,
|
|
30
30
|
renderCustomHeader,
|
|
31
31
|
renderHeaderPrefix,
|
|
32
32
|
renderHeaderFilenameSuffix,
|
|
33
33
|
renderHeaderMetadata,
|
|
34
34
|
renderAnnotation,
|
|
35
|
-
lineAnnotations,
|
|
35
|
+
lineAnnotations: renderedAnnotations,
|
|
36
36
|
renderGutterUtility,
|
|
37
37
|
getHoveredLine,
|
|
38
38
|
getAnnotationSlotName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PatchDiff.js","names":[],"sources":["../../src/react/PatchDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport { getSingularPatch } from '../utils/getSingularPatch';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport interface PatchDiffProps<LAnnotation, Caret> extends DiffBasePropsReact<\n LAnnotation,\n Caret\n> {\n patch: string;\n disableWorkerPool?: boolean;\n}\n\nexport function PatchDiff<LAnnotation = undefined, Caret = undefined>({\n patch,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n onEditChange,\n onEditComplete,\n}: PatchDiffProps<LAnnotation, Caret>): React.JSX.Element {\n const fileDiff = usePatch(patch);\n const {
|
|
1
|
+
{"version":3,"file":"PatchDiff.js","names":[],"sources":["../../src/react/PatchDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport { getSingularPatch } from '../utils/getSingularPatch';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport interface PatchDiffProps<LAnnotation, Caret> extends DiffBasePropsReact<\n LAnnotation,\n Caret\n> {\n patch: string;\n disableWorkerPool?: boolean;\n}\n\nexport function PatchDiff<LAnnotation = undefined, Caret = undefined>({\n patch,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n onEditChange,\n onEditComplete,\n}: PatchDiffProps<LAnnotation, Caret>): React.JSX.Element {\n const fileDiff = usePatch(patch);\n const {\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n fileDiff: renderedDiff,\n lineAnnotations: renderedAnnotations,\n } = useFileDiffInstance({\n fileDiff,\n options,\n editorOptions,\n editStateKey,\n metrics,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n edit,\n onEditChange,\n onEditComplete,\n });\n const children = renderDiffChildren({\n fileDiff: renderedDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations: renderedAnnotations,\n renderGutterUtility,\n getHoveredLine,\n getAnnotationSlotName,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n\nfunction usePatch(patch: string): FileDiffMetadata {\n return useMemo<FileDiffMetadata>(() => getSingularPatch(patch), [patch]);\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAgB,UAAsD,EACpE,OACA,SACA,eACA,cACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,oBAAoB,OACpB,OAAO,OACP,cACA,kBACwD;CACxD,MAAM,WAAW,SAAS,KAAK;CAC/B,MAAM,EACJ,KACA,gBACA,uBACA,UAAU,cACV,iBAAiB,wBACf,oBAAoB;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;EACA;EACA;EACA;CACF,CAAC;CACD,MAAM,WAAW,mBAAmB;EAClC,UAAU;EACV;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;EACpD,UAAA,eAAe,UAAU,eAAe;CAC3B,CAAA;AAEpB;AAEA,SAAS,SAAS,OAAiC;CACjD,OAAO,cAAgC,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;AACzE"}
|
|
@@ -6,7 +6,7 @@ import { useUnresolvedFileInstance } from "./utils/useUnresolvedFileInstance.js"
|
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/react/UnresolvedFile.tsx
|
|
8
8
|
function UnresolvedFile({ file, options, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, renderMergeConflictUtility, disableWorkerPool = false }) {
|
|
9
|
-
const { ref, getHoveredLine, fileDiff, actions, getInstance } = useUnresolvedFileInstance({
|
|
9
|
+
const { ref, getHoveredLine, fileDiff, actions, getInstance, lineAnnotations: renderedAnnotations } = useUnresolvedFileInstance({
|
|
10
10
|
file,
|
|
11
11
|
options,
|
|
12
12
|
lineAnnotations,
|
|
@@ -25,7 +25,7 @@ function UnresolvedFile({ file, options, lineAnnotations, selectedLines, classNa
|
|
|
25
25
|
renderHeaderMetadata,
|
|
26
26
|
renderAnnotation,
|
|
27
27
|
renderGutterUtility,
|
|
28
|
-
lineAnnotations,
|
|
28
|
+
lineAnnotations: renderedAnnotations,
|
|
29
29
|
getHoveredLine,
|
|
30
30
|
actions,
|
|
31
31
|
renderMergeConflictUtility,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnresolvedFile.js","names":[],"sources":["../../src/react/UnresolvedFile.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\n\nimport type { UnresolvedFile as UnresolvedFileClass } from '../components/UnresolvedFile';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { UnresolvedFileHunksRendererOptions } from '../renderers/UnresolvedFileHunksRenderer';\nimport type {\n FileContents,\n HunkSeparators,\n MergeConflictResolution,\n PostRenderPhase,\n} from '../types';\nimport { type MergeConflictDiffAction } from '../utils/parseMergeConflictDiffFromFile';\nimport type { FileDiffProps } from './FileDiff';\nimport type { FileDiffOptions } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useUnresolvedFileInstance } from './utils/useUnresolvedFileInstance';\n\nexport interface RenderMergeConflictActionContext {\n resolveConflict(resolution: MergeConflictResolution): void;\n}\n\nexport type RenderMergeConflictActions = (\n action: MergeConflictDiffAction,\n context: RenderMergeConflictActionContext\n) => ReactNode;\n\nexport type MergeConflictActionsTypeOption =\n | 'none'\n | 'default'\n | RenderMergeConflictActions;\n\nexport interface UnresolvedFileReactOptions<LAnnotation>\n extends\n Omit<\n FileDiffOptions<LAnnotation, undefined>,\n 'hunkSeparators' | 'diffStyle' | 'onMergeConflictAction' | 'onPostRender'\n >,\n UnresolvedFileHunksRendererOptions {\n hunkSeparators?: HunkSeparators;\n onPostRender?(\n node: HTMLElement,\n instance: UnresolvedFileClass<LAnnotation>,\n phase: PostRenderPhase\n ): unknown;\n maxContextLines?: number;\n}\n\nexport interface UnresolvedFileProps<LAnnotation> extends Omit<\n FileDiffProps<LAnnotation, undefined>,\n | 'fileDiff'\n | 'options'\n | 'edit'\n | 'editorOptions'\n | 'onEditChange'\n | 'onEditComplete'\n> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n renderMergeConflictUtility?(\n action: MergeConflictDiffAction,\n getInstance: () => UnresolvedFileClass<LAnnotation> | undefined\n ): ReactNode;\n disableWorkerPool?: boolean;\n}\n\nexport function UnresolvedFile<LAnnotation = undefined>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n renderMergeConflictUtility,\n disableWorkerPool = false,\n}: UnresolvedFileProps<LAnnotation>): React.JSX.Element {\n const {
|
|
1
|
+
{"version":3,"file":"UnresolvedFile.js","names":[],"sources":["../../src/react/UnresolvedFile.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\n\nimport type { UnresolvedFile as UnresolvedFileClass } from '../components/UnresolvedFile';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { UnresolvedFileHunksRendererOptions } from '../renderers/UnresolvedFileHunksRenderer';\nimport type {\n FileContents,\n HunkSeparators,\n MergeConflictResolution,\n PostRenderPhase,\n} from '../types';\nimport { type MergeConflictDiffAction } from '../utils/parseMergeConflictDiffFromFile';\nimport type { FileDiffProps } from './FileDiff';\nimport type { FileDiffOptions } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useUnresolvedFileInstance } from './utils/useUnresolvedFileInstance';\n\nexport interface RenderMergeConflictActionContext {\n resolveConflict(resolution: MergeConflictResolution): void;\n}\n\nexport type RenderMergeConflictActions = (\n action: MergeConflictDiffAction,\n context: RenderMergeConflictActionContext\n) => ReactNode;\n\nexport type MergeConflictActionsTypeOption =\n | 'none'\n | 'default'\n | RenderMergeConflictActions;\n\nexport interface UnresolvedFileReactOptions<LAnnotation>\n extends\n Omit<\n FileDiffOptions<LAnnotation, undefined>,\n 'hunkSeparators' | 'diffStyle' | 'onMergeConflictAction' | 'onPostRender'\n >,\n UnresolvedFileHunksRendererOptions {\n hunkSeparators?: HunkSeparators;\n onPostRender?(\n node: HTMLElement,\n instance: UnresolvedFileClass<LAnnotation>,\n phase: PostRenderPhase\n ): unknown;\n maxContextLines?: number;\n}\n\nexport interface UnresolvedFileProps<LAnnotation> extends Omit<\n FileDiffProps<LAnnotation, undefined>,\n | 'fileDiff'\n | 'options'\n | 'edit'\n | 'editorOptions'\n | 'onEditChange'\n | 'onEditComplete'\n> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n renderMergeConflictUtility?(\n action: MergeConflictDiffAction,\n getInstance: () => UnresolvedFileClass<LAnnotation> | undefined\n ): ReactNode;\n disableWorkerPool?: boolean;\n}\n\nexport function UnresolvedFile<LAnnotation = undefined>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n renderMergeConflictUtility,\n disableWorkerPool = false,\n}: UnresolvedFileProps<LAnnotation>): React.JSX.Element {\n const {\n ref,\n getHoveredLine,\n fileDiff,\n actions,\n getInstance,\n lineAnnotations: renderedAnnotations,\n } = useUnresolvedFileInstance({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasConflictUtility: renderMergeConflictUtility != null,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n lineAnnotations: renderedAnnotations,\n getHoveredLine,\n actions,\n renderMergeConflictUtility,\n getInstance,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;AAoEA,SAAgB,eAAwC,EACtD,MACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,4BACA,oBAAoB,SACkC;CACtD,MAAM,EACJ,KACA,gBACA,UACA,SACA,aACA,iBAAiB,wBACf,0BAA0B;EAC5B;EACA;EACA;EACA;EACA;EACA,oBAAoB,8BAA8B;EAClD,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;CACF,CAAC;CACD,MAAM,WAAW,mBAAmB;EAClC;EACA;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA;EACA;EACA;CACF,CAAC;CACD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;EACpD,UAAA,eAAe,UAAU,eAAe;CAC3B,CAAA;AAEpB"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { EditorFactory, FileDiffEditCompleteEvent, FileEditCompleteEvent } from
|
|
|
9
9
|
import { FileEditChangeHandler, FileEditCompleteHandler } from "../components/File.js";
|
|
10
10
|
import { FileDiffEditChangeHandler, FileDiffEditCompleteHandler } from "../components/FileDiff.js";
|
|
11
11
|
import { CodeViewItemEditCompleteHandler } from "../components/CodeView.js";
|
|
12
|
-
import { CodeView, CodeViewHandle, CodeViewProps, CodeViewReactOptions, ControlledCodeViewProps, UncontrolledCodeViewProps } from "./CodeView.js";
|
|
12
|
+
import { CodeView, CodeViewAnnotationArgs, CodeViewHandle, CodeViewProps, CodeViewReactOptions, ControlledCodeViewProps, UncontrolledCodeViewProps } from "./CodeView.js";
|
|
13
13
|
import { DiffBasePropsReact, FileDiffOptions, FileOptions, FileProps } from "./types.js";
|
|
14
14
|
import { File } from "./File.js";
|
|
15
15
|
import { FileDiff, FileDiffProps } from "./FileDiff.js";
|
|
@@ -26,4 +26,4 @@ import { templateRender } from "./utils/templateRender.js";
|
|
|
26
26
|
import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
|
|
27
27
|
import { useFileInstance } from "./utils/useFileInstance.js";
|
|
28
28
|
import { useStableCallback } from "./utils/useStableCallback.js";
|
|
29
|
-
export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, ChangeContent, ChangeTypes, CodeColumnType, type CodeToHtmlOptions, type CodeToTokensOptions, CodeView, CodeViewDiffItem, CodeViewFileItem, CodeViewHandle, CodeViewItem, type CodeViewItemEditCompleteHandler, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewProps, CodeViewRangeScrollTarget, CodeViewReactOptions, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, ControlledCodeViewProps, type CreatePatchOptionsNonabortable, CustomPreProperties, type DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffBasePropsReact, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, type DiffsEditorTokenizer, type DiffsEditorTokenizerOptions, type DiffsHighlighter, type DiffsStreamTokenizer, type DiffsTheme, DiffsThemeNames, EditContext, EditProvider, EditProviderProps, type EditorFactory, ExpansionDirections, ExtensionFormatMap, File, FileContents, FileDiff, FileDiffContentsLoader, type FileDiffEditChangeHandler, type FileDiffEditCompleteEvent, type FileDiffEditCompleteHandler, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileDiffOptions, FileDiffProps, type FileEditChangeHandler, type FileEditCompleteEvent, type FileEditCompleteHandler, FileHeaderRenderMode, FileOptions, FileProps, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, GutterUtilitySlotStyles, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictActionsTypeOption, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, MergeConflictSlotStyles, MultiFileDiff, MultiFileDiffProps, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PatchDiff, PatchDiffProps, PendingCodeViewLayoutReset, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderMergeConflictActionContext, RenderMergeConflictActions, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionPoint, SelectionSide, SharedRenderState, SmoothScrollSettings, StickySpecs, SupportedLanguages, ThemeTypes, ThemedDiffResult, ThemedFileResult, type ThemedToken, ThemesType, TokenEventBase, type TokensResult, UncontrolledCodeViewProps, UnresolvedFile, UnresolvedFileProps, UnresolvedFileReactOptions, VirtualFileMetrics, VirtualWindowSpecs, Virtualizer, VirtualizerContext, type WorkerInitializationRenderOptions, WorkerPoolContext, WorkerPoolContextProvider, type WorkerPoolOptions, noopRender, renderDiffChildren, renderFileChildren, templateRender, useCreateEditor, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
|
|
29
|
+
export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, ChangeContent, ChangeTypes, CodeColumnType, type CodeToHtmlOptions, type CodeToTokensOptions, CodeView, CodeViewAnnotationArgs, CodeViewDiffItem, CodeViewFileItem, CodeViewHandle, CodeViewItem, type CodeViewItemEditCompleteHandler, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewProps, CodeViewRangeScrollTarget, CodeViewReactOptions, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, ControlledCodeViewProps, type CreatePatchOptionsNonabortable, CustomPreProperties, type DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffBasePropsReact, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, type DiffsEditorTokenizer, type DiffsEditorTokenizerOptions, type DiffsHighlighter, type DiffsStreamTokenizer, type DiffsTheme, DiffsThemeNames, EditContext, EditProvider, EditProviderProps, type EditorFactory, ExpansionDirections, ExtensionFormatMap, File, FileContents, FileDiff, FileDiffContentsLoader, type FileDiffEditChangeHandler, type FileDiffEditCompleteEvent, type FileDiffEditCompleteHandler, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileDiffOptions, FileDiffProps, type FileEditChangeHandler, type FileEditCompleteEvent, type FileEditCompleteHandler, FileHeaderRenderMode, FileOptions, FileProps, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, GutterUtilitySlotStyles, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictActionsTypeOption, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, MergeConflictSlotStyles, MultiFileDiff, MultiFileDiffProps, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PatchDiff, PatchDiffProps, PendingCodeViewLayoutReset, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderMergeConflictActionContext, RenderMergeConflictActions, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionPoint, SelectionSide, SharedRenderState, SmoothScrollSettings, StickySpecs, SupportedLanguages, ThemeTypes, ThemedDiffResult, ThemedFileResult, type ThemedToken, ThemesType, TokenEventBase, type TokensResult, UncontrolledCodeViewProps, UnresolvedFile, UnresolvedFileProps, UnresolvedFileReactOptions, VirtualFileMetrics, VirtualWindowSpecs, Virtualizer, VirtualizerContext, type WorkerInitializationRenderOptions, WorkerPoolContext, WorkerPoolContextProvider, type WorkerPoolOptions, noopRender, renderDiffChildren, renderFileChildren, templateRender, useCreateEditor, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
|
package/dist/react/types.d.ts
CHANGED
|
@@ -37,7 +37,8 @@ interface DiffBasePropsReact<LAnnotation, Caret> {
|
|
|
37
37
|
metrics?: VirtualFileMetrics;
|
|
38
38
|
lineAnnotations?: DiffLineAnnotation<LAnnotation>[];
|
|
39
39
|
selectedLines?: SelectedLineRange | null;
|
|
40
|
-
|
|
40
|
+
/** Receives the matching diff. */
|
|
41
|
+
renderAnnotation?(annotation: DiffLineAnnotation<LAnnotation>, fileDiff: FileDiffMetadata): ReactNode;
|
|
41
42
|
renderCustomHeader?(fileDiff: FileDiffMetadata): ReactNode;
|
|
42
43
|
renderHeaderPrefix?(fileDiff: FileDiffMetadata): ReactNode;
|
|
43
44
|
renderHeaderFilenameSuffix?(fileDiff: FileDiffMetadata): ReactNode;
|
|
@@ -72,7 +73,8 @@ interface FileProps<LAnnotation, Caret> {
|
|
|
72
73
|
metrics?: VirtualFileMetrics;
|
|
73
74
|
lineAnnotations?: LineAnnotation<LAnnotation>[];
|
|
74
75
|
selectedLines?: SelectedLineRange | null;
|
|
75
|
-
|
|
76
|
+
/** Receives the matching file. */
|
|
77
|
+
renderAnnotation?(annotation: LineAnnotation<LAnnotation>, file: FileContents): ReactNode;
|
|
76
78
|
renderCustomHeader?(file: FileContents): ReactNode;
|
|
77
79
|
renderHeaderPrefix?(file: FileContents): ReactNode;
|
|
78
80
|
renderHeaderFilenameSuffix?(file: FileContents): ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/react/types.ts"],"mappings":";;;;;;;;KAuBK;KAEO,gBAAgB,aAAa,SAAS,KAChD,kBAAqB,aAAa,QAClC;KAGU,YAAY,aAAa,SAAS,KAC5C,cAAiB,aAAa,QAC9B;UAGe,mBAAmB,aAAa;EAC/C,UAAU,gBAAgB,aAAa;;EAEvC;;EAEA,gBAAgB,2BAA2B,aAAa;;EAExD;;;;;;;;;;EAUA,eAAe,0BAA0B,aAAa;;;;;;;EAOtD,iBAAiB,4BAA4B,aAAa;EAC1D,UAAU;EACV,kBAAkB,mBAAmB;EACrC,gBAAgB
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/react/types.ts"],"mappings":";;;;;;;;KAuBK;KAEO,gBAAgB,aAAa,SAAS,KAChD,kBAAqB,aAAa,QAClC;KAGU,YAAY,aAAa,SAAS,KAC5C,cAAiB,aAAa,QAC9B;UAGe,mBAAmB,aAAa;EAC/C,UAAU,gBAAgB,aAAa;;EAEvC;;EAEA,gBAAgB,2BAA2B,aAAa;;EAExD;;;;;;;;;;EAUA,eAAe,0BAA0B,aAAa;;;;;;;EAOtD,iBAAiB,4BAA4B,aAAa;EAC1D,UAAU;EACV,kBAAkB,mBAAmB;EACrC,gBAAgB;;EAEhB,kBACE,YAAY,mBAAmB,cAC/B,UAAU,mBACT;EACH,oBAAoB,UAAU,mBAAmB;EACjD,oBAAoB,UAAU,mBAAmB;EACjD,4BAA4B,UAAU,mBAAmB;EACzD,sBAAsB,UAAU,mBAAmB;EACnD,qBACE,sBAAsB,2CACrB;EACH;EACA,QAAQ;EACR;;UAGe,UAAU,aAAa;EACtC,MAAM;EACN,UAAU,YAAY,aAAa;;EAEnC;;EAEA,gBAAgB,sBAAsB,aAAa;;EAEnD;;;;;;EAMA,eAAe,sBAAsB,aAAa;;;;;;;EAOlD,iBAAiB,wBAAwB,aAAa;EACtD,UAAU;EACV,kBAAkB,eAAe;EACjC,gBAAgB;;EAEhB,kBACE,YAAY,eAAe,cAC3B,MAAM,eACL;EACH,oBAAoB,MAAM,eAAe;EACzC,oBAAoB,MAAM,eAAe;EACzC,4BAA4B,MAAM,eAAe;EACjD,sBAAsB,MAAM,eAAe;EAC3C,qBACE,sBAAsB,2CACrB;EACH;EACA,QAAQ;EACR;EACA"}
|
|
@@ -30,7 +30,7 @@ function renderDiffChildren({ fileDiff, actions, renderCustomHeader, renderHeade
|
|
|
30
30
|
] }),
|
|
31
31
|
renderAnnotation != null && lineAnnotations?.map((annotation, index) => /* @__PURE__ */ jsx("div", {
|
|
32
32
|
slot: getAnnotationSlotName(annotation),
|
|
33
|
-
children: renderAnnotation(annotation)
|
|
33
|
+
children: renderAnnotation(annotation, fileDiff)
|
|
34
34
|
}, index)),
|
|
35
35
|
actions != null && renderMergeConflictUtility != null && getInstance != null && actions.map((action) => {
|
|
36
36
|
if (action == null) return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderDiffChildren.js","names":[],"sources":["../../../src/react/utils/renderDiffChildren.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport {\n CUSTOM_HEADER_SLOT_ID,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n HEADER_METADATA_SLOT_ID,\n HEADER_PREFIX_SLOT_ID,\n} from '../../constants';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { DiffLineAnnotation, FileDiffMetadata } from '../../types';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { getMergeConflictActionSlotName } from '../../utils/getMergeConflictActionSlotName';\nimport {\n getMergeConflictActionAnchor,\n type MergeConflictDiffAction,\n} from '../../utils/parseMergeConflictDiffFromFile';\nimport { GutterUtilitySlotStyles, MergeConflictSlotStyles } from '../constants';\nimport type { DiffBasePropsReact } from '../types';\n\ninterface RenderDiffChildrenProps<LAnnotation, Caret, T> {\n fileDiff: FileDiffMetadata;\n actions?: (MergeConflictDiffAction | undefined)[];\n renderCustomHeader: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderCustomHeader'];\n renderHeaderPrefix: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderHeaderPrefix'];\n renderHeaderFilenameSuffix?: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderHeaderMetadata'];\n renderAnnotation: DiffBasePropsReact<LAnnotation, Caret>['renderAnnotation'];\n renderGutterUtility: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderGutterUtility'];\n renderMergeConflictUtility?(\n action: MergeConflictDiffAction,\n getInstance: () => T | undefined\n ): ReactNode;\n lineAnnotations: DiffBasePropsReact<LAnnotation, Caret>['lineAnnotations'];\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getInstance?(): T | undefined;\n getAnnotationSlotName?(annotation: DiffLineAnnotation<LAnnotation>): string;\n}\n\nexport function renderDiffChildren<LAnnotation, Caret, T>({\n fileDiff,\n actions,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n renderMergeConflictUtility,\n lineAnnotations,\n getHoveredLine,\n getInstance,\n getAnnotationSlotName = getLineAnnotationName,\n}: RenderDiffChildrenProps<LAnnotation, Caret, T>): ReactNode {\n const customHeader = renderCustomHeader?.(fileDiff);\n const prefix = renderHeaderPrefix?.(fileDiff);\n const suffix = renderHeaderFilenameSuffix?.(fileDiff);\n const metadata = renderHeaderMetadata?.(fileDiff);\n return (\n <>\n {customHeader != null ? (\n <div slot={CUSTOM_HEADER_SLOT_ID}>{customHeader}</div>\n ) : (\n <>\n {prefix != null && <div slot={HEADER_PREFIX_SLOT_ID}>{prefix}</div>}\n {suffix != null && (\n <div slot={HEADER_FILENAME_SUFFIX_SLOT_ID}>{suffix}</div>\n )}\n {metadata != null && (\n <div slot={HEADER_METADATA_SLOT_ID}>{metadata}</div>\n )}\n </>\n )}\n {renderAnnotation != null &&\n lineAnnotations?.map((annotation, index) => (\n <div key={index} slot={getAnnotationSlotName(annotation)}>\n {renderAnnotation(annotation)}\n </div>\n ))}\n {actions != null &&\n renderMergeConflictUtility != null &&\n getInstance != null &&\n actions.map((action) => {\n if (action == null) {\n return undefined;\n }\n const slot = getSlotName(action, fileDiff);\n return (\n <div key={slot} slot={slot} style={MergeConflictSlotStyles}>\n {renderMergeConflictUtility(action, getInstance)}\n </div>\n );\n })}\n {renderGutterUtility != null && (\n <div slot=\"gutter-utility-slot\" style={GutterUtilitySlotStyles}>\n {renderGutterUtility(getHoveredLine)}\n </div>\n )}\n </>\n );\n}\n\nfunction getSlotName(\n action: MergeConflictDiffAction,\n fileDiff: FileDiffMetadata\n): string | undefined {\n const anchor = getMergeConflictActionAnchor(action, fileDiff);\n return anchor != null\n ? getMergeConflictActionSlotName({\n hunkIndex: anchor.hunkIndex,\n lineIndex: anchor.lineIndex,\n conflictIndex: action.conflictIndex,\n })\n : undefined;\n}\n"],"mappings":";;;;;;;AAqDA,SAAgB,mBAA0C,EACxD,UACA,SACA,oBACA,oBACA,4BACA,sBACA,kBACA,qBACA,4BACA,iBACA,gBACA,aACA,wBAAwB,yBACoC;CAC5D,MAAM,eAAe,qBAAqB,QAAQ;CAClD,MAAM,SAAS,qBAAqB,QAAQ;CAC5C,MAAM,SAAS,6BAA6B,QAAQ;CACpD,MAAM,WAAW,uBAAuB,QAAQ;CAChD,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,gBAAgB,OACf,oBAAC,OAAD;GAAK,MAAM;GAAwB,UAAA;EAAkB,CAAA,IAErD,qBAAA,UAAA,EAAA,UAAA;GACG,UAAU,QAAQ,oBAAC,OAAD;IAAK,MAAA;IAA8B,UAAA;GAAY,CAAA;GACjE,UAAU,QACT,oBAAC,OAAD;IAAK,MAAA;IAAuC,UAAA;GAAY,CAAA;GAEzD,YAAY,QACX,oBAAC,OAAD;IAAK,MAAA;IAAgC,UAAA;GAAc,CAAA;EAErD,EAAA,CAAA;EAEH,oBAAoB,QACnB,iBAAiB,KAAK,YAAY,UAChC,oBAAC,OAAD;GAAiB,MAAM,sBAAsB,UAAU;GACpD,UAAA,iBAAiB,
|
|
1
|
+
{"version":3,"file":"renderDiffChildren.js","names":[],"sources":["../../../src/react/utils/renderDiffChildren.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport {\n CUSTOM_HEADER_SLOT_ID,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n HEADER_METADATA_SLOT_ID,\n HEADER_PREFIX_SLOT_ID,\n} from '../../constants';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { DiffLineAnnotation, FileDiffMetadata } from '../../types';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { getMergeConflictActionSlotName } from '../../utils/getMergeConflictActionSlotName';\nimport {\n getMergeConflictActionAnchor,\n type MergeConflictDiffAction,\n} from '../../utils/parseMergeConflictDiffFromFile';\nimport { GutterUtilitySlotStyles, MergeConflictSlotStyles } from '../constants';\nimport type { DiffBasePropsReact } from '../types';\n\ninterface RenderDiffChildrenProps<LAnnotation, Caret, T> {\n fileDiff: FileDiffMetadata;\n actions?: (MergeConflictDiffAction | undefined)[];\n renderCustomHeader: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderCustomHeader'];\n renderHeaderPrefix: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderHeaderPrefix'];\n renderHeaderFilenameSuffix?: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderHeaderMetadata'];\n renderAnnotation: DiffBasePropsReact<LAnnotation, Caret>['renderAnnotation'];\n renderGutterUtility: DiffBasePropsReact<\n LAnnotation,\n Caret\n >['renderGutterUtility'];\n renderMergeConflictUtility?(\n action: MergeConflictDiffAction,\n getInstance: () => T | undefined\n ): ReactNode;\n lineAnnotations: DiffBasePropsReact<LAnnotation, Caret>['lineAnnotations'];\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getInstance?(): T | undefined;\n getAnnotationSlotName?(annotation: DiffLineAnnotation<LAnnotation>): string;\n}\n\nexport function renderDiffChildren<LAnnotation, Caret, T>({\n fileDiff,\n actions,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n renderMergeConflictUtility,\n lineAnnotations,\n getHoveredLine,\n getInstance,\n getAnnotationSlotName = getLineAnnotationName,\n}: RenderDiffChildrenProps<LAnnotation, Caret, T>): ReactNode {\n const customHeader = renderCustomHeader?.(fileDiff);\n const prefix = renderHeaderPrefix?.(fileDiff);\n const suffix = renderHeaderFilenameSuffix?.(fileDiff);\n const metadata = renderHeaderMetadata?.(fileDiff);\n return (\n <>\n {customHeader != null ? (\n <div slot={CUSTOM_HEADER_SLOT_ID}>{customHeader}</div>\n ) : (\n <>\n {prefix != null && <div slot={HEADER_PREFIX_SLOT_ID}>{prefix}</div>}\n {suffix != null && (\n <div slot={HEADER_FILENAME_SUFFIX_SLOT_ID}>{suffix}</div>\n )}\n {metadata != null && (\n <div slot={HEADER_METADATA_SLOT_ID}>{metadata}</div>\n )}\n </>\n )}\n {renderAnnotation != null &&\n lineAnnotations?.map((annotation, index) => (\n <div key={index} slot={getAnnotationSlotName(annotation)}>\n {renderAnnotation(annotation, fileDiff)}\n </div>\n ))}\n {actions != null &&\n renderMergeConflictUtility != null &&\n getInstance != null &&\n actions.map((action) => {\n if (action == null) {\n return undefined;\n }\n const slot = getSlotName(action, fileDiff);\n return (\n <div key={slot} slot={slot} style={MergeConflictSlotStyles}>\n {renderMergeConflictUtility(action, getInstance)}\n </div>\n );\n })}\n {renderGutterUtility != null && (\n <div slot=\"gutter-utility-slot\" style={GutterUtilitySlotStyles}>\n {renderGutterUtility(getHoveredLine)}\n </div>\n )}\n </>\n );\n}\n\nfunction getSlotName(\n action: MergeConflictDiffAction,\n fileDiff: FileDiffMetadata\n): string | undefined {\n const anchor = getMergeConflictActionAnchor(action, fileDiff);\n return anchor != null\n ? getMergeConflictActionSlotName({\n hunkIndex: anchor.hunkIndex,\n lineIndex: anchor.lineIndex,\n conflictIndex: action.conflictIndex,\n })\n : undefined;\n}\n"],"mappings":";;;;;;;AAqDA,SAAgB,mBAA0C,EACxD,UACA,SACA,oBACA,oBACA,4BACA,sBACA,kBACA,qBACA,4BACA,iBACA,gBACA,aACA,wBAAwB,yBACoC;CAC5D,MAAM,eAAe,qBAAqB,QAAQ;CAClD,MAAM,SAAS,qBAAqB,QAAQ;CAC5C,MAAM,SAAS,6BAA6B,QAAQ;CACpD,MAAM,WAAW,uBAAuB,QAAQ;CAChD,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,gBAAgB,OACf,oBAAC,OAAD;GAAK,MAAM;GAAwB,UAAA;EAAkB,CAAA,IAErD,qBAAA,UAAA,EAAA,UAAA;GACG,UAAU,QAAQ,oBAAC,OAAD;IAAK,MAAA;IAA8B,UAAA;GAAY,CAAA;GACjE,UAAU,QACT,oBAAC,OAAD;IAAK,MAAA;IAAuC,UAAA;GAAY,CAAA;GAEzD,YAAY,QACX,oBAAC,OAAD;IAAK,MAAA;IAAgC,UAAA;GAAc,CAAA;EAErD,EAAA,CAAA;EAEH,oBAAoB,QACnB,iBAAiB,KAAK,YAAY,UAChC,oBAAC,OAAD;GAAiB,MAAM,sBAAsB,UAAU;GACpD,UAAA,iBAAiB,YAAY,QAAQ;EACnC,GAFK,KAEL,CACN;EACF,WAAW,QACV,8BAA8B,QAC9B,eAAe,QACf,QAAQ,KAAK,WAAW;GACtB,IAAI,UAAU,MACZ;GAEF,MAAM,OAAO,YAAY,QAAQ,QAAQ;GACzC,OACE,oBAAC,OAAD;IAAsB;IAAM,OAAO;IAChC,UAAA,2BAA2B,QAAQ,WAAW;GAC5C,GAFK,IAEL;EAET,CAAC;EACF,uBAAuB,QACtB,oBAAC,OAAD;GAAK,MAAK;GAAsB,OAAO;GACpC,UAAA,oBAAoB,cAAc;EAChC,CAAA;CAEP,EAAA,CAAA;AAEN;AAEA,SAAS,YACP,QACA,UACoB;CACpB,MAAM,SAAS,6BAA6B,QAAQ,QAAQ;CAC5D,OAAO,UAAU,OACb,+BAA+B;EAC7B,WAAW,OAAO;EAClB,WAAW,OAAO;EAClB,eAAe,OAAO;CACxB,CAAC,IACD,KAAA;AACN"}
|
|
@@ -28,7 +28,7 @@ function renderFileChildren({ file, renderCustomHeader, renderHeaderPrefix, rend
|
|
|
28
28
|
] }),
|
|
29
29
|
renderAnnotation != null && lineAnnotations?.map((annotation, index) => /* @__PURE__ */ jsx("div", {
|
|
30
30
|
slot: getAnnotationSlotName(annotation),
|
|
31
|
-
children: renderAnnotation(annotation)
|
|
31
|
+
children: renderAnnotation(annotation, file)
|
|
32
32
|
}, index)),
|
|
33
33
|
renderGutterUtility != null && /* @__PURE__ */ jsx("div", {
|
|
34
34
|
slot: "gutter-utility-slot",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderFileChildren.js","names":[],"sources":["../../../src/react/utils/renderFileChildren.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport {\n CUSTOM_HEADER_SLOT_ID,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n HEADER_METADATA_SLOT_ID,\n HEADER_PREFIX_SLOT_ID,\n} from '../../constants';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { FileContents, LineAnnotation } from '../../types';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { GutterUtilitySlotStyles } from '../constants';\nimport type { FileProps } from '../types';\n\ninterface RenderFileChildrenProps<LAnnotation, Caret> {\n file: FileContents;\n renderCustomHeader: FileProps<LAnnotation, Caret>['renderCustomHeader'];\n renderHeaderPrefix: FileProps<LAnnotation, Caret>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix?: FileProps<\n LAnnotation,\n Caret\n >['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: FileProps<LAnnotation, Caret>['renderHeaderMetadata'];\n renderAnnotation: FileProps<LAnnotation, Caret>['renderAnnotation'];\n lineAnnotations: FileProps<LAnnotation, Caret>['lineAnnotations'];\n renderGutterUtility: FileProps<LAnnotation, Caret>['renderGutterUtility'];\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n getAnnotationSlotName?(annotation: LineAnnotation<LAnnotation>): string;\n}\n\nexport function renderFileChildren<LAnnotation, Caret>({\n file,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n getAnnotationSlotName = getLineAnnotationName,\n}: RenderFileChildrenProps<LAnnotation, Caret>): ReactNode {\n const customHeader = renderCustomHeader?.(file);\n const prefix = renderHeaderPrefix?.(file);\n const suffix = renderHeaderFilenameSuffix?.(file);\n const metadata = renderHeaderMetadata?.(file);\n return (\n <>\n {customHeader != null ? (\n <div slot={CUSTOM_HEADER_SLOT_ID}>{customHeader}</div>\n ) : (\n <>\n {prefix != null && <div slot={HEADER_PREFIX_SLOT_ID}>{prefix}</div>}\n {suffix != null && (\n <div slot={HEADER_FILENAME_SUFFIX_SLOT_ID}>{suffix}</div>\n )}\n {metadata != null && (\n <div slot={HEADER_METADATA_SLOT_ID}>{metadata}</div>\n )}\n </>\n )}\n {renderAnnotation != null &&\n lineAnnotations?.map((annotation, index) => (\n <div key={index} slot={getAnnotationSlotName(annotation)}>\n {renderAnnotation(annotation)}\n </div>\n ))}\n {renderGutterUtility != null && (\n <div slot=\"gutter-utility-slot\" style={GutterUtilitySlotStyles}>\n {renderGutterUtility(getHoveredLine)}\n </div>\n )}\n </>\n );\n}\n"],"mappings":";;;;;AA8BA,SAAgB,mBAAuC,EACrD,MACA,oBACA,oBACA,4BACA,sBACA,kBACA,iBACA,qBACA,gBACA,wBAAwB,yBACiC;CACzD,MAAM,eAAe,qBAAqB,IAAI;CAC9C,MAAM,SAAS,qBAAqB,IAAI;CACxC,MAAM,SAAS,6BAA6B,IAAI;CAChD,MAAM,WAAW,uBAAuB,IAAI;CAC5C,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,gBAAgB,OACf,oBAAC,OAAD;GAAK,MAAM;GAAwB,UAAA;EAAkB,CAAA,IAErD,qBAAA,UAAA,EAAA,UAAA;GACG,UAAU,QAAQ,oBAAC,OAAD;IAAK,MAAA;IAA8B,UAAA;GAAY,CAAA;GACjE,UAAU,QACT,oBAAC,OAAD;IAAK,MAAA;IAAuC,UAAA;GAAY,CAAA;GAEzD,YAAY,QACX,oBAAC,OAAD;IAAK,MAAA;IAAgC,UAAA;GAAc,CAAA;EAErD,EAAA,CAAA;EAEH,oBAAoB,QACnB,iBAAiB,KAAK,YAAY,UAChC,oBAAC,OAAD;GAAiB,MAAM,sBAAsB,UAAU;GACpD,UAAA,iBAAiB,
|
|
1
|
+
{"version":3,"file":"renderFileChildren.js","names":[],"sources":["../../../src/react/utils/renderFileChildren.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport {\n CUSTOM_HEADER_SLOT_ID,\n HEADER_FILENAME_SUFFIX_SLOT_ID,\n HEADER_METADATA_SLOT_ID,\n HEADER_PREFIX_SLOT_ID,\n} from '../../constants';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { FileContents, LineAnnotation } from '../../types';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { GutterUtilitySlotStyles } from '../constants';\nimport type { FileProps } from '../types';\n\ninterface RenderFileChildrenProps<LAnnotation, Caret> {\n file: FileContents;\n renderCustomHeader: FileProps<LAnnotation, Caret>['renderCustomHeader'];\n renderHeaderPrefix: FileProps<LAnnotation, Caret>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix?: FileProps<\n LAnnotation,\n Caret\n >['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: FileProps<LAnnotation, Caret>['renderHeaderMetadata'];\n renderAnnotation: FileProps<LAnnotation, Caret>['renderAnnotation'];\n lineAnnotations: FileProps<LAnnotation, Caret>['lineAnnotations'];\n renderGutterUtility: FileProps<LAnnotation, Caret>['renderGutterUtility'];\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n getAnnotationSlotName?(annotation: LineAnnotation<LAnnotation>): string;\n}\n\nexport function renderFileChildren<LAnnotation, Caret>({\n file,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n getAnnotationSlotName = getLineAnnotationName,\n}: RenderFileChildrenProps<LAnnotation, Caret>): ReactNode {\n const customHeader = renderCustomHeader?.(file);\n const prefix = renderHeaderPrefix?.(file);\n const suffix = renderHeaderFilenameSuffix?.(file);\n const metadata = renderHeaderMetadata?.(file);\n return (\n <>\n {customHeader != null ? (\n <div slot={CUSTOM_HEADER_SLOT_ID}>{customHeader}</div>\n ) : (\n <>\n {prefix != null && <div slot={HEADER_PREFIX_SLOT_ID}>{prefix}</div>}\n {suffix != null && (\n <div slot={HEADER_FILENAME_SUFFIX_SLOT_ID}>{suffix}</div>\n )}\n {metadata != null && (\n <div slot={HEADER_METADATA_SLOT_ID}>{metadata}</div>\n )}\n </>\n )}\n {renderAnnotation != null &&\n lineAnnotations?.map((annotation, index) => (\n <div key={index} slot={getAnnotationSlotName(annotation)}>\n {renderAnnotation(annotation, file)}\n </div>\n ))}\n {renderGutterUtility != null && (\n <div slot=\"gutter-utility-slot\" style={GutterUtilitySlotStyles}>\n {renderGutterUtility(getHoveredLine)}\n </div>\n )}\n </>\n );\n}\n"],"mappings":";;;;;AA8BA,SAAgB,mBAAuC,EACrD,MACA,oBACA,oBACA,4BACA,sBACA,kBACA,iBACA,qBACA,gBACA,wBAAwB,yBACiC;CACzD,MAAM,eAAe,qBAAqB,IAAI;CAC9C,MAAM,SAAS,qBAAqB,IAAI;CACxC,MAAM,SAAS,6BAA6B,IAAI;CAChD,MAAM,WAAW,uBAAuB,IAAI;CAC5C,OACE,qBAAA,UAAA,EAAA,UAAA;EACG,gBAAgB,OACf,oBAAC,OAAD;GAAK,MAAM;GAAwB,UAAA;EAAkB,CAAA,IAErD,qBAAA,UAAA,EAAA,UAAA;GACG,UAAU,QAAQ,oBAAC,OAAD;IAAK,MAAA;IAA8B,UAAA;GAAY,CAAA;GACjE,UAAU,QACT,oBAAC,OAAD;IAAK,MAAA;IAAuC,UAAA;GAAY,CAAA;GAEzD,YAAY,QACX,oBAAC,OAAD;IAAK,MAAA;IAAgC,UAAA;GAAc,CAAA;EAErD,EAAA,CAAA;EAEH,oBAAoB,QACnB,iBAAiB,KAAK,YAAY,UAChC,oBAAC,OAAD;GAAiB,MAAM,sBAAsB,UAAU;GACpD,UAAA,iBAAiB,YAAY,IAAI;EAC/B,GAFK,KAEL,CACN;EACF,uBAAuB,QACtB,oBAAC,OAAD;GAAK,MAAK;GAAsB,OAAO;GACpC,UAAA,oBAAoB,cAAc;EAChC,CAAA;CAEP,EAAA,CAAA;AAEN"}
|
|
@@ -23,6 +23,7 @@ interface UseFileDiffInstanceProps<LAnnotation, Caret> {
|
|
|
23
23
|
onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;
|
|
24
24
|
}
|
|
25
25
|
interface UseFileDiffInstanceReturn<LAnnotation> {
|
|
26
|
+
lineAnnotations: DiffLineAnnotation<LAnnotation>[];
|
|
26
27
|
fileDiff: FileDiffMetadata;
|
|
27
28
|
ref(node: HTMLElement | null): void;
|
|
28
29
|
getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileDiffInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"useFileDiffInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"mappings":";;;;;;UAmEU,yBAAyB,aAAa;EAC9C,WAAW;EACX,UAAU;EACV,UAAU;EACV,SAAS,gBAAgB,aAAa;EACtC,eAAe,2BAA2B,aAAa;EACvD;EACA,iBAAiB,mBAAmB;EACpC,eAAe;EACf;EACA,UAAU;EACV;EACA;EACA;EACA;EACA,eAAe,0BAA0B,aAAa;EACtD,iBAAiB,4BAA4B,aAAa;;UAGlD,0BAA0B;EAClC,iBAAiB,mBAAmB;EACpC,UAAU;EACV,IAAI,MAAM;EACV,kBAAkB;EAClB,sBAAsB,YAAY,mBAAmB;;iBAGvC,oBAAoB,aAAa,SAC/C,UACA,SACA,SACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBACf,yBACD,aACA,SACE,0BAA0B"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EMPTY_LINE_ANNOTATIONS } from "../../constants.js";
|
|
1
2
|
import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
|
|
2
3
|
import { areFileTargetsEqual } from "../../utils/areFileTargetsEqual.js";
|
|
3
4
|
import { getLineAnnotationName } from "../../utils/getLineAnnotationName.js";
|
|
@@ -10,6 +11,8 @@ import { useCreateEditor } from "../EditContext.js";
|
|
|
10
11
|
import { noopRender } from "../constants.js";
|
|
11
12
|
import { WorkerPoolContext } from "../WorkerPoolContext.js";
|
|
12
13
|
import { useVirtualizer } from "../Virtualizer.js";
|
|
14
|
+
import { useForceUpdate } from "./useForceUpdate.js";
|
|
15
|
+
import { useNextRenderData } from "./useNextRenderData.js";
|
|
13
16
|
import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
14
17
|
//#region src/react/utils/useFileDiffInstance.ts
|
|
15
18
|
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
@@ -56,6 +59,12 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
|
|
|
56
59
|
parseDiffOptions: options?.parseDiffOptions
|
|
57
60
|
});
|
|
58
61
|
const instanceRef = useRef(null);
|
|
62
|
+
const forceUpdate = useForceUpdate();
|
|
63
|
+
const accepted = useAcceptedValues(acceptedCache, effectiveFileDiff, lineAnnotations);
|
|
64
|
+
const renderData = useNextRenderData(instanceRef, accepted) ?? {
|
|
65
|
+
fileDiff: effectiveFileDiff,
|
|
66
|
+
lineAnnotations: lineAnnotations ?? EMPTY_LINE_ANNOTATIONS
|
|
67
|
+
};
|
|
59
68
|
const disposeEditorRef = useRef(null);
|
|
60
69
|
const pendingAttachRef = useRef(null);
|
|
61
70
|
const getEditor = useStableCallback(() => {
|
|
@@ -72,7 +81,7 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
|
|
|
72
81
|
onEditChange,
|
|
73
82
|
onEditComplete,
|
|
74
83
|
options
|
|
75
|
-
}), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0,
|
|
84
|
+
}), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, forceUpdate);
|
|
76
85
|
else instanceRef.current = new FileDiff(mergeFileDiffOptions({
|
|
77
86
|
controlledSelection,
|
|
78
87
|
hasCustomHeader,
|
|
@@ -80,7 +89,7 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
|
|
|
80
89
|
onEditChange,
|
|
81
90
|
onEditComplete,
|
|
82
91
|
options
|
|
83
|
-
}), !disableWorkerPool ? poolManager : void 0,
|
|
92
|
+
}), !disableWorkerPool ? poolManager : void 0, forceUpdate);
|
|
84
93
|
instanceRef.current.hydrate({
|
|
85
94
|
fileDiff: effectiveFileDiff,
|
|
86
95
|
fileContainer,
|
|
@@ -106,7 +115,7 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
|
|
|
106
115
|
onEditComplete,
|
|
107
116
|
options
|
|
108
117
|
});
|
|
109
|
-
const forceRender =
|
|
118
|
+
const forceRender = !areOptionsEqual(instance.options, newOptions);
|
|
110
119
|
instance.setOptions(newOptions);
|
|
111
120
|
if (!edit) {
|
|
112
121
|
pendingAttachRef.current = null;
|
|
@@ -128,6 +137,7 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
|
|
|
128
137
|
const attach = () => {
|
|
129
138
|
if (instanceRef.current !== instance || disposeEditorRef.current != null || !instance.__canAttachEditor()) return;
|
|
130
139
|
disposeEditorRef.current = applyEdit(instance, getEditor);
|
|
140
|
+
forceUpdate();
|
|
131
141
|
};
|
|
132
142
|
if (instance.__canAttachEditor()) {
|
|
133
143
|
pendingAttachRef.current = null;
|
|
@@ -159,7 +169,7 @@ function useFileDiffInstance({ fileDiff, oldFile, newFile, options, editorOption
|
|
|
159
169
|
const getAnnotationSlotName = useCallback((annotation) => instanceRef.current?.getAnnotationSlotName(annotation) ?? getLineAnnotationName(annotation), []);
|
|
160
170
|
if (asyncAttachError != null) throw asyncAttachError;
|
|
161
171
|
return {
|
|
162
|
-
|
|
172
|
+
...renderData,
|
|
163
173
|
ref,
|
|
164
174
|
getHoveredLine,
|
|
165
175
|
getAnnotationSlotName
|
|
@@ -186,31 +196,26 @@ function useEffectiveFileDiff({ acceptedCache, fileDiff, newFile, oldFile, parse
|
|
|
186
196
|
function isSameFilePair(oldFile, newFile, filePair) {
|
|
187
197
|
return areFileTargetsEqual(oldFile ?? void 0, filePair.oldFile ?? void 0) && areFileTargetsEqual(newFile ?? void 0, filePair.newFile ?? void 0);
|
|
188
198
|
}
|
|
199
|
+
function useAcceptedValues(acceptedCache, fileDiff, lineAnnotations) {
|
|
200
|
+
"use no memo";
|
|
201
|
+
return getAcceptedValues(fileDiff, lineAnnotations, acceptedCache.current);
|
|
202
|
+
}
|
|
203
|
+
function getAcceptedValues(fileDiff, lineAnnotations, accepted) {
|
|
204
|
+
return {
|
|
205
|
+
fileDiff: accepted?.fileDiff != null && areDiffTargetsEqual(fileDiff, accepted.fileDiff.stale) ? accepted.fileDiff.installed : fileDiff,
|
|
206
|
+
lineAnnotations: accepted?.annotations != null && lineAnnotations === accepted.annotations.stale ? accepted.annotations.installed : lineAnnotations
|
|
207
|
+
};
|
|
208
|
+
}
|
|
189
209
|
function resolveAcceptedValues(fileDiff, lineAnnotations, acceptedCache) {
|
|
190
210
|
const { current: accepted } = acceptedCache;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const { fileDiff: acceptedDiff, annotations: acceptedAnnotations } = accepted;
|
|
196
|
-
let resolvedFileDiff = fileDiff;
|
|
197
|
-
if (acceptedDiff != null) {
|
|
198
|
-
if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) resolvedFileDiff = acceptedDiff.installed;
|
|
199
|
-
else accepted.fileDiff = null;
|
|
200
|
-
}
|
|
201
|
-
let resolvedAnnotations = lineAnnotations;
|
|
202
|
-
if (acceptedAnnotations != null) {
|
|
203
|
-
if (lineAnnotations === acceptedAnnotations.stale) resolvedAnnotations = acceptedAnnotations.installed;
|
|
204
|
-
else accepted.annotations = null;
|
|
205
|
-
}
|
|
211
|
+
const resolved = getAcceptedValues(fileDiff, lineAnnotations, accepted);
|
|
212
|
+
if (accepted == null) return resolved;
|
|
213
|
+
if (accepted.fileDiff != null && !areDiffTargetsEqual(fileDiff, accepted.fileDiff.stale)) accepted.fileDiff = null;
|
|
214
|
+
if (lineAnnotations !== accepted.annotations?.stale) accepted.annotations = null;
|
|
206
215
|
if (accepted.fileDiff == null && accepted.annotations == null && accepted.filePair == null) acceptedCache.current = null;
|
|
207
|
-
return
|
|
208
|
-
fileDiff: resolvedFileDiff,
|
|
209
|
-
lineAnnotations: resolvedAnnotations
|
|
210
|
-
};
|
|
216
|
+
return resolved;
|
|
211
217
|
}
|
|
212
218
|
function mergeFileDiffOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility, onEditChange, onEditComplete }) {
|
|
213
|
-
if (!(controlledSelection || hasGutterRenderUtility || hasCustomHeader || onEditChange != null || onEditComplete != null)) return options;
|
|
214
219
|
return {
|
|
215
220
|
...options,
|
|
216
221
|
controlledSelection,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {\n FileDiff,\n type FileDiffEditChangeHandler,\n type FileDiffEditCompleteEvent,\n type FileDiffEditCompleteHandler,\n type FileDiffOptions,\n} from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areDiffTargetsEqual } from '../../utils/areDiffTargetsEqual';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { parseDiffFromFile } from '../../utils/parseDiffFromFile';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedFilePair {\n oldFile: FileContents | null;\n newFile: FileContents | null;\n}\n\ninterface AcceptedCompletion<LAnnotation> {\n fileDiff: {\n installed: FileDiffMetadata;\n stale: FileDiffMetadata;\n } | null;\n filePair: {\n fileDiff: FileDiffMetadata;\n installed: AcceptedFilePair;\n stale: AcceptedFilePair;\n } | null;\n annotations: {\n installed: DiffLineAnnotation<LAnnotation>[] | undefined;\n stale: DiffLineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileDiffInstanceProps<LAnnotation, Caret> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents | null;\n newFile?: FileContents | null;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file-diff', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileDiffInstanceReturn<LAnnotation> {\n fileDiff: FileDiffMetadata;\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getAnnotationSlotName(annotation: DiffLineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileDiffInstance<LAnnotation, Caret>({\n fileDiff,\n oldFile,\n newFile,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileDiffInstanceProps<\n LAnnotation,\n Caret\n>): UseFileDiffInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const [asyncAttachError, setAsyncAttachError] = useState<unknown>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file-diff', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its diff on the instance immediately,\n // but the fileDiff/lineAnnotations props stay pre-edit until the owner's\n // state update lands. This holds the accepted values so the renders in\n // between do not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileDiffEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n fileDiff: {\n installed: event.fileDiff,\n stale: event.originalFileDiff,\n },\n filePair:\n fileDiff == null\n ? {\n fileDiff: event.fileDiff,\n installed: { oldFile: event.oldFile, newFile: event.newFile },\n stale: { oldFile: oldFile ?? null, newFile: newFile ?? null },\n }\n : null,\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n // File-pair inputs parse here. While the file props still match the pair\n // from acceptance time (stale) or the completion event's files (installed),\n // the parse is the accepted diff itself; any other pair clears the record\n // and parses fresh.\n const effectiveFileDiff = useEffectiveFileDiff({\n acceptedCache,\n fileDiff,\n newFile,\n oldFile,\n parseDiffOptions: options?.parseDiffOptions,\n });\n const instanceRef = useRef<\n | FileDiff<LAnnotation, Caret>\n | VirtualizedFileDiff<LAnnotation, Caret>\n | null\n >(null);\n const disposeEditorRef = useRef<() => void>(null);\n const pendingAttachRef = useRef<{ promise: Promise<void> } | null>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n return createEditor('file-diff', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n fileDiff: effectiveFileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n pendingAttachRef.current = null;\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n // setOptions(undefined) is a no-op, so an undefined merge result never\n // requires a forced render — comparing it against the instance's\n // constructor-default options would force a full render on every commit.\n const forceRender =\n newOptions !== undefined &&\n !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit) {\n pendingAttachRef.current = null;\n if (disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n }\n const resolved = resolveAcceptedValues(\n effectiveFileDiff,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n forceRender,\n fileDiff: resolved.fileDiff,\n lineAnnotations: resolved.lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n if (!edit || disposeEditorRef.current != null) {\n return;\n }\n if (createEditor == null) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n\n const attach = (): void => {\n if (\n instanceRef.current !== instance ||\n disposeEditorRef.current != null ||\n !instance.__canAttachEditor()\n ) {\n return;\n }\n disposeEditorRef.current = applyEdit(instance, getEditor);\n };\n // If we're all ready to attach the editor, lets go ahead\n // and do that synchronously\n if (instance.__canAttachEditor()) {\n pendingAttachRef.current = null;\n attach();\n return;\n }\n const promise = instance.__prepareForEditing();\n // If we can't hydrate the files... this will come back undefined,\n // which means there's nothing we can do\n if (promise == null) {\n pendingAttachRef.current = null;\n return;\n }\n // If we are already waiting on a hydration to finish, then there's nothing\n // we need to do\n if (pendingAttachRef.current?.promise === promise) {\n return;\n }\n const pending = { promise };\n pendingAttachRef.current = pending;\n void promise\n .then(() => {\n if (pendingAttachRef.current !== pending) {\n return;\n }\n attach();\n pendingAttachRef.current = null;\n })\n .catch((error: unknown) => {\n if (pendingAttachRef.current === pending) {\n pendingAttachRef.current = null;\n setAsyncAttachError(error);\n }\n });\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: DiffLineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n\n if (asyncAttachError != null) {\n throw asyncAttachError;\n }\n\n return {\n fileDiff: effectiveFileDiff,\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n };\n}\n\ninterface UseEffectiveFileDiffProps<LAnnotation, Caret> {\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>;\n fileDiff: FileDiffMetadata | undefined;\n newFile: FileContents | null | undefined;\n oldFile: FileContents | null | undefined;\n parseDiffOptions: FileDiffOptions<LAnnotation, Caret>['parseDiffOptions'];\n}\n\n// Resolves the diff the instance renders: the `fileDiff` prop when given;\n// otherwise the accepted edit's cached diff while the file props still name the\n// pair it was accepted against; otherwise a fresh parse of the file props. A\n// cached pair that no longer matches is dropped on the way. Kept in its own hook\n// because the render-time ref read and write are deliberate; the boundary lets\n// the calling hook stay compilable.\nfunction useEffectiveFileDiff<LAnnotation, Caret>({\n acceptedCache,\n fileDiff,\n newFile,\n oldFile,\n parseDiffOptions,\n}: UseEffectiveFileDiffProps<LAnnotation, Caret>): FileDiffMetadata {\n /* oxlint-disable react/immutability react/refs -- accepted edit output must\n * replace stale file-pair props during render */\n const effectiveFileDiff = useMemo(() => {\n if (fileDiff != null) {\n return fileDiff;\n }\n const { current: accepted } = acceptedCache;\n const filePair = accepted?.filePair;\n if (accepted != null && filePair != null) {\n if (\n isSameFilePair(oldFile, newFile, filePair.stale) ||\n isSameFilePair(oldFile, newFile, filePair.installed)\n ) {\n return filePair.fileDiff;\n }\n accepted.filePair = null;\n }\n return parseDiffFromFile(\n oldFile ?? null,\n newFile ?? null,\n parseDiffOptions\n );\n }, [acceptedCache, fileDiff, oldFile, newFile, parseDiffOptions]);\n /* oxlint-enable react/immutability react/refs */\n\n return effectiveFileDiff;\n}\n\n// Whether the file props name the same files as a recorded pair.\nfunction isSameFilePair(\n oldFile: FileContents | null | undefined,\n newFile: FileContents | null | undefined,\n filePair: AcceptedFilePair\n): boolean {\n return (\n areFileTargetsEqual(oldFile ?? undefined, filePair.oldFile ?? undefined) &&\n areFileTargetsEqual(newFile ?? undefined, filePair.newFile ?? undefined)\n );\n}\n\n// Render the installed values in place of props that still match their stale\n// counterparts. Any other prop value clears its slot — filePair settles in\n// the parse memo instead — and the ref clears once all three have.\nfunction resolveAcceptedValues<LAnnotation>(\n fileDiff: FileDiffMetadata,\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): {\n fileDiff: FileDiffMetadata;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n} {\n const { current: accepted } = acceptedCache;\n if (accepted == null) {\n return { fileDiff, lineAnnotations };\n }\n const { fileDiff: acceptedDiff, annotations: acceptedAnnotations } = accepted;\n let resolvedFileDiff = fileDiff;\n if (acceptedDiff != null) {\n if (areDiffTargetsEqual(fileDiff, acceptedDiff.stale)) {\n resolvedFileDiff = acceptedDiff.installed;\n } else {\n accepted.fileDiff = null;\n }\n }\n let resolvedAnnotations = lineAnnotations;\n if (acceptedAnnotations != null) {\n if (lineAnnotations === acceptedAnnotations.stale) {\n resolvedAnnotations = acceptedAnnotations.installed;\n } else {\n accepted.annotations = null;\n }\n }\n if (\n accepted.fileDiff == null &&\n accepted.annotations == null &&\n accepted.filePair == null\n ) {\n acceptedCache.current = null;\n }\n return { fileDiff: resolvedFileDiff, lineAnnotations: resolvedAnnotations };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation, Caret> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileDiffOptionsProps<LAnnotation, Caret>):\n | FileDiffOptions<LAnnotation, Caret>\n | undefined {\n const needsReactOverrides =\n controlledSelection ||\n hasGutterRenderUtility ||\n hasCustomHeader ||\n onEditChange != null ||\n onEditComplete != null;\n\n if (!needsReactOverrides) {\n return options;\n }\n\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: FileDiff<LAnnotation, Caret>,\n getEditor: () => Editor<'file-diff', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n type RefObject,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\n\nimport {\n FileDiff,\n type FileDiffEditChangeHandler,\n type FileDiffEditCompleteEvent,\n type FileDiffEditCompleteHandler,\n type FileDiffOptions,\n type FileDiffRenderInput,\n} from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport { EMPTY_LINE_ANNOTATIONS } from '../../constants';\nimport type { Editor, EditorChangeEvent, EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areDiffTargetsEqual } from '../../utils/areDiffTargetsEqual';\nimport { areFileTargetsEqual } from '../../utils/areFileTargetsEqual';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { parseDiffFromFile } from '../../utils/parseDiffFromFile';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useForceUpdate } from './useForceUpdate';\nimport { useNextRenderData } from './useNextRenderData';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface AcceptedFilePair {\n oldFile: FileContents | null;\n newFile: FileContents | null;\n}\n\ninterface AcceptedCompletion<LAnnotation> {\n fileDiff: {\n installed: FileDiffMetadata;\n stale: FileDiffMetadata;\n } | null;\n filePair: {\n fileDiff: FileDiffMetadata;\n installed: AcceptedFilePair;\n stale: AcceptedFilePair;\n } | null;\n annotations: {\n installed: DiffLineAnnotation<LAnnotation>[] | undefined;\n stale: DiffLineAnnotation<LAnnotation>[];\n } | null;\n}\n\ninterface UseFileDiffInstanceProps<LAnnotation, Caret> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents | null;\n newFile?: FileContents | null;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n editorOptions: EditorOptions<'file-diff', LAnnotation, Caret> | undefined;\n editStateKey: string | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n}\n\ninterface UseFileDiffInstanceReturn<LAnnotation> {\n lineAnnotations: DiffLineAnnotation<LAnnotation>[];\n fileDiff: FileDiffMetadata;\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n getAnnotationSlotName(annotation: DiffLineAnnotation<LAnnotation>): string;\n}\n\nexport function useFileDiffInstance<LAnnotation, Caret>({\n fileDiff,\n oldFile,\n newFile,\n options,\n editorOptions,\n editStateKey,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n onEditChange: _onEditChange,\n onEditComplete: _onEditComplete,\n}: UseFileDiffInstanceProps<\n LAnnotation,\n Caret\n>): UseFileDiffInstanceReturn<LAnnotation> {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation, Caret>();\n const [asyncAttachError, setAsyncAttachError] = useState<unknown>();\n const handleOnEditChange = useStableCallback(\n (event: EditorChangeEvent<'file-diff', LAnnotation, Caret>) =>\n _onEditChange?.(event)\n );\n const onEditChange = _onEditChange != null ? handleOnEditChange : undefined;\n // An accepted completion installs its diff on the instance immediately,\n // but the fileDiff/lineAnnotations props stay pre-edit until the owner's\n // state update lands. This holds the accepted values so the renders in\n // between do not repaint pre-edit state.\n const acceptedCache = useRef<AcceptedCompletion<LAnnotation> | null>(null);\n const handleOnEditComplete = useStableCallback(\n (event: FileDiffEditCompleteEvent<LAnnotation, Caret>) => {\n const decision = _onEditComplete?.(event) ?? 'reject';\n if (decision === 'accept') {\n acceptedCache.current = {\n fileDiff: {\n installed: event.fileDiff,\n stale: event.originalFileDiff,\n },\n filePair:\n fileDiff == null\n ? {\n fileDiff: event.fileDiff,\n installed: { oldFile: event.oldFile, newFile: event.newFile },\n stale: { oldFile: oldFile ?? null, newFile: newFile ?? null },\n }\n : null,\n annotations: {\n installed: event.lineAnnotations,\n stale: event.originalLineAnnotations,\n },\n };\n }\n return decision;\n }\n );\n const onEditComplete =\n _onEditComplete != null ? handleOnEditComplete : undefined;\n const effectiveFileDiff = useEffectiveFileDiff({\n acceptedCache,\n fileDiff,\n newFile,\n oldFile,\n parseDiffOptions: options?.parseDiffOptions,\n });\n const instanceRef = useRef<\n | FileDiff<LAnnotation, Caret>\n | VirtualizedFileDiff<LAnnotation, Caret>\n | null\n >(null);\n const forceUpdate = useForceUpdate();\n const accepted = useAcceptedValues(\n acceptedCache,\n effectiveFileDiff,\n lineAnnotations\n );\n const renderData = useNextRenderData(instanceRef, accepted) ?? {\n fileDiff: effectiveFileDiff,\n lineAnnotations: lineAnnotations ?? EMPTY_LINE_ANNOTATIONS,\n };\n const disposeEditorRef = useRef<() => void>(null);\n const pendingAttachRef = useRef<{ promise: Promise<void> } | null>(null);\n const getEditor = useStableCallback(() => {\n if (createEditor == null) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n return createEditor('file-diff', editorOptions ?? {}, editStateKey);\n });\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n forceUpdate\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n forceUpdate\n );\n }\n void instanceRef.current.hydrate({\n fileDiff: effectiveFileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n pendingAttachRef.current = null;\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n disposeEditorRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n // Detach editor before rendering if required\n if (!edit) {\n pendingAttachRef.current = null;\n if (disposeEditorRef.current != null) {\n const { current: disposeEditor } = disposeEditorRef;\n disposeEditorRef.current = null;\n disposeEditor();\n }\n }\n const resolved = resolveAcceptedValues(\n effectiveFileDiff,\n lineAnnotations,\n acceptedCache\n );\n void instance.render({\n forceRender,\n fileDiff: resolved.fileDiff,\n lineAnnotations: resolved.lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n if (!edit || disposeEditorRef.current != null) {\n return;\n }\n if (createEditor == null) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n\n const attach = (): void => {\n if (\n instanceRef.current !== instance ||\n disposeEditorRef.current != null ||\n !instance.__canAttachEditor()\n ) {\n return;\n }\n disposeEditorRef.current = applyEdit(instance, getEditor);\n // The editor can show content that is still highlighting, so render the\n // children again from the edit session.\n forceUpdate();\n };\n // If we're all ready to attach the editor, lets go ahead\n // and do that synchronously\n if (instance.__canAttachEditor()) {\n pendingAttachRef.current = null;\n attach();\n return;\n }\n const promise = instance.__prepareForEditing();\n // If we can't hydrate the files... this will come back undefined,\n // which means there's nothing we can do\n if (promise == null) {\n pendingAttachRef.current = null;\n return;\n }\n // If we are already waiting on a hydration to finish, then there's nothing\n // we need to do\n if (pendingAttachRef.current?.promise === promise) {\n return;\n }\n const pending = { promise };\n pendingAttachRef.current = pending;\n void promise\n .then(() => {\n if (pendingAttachRef.current !== pending) {\n return;\n }\n attach();\n pendingAttachRef.current = null;\n })\n .catch((error: unknown) => {\n if (pendingAttachRef.current === pending) {\n pendingAttachRef.current = null;\n setAsyncAttachError(error);\n }\n });\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n const getAnnotationSlotName = useCallback(\n (annotation: DiffLineAnnotation<LAnnotation>): string =>\n instanceRef.current?.getAnnotationSlotName(annotation) ??\n getLineAnnotationName(annotation),\n []\n );\n\n if (asyncAttachError != null) {\n throw asyncAttachError;\n }\n\n return {\n ...renderData,\n ref,\n getHoveredLine,\n getAnnotationSlotName,\n };\n}\n\ninterface UseEffectiveFileDiffProps<LAnnotation, Caret> {\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>;\n fileDiff: FileDiffMetadata | undefined;\n newFile: FileContents | null | undefined;\n oldFile: FileContents | null | undefined;\n parseDiffOptions: FileDiffOptions<LAnnotation, Caret>['parseDiffOptions'];\n}\n\n// Return the diff to render: the fileDiff prop, or a parse of the file props.\n// While the file props still match the accepted edit's original or completed\n// files, return the accepted diff instead. Other files remove the filePair\n// entry. The ref is read and written during render on purpose, so that stays\n// in this hook instead of the caller.\nfunction useEffectiveFileDiff<LAnnotation, Caret>({\n acceptedCache,\n fileDiff,\n newFile,\n oldFile,\n parseDiffOptions,\n}: UseEffectiveFileDiffProps<LAnnotation, Caret>): FileDiffMetadata {\n /* oxlint-disable react/immutability react/refs -- accepted edit output must\n * replace stale file-pair props during render */\n const effectiveFileDiff = useMemo(() => {\n if (fileDiff != null) {\n return fileDiff;\n }\n const { current: accepted } = acceptedCache;\n const filePair = accepted?.filePair;\n if (accepted != null && filePair != null) {\n if (\n isSameFilePair(oldFile, newFile, filePair.stale) ||\n isSameFilePair(oldFile, newFile, filePair.installed)\n ) {\n return filePair.fileDiff;\n }\n accepted.filePair = null;\n }\n return parseDiffFromFile(\n oldFile ?? null,\n newFile ?? null,\n parseDiffOptions\n );\n }, [acceptedCache, fileDiff, oldFile, newFile, parseDiffOptions]);\n /* oxlint-enable react/immutability react/refs */\n\n return effectiveFileDiff;\n}\n\n// Whether the file props name the same files as a recorded pair.\nfunction isSameFilePair(\n oldFile: FileContents | null | undefined,\n newFile: FileContents | null | undefined,\n filePair: AcceptedFilePair\n): boolean {\n return (\n areFileTargetsEqual(oldFile ?? undefined, filePair.oldFile ?? undefined) &&\n areFileTargetsEqual(newFile ?? undefined, filePair.newFile ?? undefined)\n );\n}\n\n// Read the accepted values on every render. Entries are only removed in the\n// effect, by resolveAcceptedValues. The cache changes without new props, so\n// this must not be memoized.\nfunction useAcceptedValues<LAnnotation>(\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>,\n fileDiff: FileDiffMetadata,\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined\n): FileDiffRenderInput<LAnnotation> {\n 'use no memo';\n // oxlint-disable-next-line react/refs -- the cache changes without new props\n return getAcceptedValues(fileDiff, lineAnnotations, acceptedCache.current);\n}\n\n// Use the accepted values for props that still hold their pre-edit values.\nfunction getAcceptedValues<LAnnotation>(\n fileDiff: FileDiffMetadata,\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined,\n accepted: AcceptedCompletion<LAnnotation> | null\n): FileDiffRenderInput<LAnnotation> {\n return {\n fileDiff:\n accepted?.fileDiff != null &&\n areDiffTargetsEqual(fileDiff, accepted.fileDiff.stale)\n ? accepted.fileDiff.installed\n : fileDiff,\n lineAnnotations:\n accepted?.annotations != null &&\n lineAnnotations === accepted.annotations.stale\n ? accepted.annotations.installed\n : lineAnnotations,\n };\n}\n\n// Return the accepted values, and drop each one once its prop no longer holds\n// the pre-edit value. useEffectiveFileDiff drops the filePair entry. The cache\n// is cleared once every entry is dropped.\nfunction resolveAcceptedValues<LAnnotation>(\n fileDiff: FileDiffMetadata,\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined,\n acceptedCache: RefObject<AcceptedCompletion<LAnnotation> | null>\n): FileDiffRenderInput<LAnnotation> {\n const { current: accepted } = acceptedCache;\n const resolved = getAcceptedValues(fileDiff, lineAnnotations, accepted);\n if (accepted == null) {\n return resolved;\n }\n if (\n accepted.fileDiff != null &&\n !areDiffTargetsEqual(fileDiff, accepted.fileDiff.stale)\n ) {\n accepted.fileDiff = null;\n }\n if (lineAnnotations !== accepted.annotations?.stale) {\n accepted.annotations = null;\n }\n if (\n accepted.fileDiff == null &&\n accepted.annotations == null &&\n accepted.filePair == null\n ) {\n acceptedCache.current = null;\n }\n return resolved;\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation, Caret> {\n controlledSelection: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n onEditChange?: FileDiffEditChangeHandler<LAnnotation, Caret>;\n onEditComplete?: FileDiffEditCompleteHandler<LAnnotation, Caret>;\n options: FileDiffOptions<LAnnotation, Caret> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation, Caret>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n onEditChange,\n onEditComplete,\n}: MergeFileDiffOptionsProps<LAnnotation, Caret>): FileDiffOptions<\n LAnnotation,\n Caret\n> {\n return {\n ...options,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n onEditChange,\n onEditComplete,\n };\n}\n\nfunction applyEdit<LAnnotation, Caret>(\n instance: FileDiff<LAnnotation, Caret>,\n getEditor: () => Editor<'file-diff', LAnnotation, Caret>\n): () => void {\n const editor = getEditor();\n try {\n return editor.edit(instance);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n}\n"],"mappings":"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"}
|
|
@@ -21,6 +21,8 @@ interface UseFileInstanceProps<LAnnotation, Caret> {
|
|
|
21
21
|
onEditComplete?: FileEditCompleteHandler<LAnnotation, Caret>;
|
|
22
22
|
}
|
|
23
23
|
interface UseFileInstanceReturn<LAnnotation> {
|
|
24
|
+
file: FileContents;
|
|
25
|
+
lineAnnotations: LineAnnotation<LAnnotation>[];
|
|
24
26
|
ref(node: HTMLElement | null): void;
|
|
25
27
|
getHoveredLine(): GetHoveredLineResult<'file'> | undefined;
|
|
26
28
|
getAnnotationSlotName(annotation: LineAnnotation<LAnnotation>): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;;UAoDU,qBAAqB,aAAa;EAC1C,MAAM;EACN,SAAS,YAAY,aAAa;EAClC,eAAe,sBAAsB,aAAa;EAClD;EACA,iBAAiB,eAAe;EAChC,eAAe;EACf;EACA,UAAU;EACV;EACA;EACA;EACA;EACA,eAAe,sBAAsB,aAAa;EAClD,iBAAiB,wBAAwB,aAAa;;UAG9C,sBAAsB;EAC9B,MAAM;EACN,iBAAiB,eAAe;EAChC,IAAI,MAAM;EACV,kBAAkB;EAClB,sBAAsB,YAAY,eAAe;;iBAGnC,gBAAgB,aAAa,SAC3C,MACA,SACA,eACA,cACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,MACA,cAAc,eACd,gBAAgB,mBACf,qBACD,aACA,SACE,sBAAsB"}
|