@pierre/diffs 1.3.0-beta.8 → 1.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeView.d.ts +12 -12
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +51 -43
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +7 -2
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +36 -8
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +34 -6
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +198 -17
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/FileStream.d.ts.map +1 -1
- package/dist/components/FileStream.js +2 -1
- package/dist/components/FileStream.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +2 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +9 -5
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +14 -0
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +61 -3
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/Virtualizer.d.ts +14 -2
- package/dist/components/Virtualizer.d.ts.map +1 -1
- package/dist/components/Virtualizer.js +29 -3
- package/dist/components/Virtualizer.js.map +1 -1
- package/dist/edit/index.d.ts +5 -0
- package/dist/edit/index.js +3 -0
- package/dist/editor/command.d.ts +1 -1
- package/dist/editor/command.d.ts.map +1 -1
- package/dist/editor/command.js +11 -0
- package/dist/editor/command.js.map +1 -1
- package/dist/editor/editStack.d.ts +6 -2
- package/dist/editor/editStack.d.ts.map +1 -1
- package/dist/editor/editStack.js +54 -13
- package/dist/editor/editStack.js.map +1 -1
- package/dist/editor/editor.d.ts +51 -23
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +995 -242
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/languages.d.ts +26 -0
- package/dist/editor/languages.d.ts.map +1 -0
- package/dist/editor/languages.js +363 -0
- package/dist/editor/languages.js.map +1 -0
- package/dist/editor/lineAnnotations.d.ts.map +1 -1
- package/dist/editor/lineAnnotations.js +25 -26
- package/dist/editor/lineAnnotations.js.map +1 -1
- package/dist/editor/marker.d.ts +5 -3
- package/dist/editor/marker.d.ts.map +1 -1
- package/dist/editor/marker.js +111 -91
- package/dist/editor/marker.js.map +1 -1
- package/dist/editor/matchBrackets.d.ts +3 -2
- package/dist/editor/matchBrackets.d.ts.map +1 -1
- package/dist/editor/matchBrackets.js +2 -10
- package/dist/editor/matchBrackets.js.map +1 -1
- package/dist/editor/pieceTable.d.ts +2 -1
- package/dist/editor/pieceTable.d.ts.map +1 -1
- package/dist/editor/pieceTable.js +103 -39
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/platform.js +2 -0
- package/dist/editor/platform.js.map +1 -1
- package/dist/editor/popover.d.ts +25 -5
- package/dist/editor/popover.d.ts.map +1 -1
- package/dist/editor/popover.js +60 -14
- package/dist/editor/popover.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +1 -0
- package/dist/editor/searchPanel.d.ts.map +1 -1
- package/dist/editor/searchPanel.js +15 -8
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +31 -11
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +198 -70
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/selectionAction.d.ts +4 -3
- package/dist/editor/selectionAction.d.ts.map +1 -1
- package/dist/editor/selectionAction.js +9 -5
- package/dist/editor/selectionAction.js.map +1 -1
- package/dist/editor/stateStorage.d.ts +15 -0
- package/dist/editor/stateStorage.d.ts.map +1 -0
- package/dist/editor/stateStorage.js +65 -0
- package/dist/editor/stateStorage.js.map +1 -0
- package/dist/editor/textDocument.d.ts +12 -77
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +76 -34
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/textMeasure.d.ts +7 -12
- package/dist/editor/textMeasure.d.ts.map +1 -1
- package/dist/editor/textMeasure.js +40 -32
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/{tokenzier.d.ts → tokenizer.d.ts} +3 -3
- package/dist/editor/tokenizer.d.ts.map +1 -0
- package/dist/editor/{tokenzier.js → tokenizer.js} +91 -26
- package/dist/editor/tokenizer.js.map +1 -0
- package/dist/editor/utils.js +1 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.js +7 -6
- package/dist/managers/InteractionManager.d.ts +18 -7
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +154 -99
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/managers/UniversalRenderingManager.d.ts +2 -1
- package/dist/managers/UniversalRenderingManager.d.ts.map +1 -1
- package/dist/managers/UniversalRenderingManager.js +7 -3
- package/dist/managers/UniversalRenderingManager.js.map +1 -1
- package/dist/react/CodeView.d.ts +13 -13
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +38 -29
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/EditContext.d.ts +20 -0
- package/dist/react/EditContext.d.ts.map +1 -0
- package/dist/react/EditContext.js +20 -0
- package/dist/react/EditContext.js.map +1 -0
- package/dist/react/File.d.ts +2 -1
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +3 -2
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +2 -2
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +3 -2
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +2 -2
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +3 -2
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +2 -2
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +3 -2
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +1 -1
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +3 -3
- package/dist/react/types.d.ts +9 -1
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +5 -3
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +28 -27
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +5 -3
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +29 -25
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +3 -3
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +33 -1
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +134 -21
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +2 -0
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +33 -11
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/FileDiffReact.js +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.js +1 -1
- package/dist/style.js +1 -1
- package/dist/types.d.ts +185 -42
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/annotationHelpers.d.ts +20 -0
- package/dist/utils/annotationHelpers.d.ts.map +1 -0
- package/dist/utils/annotationHelpers.js +29 -0
- package/dist/utils/annotationHelpers.js.map +1 -0
- package/dist/utils/computeFileOffsets.d.ts.map +1 -1
- package/dist/utils/computeFileOffsets.js +34 -5
- package/dist/utils/computeFileOffsets.js.map +1 -1
- package/dist/utils/editSessionHunks.d.ts +66 -0
- package/dist/utils/editSessionHunks.d.ts.map +1 -0
- package/dist/utils/editSessionHunks.js +437 -0
- package/dist/utils/editSessionHunks.js.map +1 -0
- package/dist/utils/getHunkSideBoundaries.d.ts +7 -0
- package/dist/utils/getHunkSideBoundaries.d.ts.map +1 -0
- package/dist/utils/getHunkSideBoundaries.js +12 -0
- package/dist/utils/getHunkSideBoundaries.js.map +1 -0
- package/dist/utils/getTotalLineCountFromHunks.d.ts.map +1 -1
- package/dist/utils/getTotalLineCountFromHunks.js +2 -1
- package/dist/utils/getTotalLineCountFromHunks.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -1
- package/dist/utils/hydratePartialDiff.js +4 -3
- package/dist/utils/hydratePartialDiff.js.map +1 -1
- package/dist/utils/isGutterUtilityPath.d.ts +5 -0
- package/dist/utils/isGutterUtilityPath.d.ts.map +1 -0
- package/dist/utils/isGutterUtilityPath.js +12 -0
- package/dist/utils/isGutterUtilityPath.js.map +1 -0
- package/dist/utils/iterateOverDiff.d.ts.map +1 -1
- package/dist/utils/iterateOverDiff.js +17 -12
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.js +9 -6
- package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +6 -3
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/realignChangeContent.d.ts +33 -0
- package/dist/utils/realignChangeContent.d.ts.map +1 -0
- package/dist/utils/realignChangeContent.js +148 -0
- package/dist/utils/realignChangeContent.js.map +1 -0
- package/dist/utils/renderDiffWithHighlighter.js +1 -1
- package/dist/utils/resolveRegion.d.ts.map +1 -1
- package/dist/utils/resolveRegion.js +18 -2
- package/dist/utils/resolveRegion.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +8 -2
- package/dist/utils/updateDiffHunks.d.ts.map +1 -1
- package/dist/utils/updateDiffHunks.js +9 -7
- package/dist/utils/updateDiffHunks.js.map +1 -1
- package/dist/utils/virtualDiffLayout.d.ts +42 -2
- package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
- package/dist/utils/virtualDiffLayout.js +101 -7
- package/dist/utils/virtualDiffLayout.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +4 -2
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/types.d.ts +4 -0
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +60 -20
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +61 -19
- package/dist/worker/worker.js.map +1 -1
- package/package.json +13 -8
- package/dist/editor/index.d.ts +0 -3
- package/dist/editor/index.js +0 -3
- package/dist/editor/tokenzier.d.ts.map +0 -1
- package/dist/editor/tokenzier.js.map +0 -1
- package/dist/react/EditorContext.d.ts +0 -15
- package/dist/react/EditorContext.d.ts.map +0 -1
- package/dist/react/EditorContext.js +0 -23
- package/dist/react/EditorContext.js.map +0 -1
|
@@ -7,7 +7,7 @@ import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
|
|
|
7
7
|
import { useMemo } from "react";
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
//#region src/react/MultiFileDiff.tsx
|
|
10
|
-
function MultiFileDiff({ oldFile, newFile, options, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false,
|
|
10
|
+
function MultiFileDiff({ oldFile, newFile, options, editorOptions, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false, edit = false }) {
|
|
11
11
|
const fileDiff = useMemo(() => {
|
|
12
12
|
return parseDiffFromFile(oldFile, newFile, options?.parseDiffOptions);
|
|
13
13
|
}, [
|
|
@@ -18,6 +18,7 @@ function MultiFileDiff({ oldFile, newFile, options, metrics, lineAnnotations, se
|
|
|
18
18
|
const { ref, getHoveredLine } = useFileDiffInstance({
|
|
19
19
|
fileDiff,
|
|
20
20
|
options,
|
|
21
|
+
editorOptions,
|
|
21
22
|
metrics,
|
|
22
23
|
lineAnnotations,
|
|
23
24
|
selectedLines,
|
|
@@ -25,7 +26,7 @@ function MultiFileDiff({ oldFile, newFile, options, metrics, lineAnnotations, se
|
|
|
25
26
|
hasGutterRenderUtility: renderGutterUtility != null,
|
|
26
27
|
hasCustomHeader: renderCustomHeader != null,
|
|
27
28
|
disableWorkerPool,
|
|
28
|
-
|
|
29
|
+
edit
|
|
29
30
|
});
|
|
30
31
|
return /* @__PURE__ */ jsx(DIFFS_TAG_NAME, {
|
|
31
32
|
ref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiFileDiff.js","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { DiffFileInput, FileContents } from '../types';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\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<\n LAnnotation,\n> extends DiffBasePropsReact<LAnnotation> {\n disableWorkerPool?: boolean;\n
|
|
1
|
+
{"version":3,"file":"MultiFileDiff.js","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { DiffFileInput, FileContents } from '../types';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\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<\n LAnnotation,\n> extends DiffBasePropsReact<LAnnotation> {\n disableWorkerPool?: boolean;\n}\n\nexport type MultiFileDiffProps<LAnnotation> =\n MultiFileDiffBaseProps<LAnnotation> & DiffFileInput;\n\nexport function MultiFileDiff<LAnnotation = undefined>({\n oldFile,\n newFile,\n options,\n editorOptions,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n}: MultiFileDiffProps<LAnnotation>): React.JSX.Element {\n const fileDiff = useMemo(() => {\n return parseDiffFromFile(oldFile, newFile, options?.parseDiffOptions);\n }, [oldFile, newFile, options?.parseDiffOptions]);\n const { ref, getHoveredLine } = useFileDiffInstance({\n fileDiff,\n options,\n editorOptions,\n metrics,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n edit,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;;;AAuBA,SAAgB,cAAuC,EACrD,SACA,SACA,SACA,eACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,oBAAoB,OACpB,OAAO,SAC8C;CACrD,MAAM,WAAW,cAAc;EAC7B,OAAO,kBAAkB,SAAS,SAAS,SAAS,gBAAgB;CACtE,GAAG;EAAC;EAAS;EAAS,SAAS;CAAgB,CAAC;CAChD,MAAM,EAAE,KAAK,mBAAmB,oBAAoB;EAClD;EACA;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;EACA;CACF,CAAC;CAYD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;YACpD,eAbY,mBAAmB;GAClC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAG2B,GAAG,eAAe;CAC3B,CAAA;AAEpB"}
|
|
@@ -4,11 +4,11 @@ import { DiffBasePropsReact } from "./types.js";
|
|
|
4
4
|
interface PatchDiffProps<LAnnotation> extends DiffBasePropsReact<LAnnotation> {
|
|
5
5
|
patch: string;
|
|
6
6
|
disableWorkerPool?: boolean;
|
|
7
|
-
contentEditable?: boolean;
|
|
8
7
|
}
|
|
9
8
|
declare function PatchDiff<LAnnotation = undefined>({
|
|
10
9
|
patch,
|
|
11
10
|
options,
|
|
11
|
+
editorOptions,
|
|
12
12
|
metrics,
|
|
13
13
|
lineAnnotations,
|
|
14
14
|
selectedLines,
|
|
@@ -22,7 +22,7 @@ declare function PatchDiff<LAnnotation = undefined>({
|
|
|
22
22
|
renderHeaderMetadata,
|
|
23
23
|
renderGutterUtility,
|
|
24
24
|
disableWorkerPool,
|
|
25
|
-
|
|
25
|
+
edit
|
|
26
26
|
}: PatchDiffProps<LAnnotation>): React.JSX.Element;
|
|
27
27
|
//#endregion
|
|
28
28
|
export { PatchDiff, PatchDiffProps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PatchDiff.d.ts","names":[],"sources":["../../src/react/PatchDiff.tsx"],"mappings":";;;UAYiB,cAAA,sBAEP,kBAAkB,CAAC,WAAA;EAC3B,KAAA;EACA,iBAAA;
|
|
1
|
+
{"version":3,"file":"PatchDiff.d.ts","names":[],"sources":["../../src/react/PatchDiff.tsx"],"mappings":";;;UAYiB,cAAA,sBAEP,kBAAkB,CAAC,WAAA;EAC3B,KAAA;EACA,iBAAA;AAAA;AAAA,iBAGc,SAAA;EACd,KAAA;EACA,OAAA;EACA,aAAA;EACA,OAAA;EACA,eAAA;EACA,aAAA;EACA,SAAA;EACA,KAAA;EACA,eAAA;EACA,gBAAA;EACA,kBAAA;EACA,kBAAA;EACA,0BAAA;EACA,oBAAA;EACA,mBAAA;EACA,iBAAA;EACA;AAAA,GACC,cAAA,CAAe,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,OAAA"}
|
package/dist/react/PatchDiff.js
CHANGED
|
@@ -7,11 +7,12 @@ import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
|
|
|
7
7
|
import { useMemo } from "react";
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
//#region src/react/PatchDiff.tsx
|
|
10
|
-
function PatchDiff({ patch, options, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false,
|
|
10
|
+
function PatchDiff({ patch, options, editorOptions, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false, edit = false }) {
|
|
11
11
|
const fileDiff = usePatch(patch);
|
|
12
12
|
const { ref, getHoveredLine } = useFileDiffInstance({
|
|
13
13
|
fileDiff,
|
|
14
14
|
options,
|
|
15
|
+
editorOptions,
|
|
15
16
|
metrics,
|
|
16
17
|
lineAnnotations,
|
|
17
18
|
selectedLines,
|
|
@@ -19,7 +20,7 @@ function PatchDiff({ patch, options, metrics, lineAnnotations, selectedLines, cl
|
|
|
19
20
|
hasGutterRenderUtility: renderGutterUtility != null,
|
|
20
21
|
hasCustomHeader: renderCustomHeader != null,
|
|
21
22
|
disableWorkerPool,
|
|
22
|
-
|
|
23
|
+
edit
|
|
23
24
|
});
|
|
24
25
|
return /* @__PURE__ */ jsx(DIFFS_TAG_NAME, {
|
|
25
26
|
ref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PatchDiff.js","names":[],"sources":["../../src/react/PatchDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport { getSingularPatch } from '../utils/getSingularPatch';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport interface PatchDiffProps<\n LAnnotation,\n> extends DiffBasePropsReact<LAnnotation> {\n patch: string;\n disableWorkerPool?: boolean;\n
|
|
1
|
+
{"version":3,"file":"PatchDiff.js","names":[],"sources":["../../src/react/PatchDiff.tsx"],"sourcesContent":["'use client';\n\nimport { useMemo } from 'react';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport { getSingularPatch } from '../utils/getSingularPatch';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport interface PatchDiffProps<\n LAnnotation,\n> extends DiffBasePropsReact<LAnnotation> {\n patch: string;\n disableWorkerPool?: boolean;\n}\n\nexport function PatchDiff<LAnnotation = undefined>({\n patch,\n options,\n editorOptions,\n metrics,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n}: PatchDiffProps<LAnnotation>): React.JSX.Element {\n const fileDiff = usePatch(patch);\n const { ref, getHoveredLine } = useFileDiffInstance({\n fileDiff,\n options,\n editorOptions,\n metrics,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n edit,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n\nfunction usePatch(patch: string): FileDiffMetadata {\n return useMemo<FileDiffMetadata>(() => getSingularPatch(patch), [patch]);\n}\n"],"mappings":";;;;;;;;;AAmBA,SAAgB,UAAmC,EACjD,OACA,SACA,eACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,oBAAoB,OACpB,OAAO,SAC0C;CACjD,MAAM,WAAW,SAAS,KAAK;CAC/B,MAAM,EAAE,KAAK,mBAAmB,oBAAoB;EAClD;EACA;EACA;EACA;EACA;EACA;EACA;EACA,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;EACA;CACF,CAAC;CAYD,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;YACpD,eAbY,mBAAmB;GAClC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAG2B,GAAG,eAAe;CAC3B,CAAA;AAEpB;AAEA,SAAS,SAAS,OAAiC;CACjD,OAAO,cAAgC,iBAAiB,KAAK,GAAG,CAAC,KAAK,CAAC;AACzE"}
|
|
@@ -17,7 +17,7 @@ interface UnresolvedFileReactOptions<LAnnotation> extends Omit<FileDiffOptions<L
|
|
|
17
17
|
onPostRender?(node: HTMLElement, instance: UnresolvedFile$1<LAnnotation>, phase: PostRenderPhase): unknown;
|
|
18
18
|
maxContextLines?: number;
|
|
19
19
|
}
|
|
20
|
-
interface UnresolvedFileProps<LAnnotation> extends Omit<FileDiffProps<LAnnotation>, 'fileDiff' | 'options'> {
|
|
20
|
+
interface UnresolvedFileProps<LAnnotation> extends Omit<FileDiffProps<LAnnotation>, 'fileDiff' | 'options' | 'edit' | 'editorOptions'> {
|
|
21
21
|
file: FileContents;
|
|
22
22
|
options?: UnresolvedFileReactOptions<LAnnotation>;
|
|
23
23
|
renderMergeConflictUtility?(action: MergeConflictDiffAction, getInstance: () => UnresolvedFile$1<LAnnotation> | undefined): ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnresolvedFile.js","names":[],"sources":["../../src/react/UnresolvedFile.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\n\nimport type { FileDiffOptions } from '../components/FileDiff';\nimport type { UnresolvedFile as UnresolvedFileClass } from '../components/UnresolvedFile';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { UnresolvedFileHunksRendererOptions } from '../renderers/UnresolvedFileHunksRenderer';\nimport type {\n FileContents,\n HunkSeparators,\n MergeConflictResolution,\n PostRenderPhase,\n} from '../types';\nimport { type MergeConflictDiffAction } from '../utils/parseMergeConflictDiffFromFile';\nimport type { FileDiffProps } from './FileDiff';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useUnresolvedFileInstance } from './utils/useUnresolvedFileInstance';\n\nexport interface RenderMergeConflictActionContext {\n resolveConflict(resolution: MergeConflictResolution): void;\n}\n\nexport type RenderMergeConflictActions = (\n action: MergeConflictDiffAction,\n context: RenderMergeConflictActionContext\n) => ReactNode;\n\nexport type MergeConflictActionsTypeOption =\n | 'none'\n | 'default'\n | RenderMergeConflictActions;\n\nexport interface UnresolvedFileReactOptions<LAnnotation>\n extends\n Omit<\n FileDiffOptions<LAnnotation>,\n 'hunkSeparators' | 'diffStyle' | 'onMergeConflictAction' | 'onPostRender'\n >,\n UnresolvedFileHunksRendererOptions {\n hunkSeparators?: HunkSeparators;\n onPostRender?(\n node: HTMLElement,\n instance: UnresolvedFileClass<LAnnotation>,\n phase: PostRenderPhase\n ): unknown;\n maxContextLines?: number;\n}\n\nexport interface UnresolvedFileProps<LAnnotation> extends Omit<\n FileDiffProps<LAnnotation>,\n 'fileDiff' | 'options'\n> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n renderMergeConflictUtility?(\n action: MergeConflictDiffAction,\n getInstance: () => UnresolvedFileClass<LAnnotation> | undefined\n ): ReactNode;\n disableWorkerPool?: boolean;\n}\n\nexport function UnresolvedFile<LAnnotation = undefined>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n renderMergeConflictUtility,\n disableWorkerPool = false,\n}: UnresolvedFileProps<LAnnotation>): React.JSX.Element {\n const { ref, getHoveredLine, fileDiff, actions, getInstance } =\n useUnresolvedFileInstance({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasConflictUtility: renderMergeConflictUtility != null,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n lineAnnotations,\n getHoveredLine,\n actions,\n renderMergeConflictUtility,\n getInstance,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;AA+DA,SAAgB,eAAwC,EACtD,MACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,4BACA,oBAAoB,SACkC;CACtD,MAAM,EAAE,KAAK,gBAAgB,UAAU,SAAS,gBAC9C,0BAA0B;EACxB;EACA;EACA;EACA;EACA;EACA,oBAAoB,8BAA8B;EAClD,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;CACF,CAAC;CAeH,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;YACpD,eAhBY,mBAAmB;GAClC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAG2B,GAAG,eAAe;CAC3B,CAAA;AAEpB"}
|
|
1
|
+
{"version":3,"file":"UnresolvedFile.js","names":[],"sources":["../../src/react/UnresolvedFile.tsx"],"sourcesContent":["'use client';\n\nimport type { ReactNode } from 'react';\n\nimport type { FileDiffOptions } from '../components/FileDiff';\nimport type { UnresolvedFile as UnresolvedFileClass } from '../components/UnresolvedFile';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { UnresolvedFileHunksRendererOptions } from '../renderers/UnresolvedFileHunksRenderer';\nimport type {\n FileContents,\n HunkSeparators,\n MergeConflictResolution,\n PostRenderPhase,\n} from '../types';\nimport { type MergeConflictDiffAction } from '../utils/parseMergeConflictDiffFromFile';\nimport type { FileDiffProps } from './FileDiff';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useUnresolvedFileInstance } from './utils/useUnresolvedFileInstance';\n\nexport interface RenderMergeConflictActionContext {\n resolveConflict(resolution: MergeConflictResolution): void;\n}\n\nexport type RenderMergeConflictActions = (\n action: MergeConflictDiffAction,\n context: RenderMergeConflictActionContext\n) => ReactNode;\n\nexport type MergeConflictActionsTypeOption =\n | 'none'\n | 'default'\n | RenderMergeConflictActions;\n\nexport interface UnresolvedFileReactOptions<LAnnotation>\n extends\n Omit<\n FileDiffOptions<LAnnotation>,\n 'hunkSeparators' | 'diffStyle' | 'onMergeConflictAction' | 'onPostRender'\n >,\n UnresolvedFileHunksRendererOptions {\n hunkSeparators?: HunkSeparators;\n onPostRender?(\n node: HTMLElement,\n instance: UnresolvedFileClass<LAnnotation>,\n phase: PostRenderPhase\n ): unknown;\n maxContextLines?: number;\n}\n\nexport interface UnresolvedFileProps<LAnnotation> extends Omit<\n FileDiffProps<LAnnotation>,\n 'fileDiff' | 'options' | 'edit' | 'editorOptions'\n> {\n file: FileContents;\n options?: UnresolvedFileReactOptions<LAnnotation>;\n renderMergeConflictUtility?(\n action: MergeConflictDiffAction,\n getInstance: () => UnresolvedFileClass<LAnnotation> | undefined\n ): ReactNode;\n disableWorkerPool?: boolean;\n}\n\nexport function UnresolvedFile<LAnnotation = undefined>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n className,\n style,\n prerenderedHTML,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n renderMergeConflictUtility,\n disableWorkerPool = false,\n}: UnresolvedFileProps<LAnnotation>): React.JSX.Element {\n const { ref, getHoveredLine, fileDiff, actions, getInstance } =\n useUnresolvedFileInstance({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n hasConflictUtility: renderMergeConflictUtility != null,\n hasGutterRenderUtility: renderGutterUtility != null,\n hasCustomHeader: renderCustomHeader != null,\n disableWorkerPool,\n });\n const children = renderDiffChildren({\n fileDiff,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n lineAnnotations,\n getHoveredLine,\n actions,\n renderMergeConflictUtility,\n getInstance,\n });\n return (\n <DIFFS_TAG_NAME ref={ref} className={className} style={style}>\n {templateRender(children, prerenderedHTML)}\n </DIFFS_TAG_NAME>\n );\n}\n"],"mappings":";;;;;;;AA+DA,SAAgB,eAAwC,EACtD,MACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,4BACA,oBAAoB,SACkC;CACtD,MAAM,EAAE,KAAK,gBAAgB,UAAU,SAAS,gBAC9C,0BAA0B;EACxB;EACA;EACA;EACA;EACA;EACA,oBAAoB,8BAA8B;EAClD,wBAAwB,uBAAuB;EAC/C,iBAAiB,sBAAsB;EACvC;CACF,CAAC;CAeH,OACE,oBAAC,gBAAD;EAAqB;EAAgB;EAAkB;YACpD,eAhBY,mBAAmB;GAClC;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAG2B,GAAG,eAAe;CAC3B,CAAA;AAEpB"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor,
|
|
1
|
+
import { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, CreatePatchOptionsNonabortable, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, EditableInstance, EditorActiveLineOptions, EditorSelection, EditorState, EditorViewState, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileHeaderRenderMode, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PendingCodeViewLayoutReset, Position, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, Range, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionDirection, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, TextEdit, ThemeRegistration, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, TokenEventBase, VirtualFileMetrics, VirtualWindowSpecs } from "../types.js";
|
|
2
2
|
import { WorkerInitializationRenderOptions, WorkerPoolOptions } from "../worker/types.js";
|
|
3
3
|
import { FileOptions } from "../components/File.js";
|
|
4
|
-
import { CodeView, CodeViewHandle, CodeViewProps, ControlledCodeViewProps, UncontrolledCodeViewProps } from "./CodeView.js";
|
|
4
|
+
import { CodeView, CodeViewHandle, CodeViewProps, CodeViewReactOptions, ControlledCodeViewProps, UncontrolledCodeViewProps } from "./CodeView.js";
|
|
5
5
|
import { DiffBasePropsReact, FileProps } from "./types.js";
|
|
6
6
|
import { File } from "./File.js";
|
|
7
7
|
import { FileDiff, FileDiffProps } from "./FileDiff.js";
|
|
@@ -10,7 +10,7 @@ import { MultiFileDiff, MultiFileDiffProps } from "./MultiFileDiff.js";
|
|
|
10
10
|
import { PatchDiff, PatchDiffProps } from "./PatchDiff.js";
|
|
11
11
|
import { Virtualizer, VirtualizerContext, useVirtualizer } from "./Virtualizer.js";
|
|
12
12
|
import { WorkerPoolContext, WorkerPoolContextProvider, useWorkerPool } from "./WorkerPoolContext.js";
|
|
13
|
-
import {
|
|
13
|
+
import { CreateEditor, EditContext, EditProvider, EditProviderProps, useCreateEditor } from "./EditContext.js";
|
|
14
14
|
import { GutterUtilitySlotStyles, MergeConflictSlotStyles, noopRender } from "./constants.js";
|
|
15
15
|
import { renderDiffChildren } from "./utils/renderDiffChildren.js";
|
|
16
16
|
import { renderFileChildren } from "./utils/renderFileChildren.js";
|
|
@@ -18,4 +18,4 @@ import { templateRender } from "./utils/templateRender.js";
|
|
|
18
18
|
import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
|
|
19
19
|
import { useFileInstance } from "./utils/useFileInstance.js";
|
|
20
20
|
import { useStableCallback } from "./utils/useStableCallback.js";
|
|
21
|
-
export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, type BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, type CodeToHastOptions, CodeView, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewHandle, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewProps, CodeViewRangeScrollTarget, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, ControlledCodeViewProps, type CreatePatchOptionsNonabortable, CustomPreProperties, type DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffBasePropsReact, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor,
|
|
21
|
+
export { AnnotationLineMap, AnnotationSide, AnnotationSpan, AppliedThemeStyleCache, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, type BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, type CodeToHastOptions, CodeView, CodeViewCreateEditorOptions, CodeViewDiffItem, CodeViewFileItem, CodeViewHandle, CodeViewItem, CodeViewItemScrollTarget, CodeViewLayout, CodeViewLineScrollTarget, CodeViewPositionScrollTarget, CodeViewProps, CodeViewRangeScrollTarget, CodeViewReactOptions, CodeViewScrollBehavior, CodeViewScrollTarget, ConflictResolverTypes, ContextContent, ControlledCodeViewProps, CreateEditor, type CreatePatchOptionsNonabortable, CustomPreProperties, type DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffBasePropsReact, DiffFileInput, DiffIndicators, DiffLineAnnotation, DiffLineEventBaseProps, DiffTokenEventBaseProps, DiffsBaseComponent, DiffsComponentOptions, DiffsEditableComponent, DiffsEditor, DiffsHighlighter, DiffsTextDocument, DiffsThemeNames, EditContext, EditProvider, EditProviderProps, EditableInstance, EditorActiveLineOptions, EditorSelection, EditorState, EditorViewState, ExpansionDirections, ExtensionFormatMap, File, FileContents, FileDiff, FileDiffContentsLoader, FileDiffLoadedChangedFiles, FileDiffLoadedFiles, FileDiffLoadedPureRenamedFile, FileDiffMetadata, FileDiffProps, FileHeaderRenderMode, type FileOptions, FileProps, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, GutterUtilitySlotStyles, HighlightedToken, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, type LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MaybeDiffFileInput, MergeConflictActionPayload, MergeConflictActionsTypeOption, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, MergeConflictSlotStyles, MultiFileDiff, MultiFileDiffProps, NumericScrollLineAnchor, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PatchDiff, PatchDiffProps, PendingCodeViewLayoutReset, Position, PostRenderPhase, PrePropertiesConfig, ProcessFileConflictData, Range, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderFilenameSuffixCallback, RenderHeaderMetadataCallback, RenderHeaderPrefixCallback, RenderMergeConflictActionContext, RenderMergeConflictActions, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectedLineRange, SelectionDirection, SelectionPoint, SelectionSide, SharedRenderState, type ShikiTransformer, SmoothScrollSettings, StickySpecs, SupportedLanguages, TextEdit, type ThemeRegistration, type ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, type ThemedToken, ThemesType, TokenEventBase, UncontrolledCodeViewProps, UnresolvedFile, UnresolvedFileProps, UnresolvedFileReactOptions, VirtualFileMetrics, VirtualWindowSpecs, Virtualizer, VirtualizerContext, type WorkerInitializationRenderOptions, WorkerPoolContext, WorkerPoolContextProvider, type WorkerPoolOptions, noopRender, renderDiffChildren, renderFileChildren, templateRender, useCreateEditor, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
|
package/dist/react/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { useStableCallback } from "./utils/useStableCallback.js";
|
|
2
|
+
import { EditContext, EditProvider, useCreateEditor } from "./EditContext.js";
|
|
1
3
|
import { GutterUtilitySlotStyles, MergeConflictSlotStyles, noopRender } from "./constants.js";
|
|
2
4
|
import { renderDiffChildren } from "./utils/renderDiffChildren.js";
|
|
3
5
|
import { renderFileChildren } from "./utils/renderFileChildren.js";
|
|
4
|
-
import { useStableCallback } from "./utils/useStableCallback.js";
|
|
5
6
|
import { WorkerPoolContext, WorkerPoolContextProvider, useWorkerPool } from "./WorkerPoolContext.js";
|
|
6
7
|
import { CodeView } from "./CodeView.js";
|
|
7
|
-
import { EditorContext, EditorProvider, useEditor } from "./EditorContext.js";
|
|
8
8
|
import { templateRender } from "./utils/templateRender.js";
|
|
9
9
|
import { Virtualizer, VirtualizerContext, useVirtualizer } from "./Virtualizer.js";
|
|
10
10
|
import { useFileInstance } from "./utils/useFileInstance.js";
|
|
@@ -14,4 +14,4 @@ import { FileDiff } from "./FileDiff.js";
|
|
|
14
14
|
import { MultiFileDiff } from "./MultiFileDiff.js";
|
|
15
15
|
import { PatchDiff } from "./PatchDiff.js";
|
|
16
16
|
import { UnresolvedFile } from "./UnresolvedFile.js";
|
|
17
|
-
export { CodeView,
|
|
17
|
+
export { CodeView, EditContext, EditProvider, File, FileDiff, GutterUtilitySlotStyles, MergeConflictSlotStyles, MultiFileDiff, PatchDiff, UnresolvedFile, Virtualizer, VirtualizerContext, WorkerPoolContext, WorkerPoolContextProvider, noopRender, renderDiffChildren, renderFileChildren, templateRender, useCreateEditor, useFileDiffInstance, useFileInstance, useStableCallback, useVirtualizer, useWorkerPool };
|
package/dist/react/types.d.ts
CHANGED
|
@@ -2,11 +2,16 @@ import { DiffLineAnnotation, FileContents, FileDiffMetadata, LineAnnotation, Sel
|
|
|
2
2
|
import { GetHoveredLineResult } from "../managers/InteractionManager.js";
|
|
3
3
|
import { FileOptions } from "../components/File.js";
|
|
4
4
|
import { FileDiffOptions } from "../components/FileDiff.js";
|
|
5
|
+
import { EditorOptions } from "../editor/editor.js";
|
|
5
6
|
import { CSSProperties, ReactNode } from "react";
|
|
6
7
|
|
|
7
8
|
//#region src/react/types.d.ts
|
|
8
9
|
interface DiffBasePropsReact<LAnnotation> {
|
|
9
10
|
options?: FileDiffOptions<LAnnotation>;
|
|
11
|
+
/** Whether this surface has an active edit session. */
|
|
12
|
+
edit?: boolean;
|
|
13
|
+
/** Creation-time options passed to the nearest EditProvider factory. */
|
|
14
|
+
editorOptions?: EditorOptions<LAnnotation>;
|
|
10
15
|
metrics?: VirtualFileMetrics;
|
|
11
16
|
lineAnnotations?: DiffLineAnnotation<LAnnotation>[];
|
|
12
17
|
selectedLines?: SelectedLineRange | null;
|
|
@@ -23,6 +28,10 @@ interface DiffBasePropsReact<LAnnotation> {
|
|
|
23
28
|
interface FileProps<LAnnotation> {
|
|
24
29
|
file: FileContents;
|
|
25
30
|
options?: FileOptions<LAnnotation>;
|
|
31
|
+
/** Whether this surface has an active edit session. */
|
|
32
|
+
edit?: boolean;
|
|
33
|
+
/** Creation-time options passed to the nearest EditProvider factory. */
|
|
34
|
+
editorOptions?: EditorOptions<LAnnotation>;
|
|
26
35
|
metrics?: VirtualFileMetrics;
|
|
27
36
|
lineAnnotations?: LineAnnotation<LAnnotation>[];
|
|
28
37
|
selectedLines?: SelectedLineRange | null;
|
|
@@ -36,7 +45,6 @@ interface FileProps<LAnnotation> {
|
|
|
36
45
|
style?: CSSProperties;
|
|
37
46
|
prerenderedHTML?: string;
|
|
38
47
|
disableWorkerPool?: boolean;
|
|
39
|
-
contentEditable?: boolean;
|
|
40
48
|
}
|
|
41
49
|
//#endregion
|
|
42
50
|
export { DiffBasePropsReact, FileProps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/react/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/react/types.ts"],"mappings":";;;;;;;;UAeiB,kBAAA;EACf,OAAA,GAAU,eAAA,CAAgB,WAAA;;EAE1B,IAAA;EAHiC;EAKjC,aAAA,GAAgB,aAAA,CAAc,WAAA;EAC9B,OAAA,GAAU,kBAAA;EACV,eAAA,GAAkB,kBAAA,CAAmB,WAAA;EACrC,aAAA,GAAgB,iBAAA;EAChB,gBAAA,EAAkB,WAAA,EAAa,kBAAA,CAAmB,WAAA,IAAe,SAAA;EACjE,kBAAA,EAAoB,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACjD,kBAAA,EAAoB,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACjD,0BAAA,EAA4B,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACzD,oBAAA,EAAsB,QAAA,EAAU,gBAAA,GAAmB,SAAA;EACnD,mBAAA,EACE,cAAA,QAAsB,oBAAA,uBACrB,SAAA;EACH,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,eAAA;AAAA;AAAA,UAGe,SAAA;EACf,IAAA,EAAM,YAAA;EACN,OAAA,GAAU,WAAA,CAAY,WAAA;EAZmC;EAczD,IAAA;EAbmD;EAenD,aAAA,GAAgB,aAAA,CAAc,WAAA;EAC9B,OAAA,GAAU,kBAAA;EACV,eAAA,GAAkB,cAAA,CAAe,WAAA;EACjC,aAAA,GAAgB,iBAAA;EAChB,gBAAA,EAAkB,WAAA,EAAa,cAAA,CAAe,WAAA,IAAe,SAAA;EAC7D,kBAAA,EAAoB,IAAA,EAAM,YAAA,GAAe,SAAA;EACzC,kBAAA,EAAoB,IAAA,EAAM,YAAA,GAAe,SAAA;EACzC,0BAAA,EAA4B,IAAA,EAAM,YAAA,GAAe,SAAA;EACjD,oBAAA,EAAsB,IAAA,EAAM,YAAA,GAAe,SAAA;EAC3C,mBAAA,EACE,cAAA,QAAsB,oBAAA,uBACrB,SAAA;EACH,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,eAAA;EACA,iBAAA;AAAA"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { DiffLineAnnotation, FileDiffMetadata, SelectedLineRange, VirtualFileMetrics } from "../../types.js";
|
|
2
2
|
import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
|
|
3
3
|
import { FileDiffOptions } from "../../components/FileDiff.js";
|
|
4
|
-
|
|
4
|
+
import { EditorOptions } from "../../editor/editor.js";
|
|
5
5
|
//#region src/react/utils/useFileDiffInstance.d.ts
|
|
6
6
|
interface UseFileDiffInstanceProps<LAnnotation> {
|
|
7
7
|
fileDiff: FileDiffMetadata;
|
|
8
8
|
options: FileDiffOptions<LAnnotation> | undefined;
|
|
9
|
+
editorOptions: EditorOptions<LAnnotation> | undefined;
|
|
9
10
|
lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;
|
|
10
11
|
selectedLines: SelectedLineRange | null | undefined;
|
|
11
12
|
prerenderedHTML: string | undefined;
|
|
@@ -13,7 +14,7 @@ interface UseFileDiffInstanceProps<LAnnotation> {
|
|
|
13
14
|
hasGutterRenderUtility: boolean;
|
|
14
15
|
hasCustomHeader: boolean;
|
|
15
16
|
disableWorkerPool: boolean;
|
|
16
|
-
|
|
17
|
+
edit: boolean;
|
|
17
18
|
}
|
|
18
19
|
interface UseFileDiffInstanceReturn {
|
|
19
20
|
ref(node: HTMLElement | null): void;
|
|
@@ -22,6 +23,7 @@ interface UseFileDiffInstanceReturn {
|
|
|
22
23
|
declare function useFileDiffInstance<LAnnotation>({
|
|
23
24
|
fileDiff,
|
|
24
25
|
options,
|
|
26
|
+
editorOptions,
|
|
25
27
|
lineAnnotations,
|
|
26
28
|
selectedLines,
|
|
27
29
|
prerenderedHTML,
|
|
@@ -29,7 +31,7 @@ declare function useFileDiffInstance<LAnnotation>({
|
|
|
29
31
|
hasGutterRenderUtility,
|
|
30
32
|
hasCustomHeader,
|
|
31
33
|
disableWorkerPool,
|
|
32
|
-
|
|
34
|
+
edit
|
|
33
35
|
}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn;
|
|
34
36
|
//#endregion
|
|
35
37
|
export { useFileDiffInstance };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileDiffInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useFileDiffInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"mappings":";;;;;UA4BU,wBAAA;EACR,QAAA,EAAU,gBAAA;EACV,OAAA,EAAS,eAAA,CAAgB,WAAA;EACzB,aAAA,EAAe,aAAA,CAAc,WAAA;EAC7B,eAAA,EAAiB,kBAAA,CAAmB,WAAA;EACpC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,IAAA;AAAA;AAAA,UAGQ,yBAAA;EACR,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAoB;AAAA;AAAA,iBAGxB,mBAAA;EACd,QAAA;EACA,OAAA;EACA,aAAA;EACA,eAAA;EACA,aAAA;EACA,eAAA;EACA,OAAA;EACA,sBAAA;EACA,eAAA;EACA,iBAAA;EACA;AAAA,GACC,wBAAA,CAAyB,WAAA,IAAe,yBAAA"}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import { areOptionsEqual } from "../../utils/areOptionsEqual.js";
|
|
2
2
|
import { FileDiff } from "../../components/FileDiff.js";
|
|
3
3
|
import { VirtualizedFileDiff } from "../../components/VirtualizedFileDiff.js";
|
|
4
|
-
import { noopRender } from "../constants.js";
|
|
5
4
|
import { useStableCallback } from "./useStableCallback.js";
|
|
5
|
+
import { useCreateEditor } from "../EditContext.js";
|
|
6
|
+
import { noopRender } from "../constants.js";
|
|
6
7
|
import { WorkerPoolContext } from "../WorkerPoolContext.js";
|
|
7
|
-
import { useEditor } from "../EditorContext.js";
|
|
8
8
|
import { useVirtualizer } from "../Virtualizer.js";
|
|
9
9
|
import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
|
|
10
10
|
//#region src/react/utils/useFileDiffInstance.ts
|
|
11
|
-
const
|
|
12
|
-
function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool,
|
|
11
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
12
|
+
function useFileDiffInstance({ fileDiff, options, editorOptions, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, edit }) {
|
|
13
13
|
const simpleVirtualizer = useVirtualizer();
|
|
14
14
|
const controlledSelection = selectedLines !== void 0;
|
|
15
15
|
const poolManager = useContext(WorkerPoolContext);
|
|
16
|
-
const
|
|
16
|
+
const createEditor = useCreateEditor();
|
|
17
17
|
const instanceRef = useRef(null);
|
|
18
18
|
const ref = useStableCallback((fileContainer) => {
|
|
19
19
|
if (fileContainer != null) {
|
|
20
20
|
if (instanceRef.current != null) throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");
|
|
21
21
|
if (simpleVirtualizer != null) instanceRef.current = new VirtualizedFileDiff(mergeFileDiffOptions({
|
|
22
22
|
controlledSelection,
|
|
23
|
-
|
|
23
|
+
edit,
|
|
24
24
|
hasCustomHeader,
|
|
25
|
-
hasEditor:
|
|
25
|
+
hasEditor: createEditor !== void 0,
|
|
26
26
|
hasGutterRenderUtility,
|
|
27
27
|
options
|
|
28
28
|
}), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
|
|
29
29
|
else instanceRef.current = new FileDiff(mergeFileDiffOptions({
|
|
30
30
|
controlledSelection,
|
|
31
|
-
|
|
31
|
+
edit,
|
|
32
32
|
hasCustomHeader,
|
|
33
|
-
hasEditor:
|
|
33
|
+
hasEditor: createEditor !== void 0,
|
|
34
34
|
hasGutterRenderUtility,
|
|
35
35
|
options
|
|
36
36
|
}), !disableWorkerPool ? poolManager : void 0, true);
|
|
@@ -46,14 +46,14 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
|
|
|
46
46
|
instanceRef.current = null;
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
|
|
49
|
+
useIsomorphicLayoutEffect(() => {
|
|
50
50
|
const { current: instance } = instanceRef;
|
|
51
51
|
if (instance == null) return;
|
|
52
52
|
const newOptions = mergeFileDiffOptions({
|
|
53
53
|
controlledSelection,
|
|
54
|
-
|
|
54
|
+
edit,
|
|
55
55
|
hasCustomHeader,
|
|
56
|
-
hasEditor:
|
|
56
|
+
hasEditor: createEditor !== void 0,
|
|
57
57
|
hasGutterRenderUtility,
|
|
58
58
|
options
|
|
59
59
|
});
|
|
@@ -66,12 +66,19 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
|
|
|
66
66
|
});
|
|
67
67
|
if (selectedLines !== void 0) instance.setSelectedLines(selectedLines);
|
|
68
68
|
});
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
if (
|
|
72
|
-
|
|
69
|
+
useIsomorphicLayoutEffect(() => {
|
|
70
|
+
if (edit && instanceRef.current != null) {
|
|
71
|
+
if (createEditor === void 0) throw new Error("FileDiff: EditContext is not attached");
|
|
72
|
+
const editor = createEditor(editorOptions ?? {});
|
|
73
|
+
if (editor == null) throw new Error("FileDiff: EditProvider.createEditor must return an editor instance");
|
|
74
|
+
try {
|
|
75
|
+
return editor.edit(instanceRef.current);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
editor.cleanUp();
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
|
-
}, [
|
|
81
|
+
}, [edit]);
|
|
75
82
|
return {
|
|
76
83
|
ref,
|
|
77
84
|
getHoveredLine: useCallback(() => {
|
|
@@ -79,10 +86,10 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
|
|
|
79
86
|
}, [])
|
|
80
87
|
};
|
|
81
88
|
}
|
|
82
|
-
function mergeFileDiffOptions({ options, controlledSelection,
|
|
83
|
-
const
|
|
89
|
+
function mergeFileDiffOptions({ options, controlledSelection, edit, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
|
|
90
|
+
const needsEditorOverrides = edit && hasEditor;
|
|
84
91
|
const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
|
|
85
|
-
if (!needsReactOverrides && !
|
|
92
|
+
if (!needsReactOverrides && !needsEditorOverrides) return options;
|
|
86
93
|
return {
|
|
87
94
|
...options,
|
|
88
95
|
...needsReactOverrides ? {
|
|
@@ -90,13 +97,7 @@ function mergeFileDiffOptions({ options, controlledSelection, contentEditable, h
|
|
|
90
97
|
renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
|
|
91
98
|
renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
|
|
92
99
|
} : null,
|
|
93
|
-
...
|
|
94
|
-
useTokenTransformer: true,
|
|
95
|
-
enableGutterUtility: false,
|
|
96
|
-
enableLineSelection: false,
|
|
97
|
-
expandUnchanged: true,
|
|
98
|
-
lineHoverHighlight: "disabled"
|
|
99
|
-
} : null
|
|
100
|
+
...needsEditorOverrides ? { useTokenTransformer: true } : null
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
103
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { FileDiff, type FileDiffOptions } from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport {
|
|
1
|
+
{"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { FileDiff, type FileDiffOptions } from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { EditorOptions } from '../../edit';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useCreateEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n editorOptions: EditorOptions<LAnnotation> | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n edit: boolean;\n}\n\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\n\nexport function useFileDiffInstance<LAnnotation>({\n fileDiff,\n options,\n editorOptions,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n edit,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const createEditor = useCreateEditor<LAnnotation>();\n const instanceRef = useRef<\n FileDiff<LAnnotation> | VirtualizedFileDiff<LAnnotation> | null\n >(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor: createEditor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor: createEditor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n fileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor: createEditor !== undefined,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n forceRender,\n fileDiff,\n lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n useIsomorphicLayoutEffect(() => {\n if (edit && instanceRef.current != null) {\n if (createEditor === undefined) {\n throw new Error('FileDiff: EditContext is not attached');\n }\n const editor = createEditor(editorOptions ?? {});\n if (editor == null) {\n throw new Error(\n 'FileDiff: EditProvider.createEditor must return an editor instance'\n );\n }\n try {\n return editor.edit(instanceRef.current);\n } catch (error) {\n editor.cleanUp();\n throw error;\n }\n }\n return undefined;\n }, [edit]);\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return {\n ref,\n getHoveredLine,\n };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation> {\n controlledSelection: boolean;\n edit: boolean;\n hasEditor: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n options: FileDiffOptions<LAnnotation> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation>({\n options,\n controlledSelection,\n edit,\n hasCustomHeader,\n hasEditor,\n hasGutterRenderUtility,\n}: MergeFileDiffOptionsProps<LAnnotation>):\n | FileDiffOptions<LAnnotation>\n | undefined {\n const needsEditorOverrides = edit && hasEditor;\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides && !needsEditorOverrides) {\n return options;\n }\n\n return {\n ...options,\n ...(needsReactOverrides\n ? {\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n }\n : null),\n ...(needsEditorOverrides ? { useTokenTransformer: true } : null),\n };\n}\n"],"mappings":";;;;;;;;;;AAyBA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AAqB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,eACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,QACmE;CACnE,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,eAAe,gBAA6B;CAClD,MAAM,cAAc,OAElB,IAAI;CACN,MAAM,MAAM,mBAAmB,kBAAsC;EACnE,IAAI,iBAAiB,MAAM;GACzB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,kFACF;GAEF,IAAI,qBAAqB,MACvB,YAAY,UAAU,IAAI,oBACxB,qBAAqB;IACnB;IACA;IACA;IACA,WAAW,iBAAiB,KAAA;IAC5B;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,SACxB,qBAAqB;IACnB;IACA;IACA;IACA,WAAW,iBAAiB,KAAA;IAC5B;IACA;GACF,CAAC,GACD,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;GAEF,YAAiB,QAAQ,QAAQ;IAC/B;IACA;IACA;IACA;GACF,CAAC;EACH,OAAO;GACL,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,uEACF;GAEF,YAAY,QAAQ,QAAQ;GAC5B,YAAY,UAAU;EACxB;CACF,CAAC;CAED,gCAAgC;EAC9B,MAAM,EAAE,SAAS,aAAa;EAC9B,IAAI,YAAY,MAAM;EACtB,MAAM,aAAa,qBAAqB;GACtC;GACA;GACA;GACA,WAAW,iBAAiB,KAAA;GAC5B;GACA;EACF,CAAC;EACD,MAAM,cAAc,CAAC,gBAAgB,SAAS,SAAS,UAAU;EACjE,SAAS,WAAW,UAAU;EAC9B,SAAc,OAAO;GACnB;GACA;GACA;EACF,CAAC;EACD,IAAI,kBAAkB,KAAA,GACpB,SAAS,iBAAiB,aAAa;CAE3C,CAAC;CAED,gCAAgC;EAC9B,IAAI,QAAQ,YAAY,WAAW,MAAM;GACvC,IAAI,iBAAiB,KAAA,GACnB,MAAM,IAAI,MAAM,uCAAuC;GAEzD,MAAM,SAAS,aAAa,iBAAiB,CAAC,CAAC;GAC/C,IAAI,UAAU,MACZ,MAAM,IAAI,MACR,oEACF;GAEF,IAAI;IACF,OAAO,OAAO,KAAK,YAAY,OAAO;GACxC,SAAS,OAAO;IACd,OAAO,QAAQ;IACf,MAAM;GACR;EACF;CAEF,GAAG,CAAC,IAAI,CAAC;CAQT,OAAO;EACL;EACA,gBARqB,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CAIW;CACf;AACF;AAWA,SAAS,qBAAkC,EACzC,SACA,qBACA,MACA,iBACA,WACA,0BAGY;CACZ,MAAM,uBAAuB,QAAQ;CACrC,MAAM,sBACJ,uBAAuB,0BAA0B;CAEnD,IAAI,CAAC,uBAAuB,CAAC,sBAC3B,OAAO;CAGT,OAAO;EACL,GAAG;EACH,GAAI,sBACA;GACE;GACA,oBAAoB,kBAChB,aACA,SAAS;GACb,qBAAqB,yBACjB,aACA,SAAS;EACf,IACA;EACJ,GAAI,uBAAuB,EAAE,qBAAqB,KAAK,IAAI;CAC7D;AACF"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { FileContents, LineAnnotation, SelectedLineRange, VirtualFileMetrics } from "../../types.js";
|
|
2
2
|
import { GetHoveredLineResult } from "../../managers/InteractionManager.js";
|
|
3
3
|
import { FileOptions } from "../../components/File.js";
|
|
4
|
-
|
|
4
|
+
import { EditorOptions } from "../../editor/editor.js";
|
|
5
5
|
//#region src/react/utils/useFileInstance.d.ts
|
|
6
6
|
interface UseFileInstanceProps<LAnnotation> {
|
|
7
7
|
file: FileContents;
|
|
8
8
|
options: FileOptions<LAnnotation> | undefined;
|
|
9
|
+
editorOptions: EditorOptions<LAnnotation> | undefined;
|
|
9
10
|
lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;
|
|
10
11
|
selectedLines: SelectedLineRange | null | undefined;
|
|
11
12
|
prerenderedHTML: string | undefined;
|
|
@@ -13,7 +14,7 @@ interface UseFileInstanceProps<LAnnotation> {
|
|
|
13
14
|
hasGutterRenderUtility: boolean;
|
|
14
15
|
hasCustomHeader: boolean;
|
|
15
16
|
disableWorkerPool: boolean;
|
|
16
|
-
|
|
17
|
+
edit: boolean;
|
|
17
18
|
onChange?: (file: FileContents, lineAnnotations?: LineAnnotation<LAnnotation>[]) => void;
|
|
18
19
|
}
|
|
19
20
|
interface UseFileInstanceReturn {
|
|
@@ -23,6 +24,7 @@ interface UseFileInstanceReturn {
|
|
|
23
24
|
declare function useFileInstance<LAnnotation>({
|
|
24
25
|
file,
|
|
25
26
|
options,
|
|
27
|
+
editorOptions,
|
|
26
28
|
lineAnnotations,
|
|
27
29
|
selectedLines,
|
|
28
30
|
prerenderedHTML,
|
|
@@ -30,7 +32,7 @@ declare function useFileInstance<LAnnotation>({
|
|
|
30
32
|
hasGutterRenderUtility,
|
|
31
33
|
hasCustomHeader,
|
|
32
34
|
disableWorkerPool,
|
|
33
|
-
|
|
35
|
+
edit
|
|
34
36
|
}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn;
|
|
35
37
|
//#endregion
|
|
36
38
|
export { useFileInstance };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;UA4BU,oBAAA;EACR,IAAA,EAAM,YAAA;EACN,OAAA,EAAS,WAAA,CAAY,WAAA;EACrB,aAAA,EAAe,aAAA,CAAc,WAAA;EAC7B,eAAA,EAAiB,cAAA,CAAe,WAAA;EAChC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,IAAA;EACA,QAAA,IACE,IAAA,EAAM,YAAA,EACN,eAAA,GAAkB,cAAA,CAAe,WAAA;AAAA;AAAA,UAI3B,qBAAA;EACR,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAoB;AAAA;AAAA,iBAGxB,eAAA;EACd,IAAA;EACA,OAAA;EACA,aAAA;EACA,eAAA;EACA,aAAA;EACA,eAAA;EACA,OAAA;EACA,sBAAA;EACA,eAAA;EACA,iBAAA;EACA;AAAA,GACC,oBAAA,CAAqB,WAAA,IAAe,qBAAA"}
|