@pierre/diffs 1.2.12 → 1.3.0-beta.10
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 +91 -6
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +300 -38
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +14 -3
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +98 -12
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +68 -19
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +363 -25
- 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/UnresolvedFile.d.ts +2 -2
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +2 -2
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +4 -2
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +59 -47
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +27 -5
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +262 -56
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/Virtualizer.d.ts +4 -1
- package/dist/components/Virtualizer.d.ts.map +1 -1
- package/dist/components/Virtualizer.js +21 -4
- package/dist/components/Virtualizer.js.map +1 -1
- package/dist/constants.d.ts +4 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -1
- package/dist/constants.js.map +1 -1
- package/dist/editor/command.d.ts +7 -0
- package/dist/editor/command.d.ts.map +1 -0
- package/dist/editor/command.js +54 -0
- package/dist/editor/command.js.map +1 -0
- package/dist/editor/editStack.d.ts +71 -0
- package/dist/editor/editStack.d.ts.map +1 -0
- package/dist/editor/editStack.js +218 -0
- package/dist/editor/editStack.js.map +1 -0
- package/dist/editor/editor.d.ts +105 -0
- package/dist/editor/editor.d.ts.map +1 -0
- package/dist/editor/editor.js +2545 -0
- package/dist/editor/editor.js.map +1 -0
- package/dist/editor/editor2.js +6 -0
- package/dist/editor/editor2.js.map +1 -0
- package/dist/editor/index.d.ts +5 -0
- package/dist/editor/index.js +3 -0
- 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 +9 -0
- package/dist/editor/lineAnnotations.d.ts.map +1 -0
- package/dist/editor/lineAnnotations.js +212 -0
- package/dist/editor/lineAnnotations.js.map +1 -0
- package/dist/editor/marker.d.ts +38 -0
- package/dist/editor/marker.d.ts.map +1 -0
- package/dist/editor/marker.js +245 -0
- package/dist/editor/marker.js.map +1 -0
- package/dist/editor/matchBrackets.d.ts +9 -0
- package/dist/editor/matchBrackets.d.ts.map +1 -0
- package/dist/editor/matchBrackets.js +138 -0
- package/dist/editor/matchBrackets.js.map +1 -0
- package/dist/editor/pieceTable.d.ts +41 -0
- package/dist/editor/pieceTable.d.ts.map +1 -0
- package/dist/editor/pieceTable.js +671 -0
- package/dist/editor/pieceTable.js.map +1 -0
- package/dist/editor/platform.d.ts +19 -0
- package/dist/editor/platform.d.ts.map +1 -0
- package/dist/editor/platform.js +57 -0
- package/dist/editor/platform.js.map +1 -0
- package/dist/editor/popover.d.ts +65 -0
- package/dist/editor/popover.d.ts.map +1 -0
- package/dist/editor/popover.js +187 -0
- package/dist/editor/popover.js.map +1 -0
- package/dist/editor/searchPanel.d.ts +40 -0
- package/dist/editor/searchPanel.d.ts.map +1 -0
- package/dist/editor/searchPanel.js +318 -0
- package/dist/editor/searchPanel.js.map +1 -0
- package/dist/editor/selection.d.ts +211 -0
- package/dist/editor/selection.d.ts.map +1 -0
- package/dist/editor/selection.js +1626 -0
- package/dist/editor/selection.js.map +1 -0
- package/dist/editor/selectionAction.d.ts +46 -0
- package/dist/editor/selectionAction.d.ts.map +1 -0
- package/dist/editor/selectionAction.js +64 -0
- package/dist/editor/selectionAction.js.map +1 -0
- package/dist/editor/sprite.d.ts +8 -0
- package/dist/editor/sprite.d.ts.map +1 -0
- package/dist/editor/sprite.js +45 -0
- package/dist/editor/sprite.js.map +1 -0
- 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 +77 -0
- package/dist/editor/textDocument.d.ts.map +1 -0
- package/dist/editor/textDocument.js +271 -0
- package/dist/editor/textDocument.js.map +1 -0
- package/dist/editor/textMeasure.d.ts +61 -0
- package/dist/editor/textMeasure.d.ts.map +1 -0
- package/dist/editor/textMeasure.js +209 -0
- package/dist/editor/textMeasure.js.map +1 -0
- package/dist/editor/tokenizer.d.ts +41 -0
- package/dist/editor/tokenizer.d.ts.map +1 -0
- package/dist/editor/tokenizer.js +513 -0
- package/dist/editor/tokenizer.js.map +1 -0
- package/dist/editor/utils.d.ts +21 -0
- package/dist/editor/utils.d.ts.map +1 -0
- package/dist/editor/utils.js +68 -0
- package/dist/editor/utils.js.map +1 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.js +12 -10
- package/dist/managers/InteractionManager.d.ts +7 -0
- package/dist/managers/InteractionManager.d.ts.map +1 -1
- package/dist/managers/InteractionManager.js +22 -1
- package/dist/managers/InteractionManager.js.map +1 -1
- package/dist/managers/ResizeManager.d.ts +10 -2
- package/dist/managers/ResizeManager.d.ts.map +1 -1
- package/dist/managers/ResizeManager.js +33 -13
- package/dist/managers/ResizeManager.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 +6 -1
- package/dist/managers/UniversalRenderingManager.js.map +1 -1
- package/dist/react/CodeView.d.ts +26 -1
- package/dist/react/CodeView.d.ts.map +1 -1
- package/dist/react/CodeView.js +82 -19
- package/dist/react/CodeView.js.map +1 -1
- package/dist/react/EditContext.d.ts +15 -0
- package/dist/react/EditContext.d.ts.map +1 -0
- package/dist/react/EditContext.js +23 -0
- package/dist/react/EditContext.js.map +1 -0
- package/dist/react/File.d.ts +3 -1
- package/dist/react/File.d.ts.map +1 -1
- package/dist/react/File.js +4 -2
- package/dist/react/File.js.map +1 -1
- package/dist/react/FileDiff.d.ts +4 -1
- package/dist/react/FileDiff.d.ts.map +1 -1
- package/dist/react/FileDiff.js +4 -2
- package/dist/react/FileDiff.js.map +1 -1
- package/dist/react/MultiFileDiff.d.ts +7 -5
- package/dist/react/MultiFileDiff.d.ts.map +1 -1
- package/dist/react/MultiFileDiff.js +4 -2
- package/dist/react/MultiFileDiff.js.map +1 -1
- package/dist/react/PatchDiff.d.ts +4 -1
- package/dist/react/PatchDiff.d.ts.map +1 -1
- package/dist/react/PatchDiff.js +4 -2
- package/dist/react/PatchDiff.js.map +1 -1
- package/dist/react/UnresolvedFile.d.ts +1 -0
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js +2 -1
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +3 -2
- package/dist/react/index.js +2 -1
- package/dist/react/types.d.ts +3 -0
- package/dist/react/types.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts +2 -0
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +16 -8
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/renderFileChildren.d.ts +2 -0
- package/dist/react/utils/renderFileChildren.d.ts.map +1 -1
- package/dist/react/utils/renderFileChildren.js +16 -8
- package/dist/react/utils/renderFileChildren.js.map +1 -1
- package/dist/react/utils/useFileDiffInstance.d.ts +3 -1
- package/dist/react/utils/useFileDiffInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +30 -6
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/react/utils/useFileInstance.d.ts +4 -1
- package/dist/react/utils/useFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useFileInstance.js +30 -5
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +28 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +244 -22
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +8 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +155 -45
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +11 -10
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +15 -7
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/types.d.ts +282 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/applyLineTextWithNewline.d.ts +5 -0
- package/dist/utils/applyLineTextWithNewline.d.ts.map +1 -0
- package/dist/utils/applyLineTextWithNewline.js +11 -0
- package/dist/utils/applyLineTextWithNewline.js.map +1 -0
- package/dist/utils/areHunkDataEqual.js +1 -1
- package/dist/utils/areHunkDataEqual.js.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.d.ts +2 -2
- package/dist/utils/areManagedSnapshotsEqual.d.ts.map +1 -1
- package/dist/utils/areManagedSnapshotsEqual.js +5 -0
- package/dist/utils/areManagedSnapshotsEqual.js.map +1 -1
- package/dist/utils/awaitWithTimeout.d.ts +5 -0
- package/dist/utils/awaitWithTimeout.d.ts.map +1 -0
- package/dist/utils/awaitWithTimeout.js +15 -0
- package/dist/utils/awaitWithTimeout.js.map +1 -0
- package/dist/utils/cleanLastNewline.js +6 -1
- package/dist/utils/cleanLastNewline.js.map +1 -1
- package/dist/utils/cloneFileDiffMetadata.d.ts +7 -0
- package/dist/utils/cloneFileDiffMetadata.d.ts.map +1 -0
- package/dist/utils/cloneFileDiffMetadata.js +16 -0
- package/dist/utils/cloneFileDiffMetadata.js.map +1 -0
- package/dist/utils/computeEstimatedDiffHeights.d.ts +3 -1
- package/dist/utils/computeEstimatedDiffHeights.d.ts.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.js +8 -1
- package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
- package/dist/utils/computeFileOffsets.d.ts +21 -0
- package/dist/utils/computeFileOffsets.d.ts.map +1 -0
- package/dist/utils/computeFileOffsets.js +51 -0
- package/dist/utils/computeFileOffsets.js.map +1 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts +5 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.d.ts.map +1 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.js +19 -0
- package/dist/utils/createCodeViewHeaderFooterHostElement.js.map +1 -0
- package/dist/utils/createFileHeaderElement.d.ts.map +1 -1
- package/dist/utils/createFileHeaderElement.js +5 -1
- package/dist/utils/createFileHeaderElement.js.map +1 -1
- package/dist/utils/createTransformerWithState.js +9 -0
- package/dist/utils/createTransformerWithState.js.map +1 -1
- package/dist/utils/editSessionHunks.d.ts +84 -0
- package/dist/utils/editSessionHunks.d.ts.map +1 -0
- package/dist/utils/editSessionHunks.js +366 -0
- package/dist/utils/editSessionHunks.js.map +1 -0
- package/dist/utils/getDiffFileInput.d.ts +14 -0
- package/dist/utils/getDiffFileInput.d.ts.map +1 -0
- package/dist/utils/getDiffFileInput.js +24 -0
- package/dist/utils/getDiffFileInput.js.map +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFiletypeFromFileName.d.ts.map +1 -1
- package/dist/utils/getFiletypeFromFileName.js +2 -0
- package/dist/utils/getFiletypeFromFileName.js.map +1 -1
- package/dist/utils/hydratePartialDiff.d.ts +10 -0
- package/dist/utils/hydratePartialDiff.d.ts.map +1 -0
- package/dist/utils/hydratePartialDiff.js +140 -0
- package/dist/utils/hydratePartialDiff.js.map +1 -0
- package/dist/utils/iterateOverDiff.js +3 -3
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/parseDiffFromFile.d.ts +1 -1
- package/dist/utils/parseDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseDiffFromFile.js +26 -5
- package/dist/utils/parseDiffFromFile.js.map +1 -1
- package/dist/utils/parsePatchFiles.d.ts.map +1 -1
- package/dist/utils/parsePatchFiles.js +2 -0
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/realignChangeContent.d.ts +28 -0
- package/dist/utils/realignChangeContent.d.ts.map +1 -0
- package/dist/utils/realignChangeContent.js +142 -0
- package/dist/utils/realignChangeContent.js.map +1 -0
- package/dist/utils/renderDiffWithHighlighter.js +1 -1
- package/dist/utils/renderFileWithHighlighter.d.ts.map +1 -1
- package/dist/utils/renderFileWithHighlighter.js +5 -14
- package/dist/utils/renderFileWithHighlighter.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +24 -0
- package/dist/utils/updateDiffHunks.d.ts.map +1 -0
- package/dist/utils/updateDiffHunks.js +235 -0
- package/dist/utils/updateDiffHunks.js.map +1 -0
- package/dist/utils/virtualDiffLayout.d.ts +40 -1
- package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
- package/dist/utils/virtualDiffLayout.js +96 -1
- package/dist/utils/virtualDiffLayout.js.map +1 -1
- package/dist/worker/WorkerPoolManager.d.ts +7 -2
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +83 -18
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/index.d.ts +2 -2
- package/dist/worker/types.d.ts +11 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +46 -66
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +46 -66
- package/dist/worker/worker.js.map +1 -1
- package/package.json +12 -5
- package/dist/utils/iterateOverFile.d.ts +0 -50
- package/dist/utils/iterateOverFile.d.ts.map +0 -1
- package/dist/utils/iterateOverFile.js +0 -49
- package/dist/utils/iterateOverFile.js.map +0 -1
|
@@ -3,21 +3,29 @@ import { getLineAnnotationName } from "../../utils/getLineAnnotationName.js";
|
|
|
3
3
|
import { GutterUtilitySlotStyles } from "../constants.js";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
//#region src/react/utils/renderFileChildren.tsx
|
|
6
|
-
function renderFileChildren({ file, renderCustomHeader, renderHeaderPrefix, renderHeaderMetadata, renderAnnotation, lineAnnotations, renderGutterUtility, getHoveredLine }) {
|
|
6
|
+
function renderFileChildren({ file, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderAnnotation, lineAnnotations, renderGutterUtility, getHoveredLine }) {
|
|
7
7
|
const customHeader = renderCustomHeader?.(file);
|
|
8
8
|
const prefix = renderHeaderPrefix?.(file);
|
|
9
|
+
const suffix = renderHeaderFilenameSuffix?.(file);
|
|
9
10
|
const metadata = renderHeaderMetadata?.(file);
|
|
10
11
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
11
12
|
customHeader != null ? /* @__PURE__ */ jsx("div", {
|
|
12
13
|
slot: CUSTOM_HEADER_SLOT_ID,
|
|
13
14
|
children: customHeader
|
|
14
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
16
|
+
prefix != null && /* @__PURE__ */ jsx("div", {
|
|
17
|
+
slot: "header-prefix",
|
|
18
|
+
children: prefix
|
|
19
|
+
}),
|
|
20
|
+
suffix != null && /* @__PURE__ */ jsx("div", {
|
|
21
|
+
slot: "header-filename-suffix",
|
|
22
|
+
children: suffix
|
|
23
|
+
}),
|
|
24
|
+
metadata != null && /* @__PURE__ */ jsx("div", {
|
|
25
|
+
slot: "header-metadata",
|
|
26
|
+
children: metadata
|
|
27
|
+
})
|
|
28
|
+
] }),
|
|
21
29
|
renderAnnotation != null && lineAnnotations?.map((annotation, index) => /* @__PURE__ */ jsx("div", {
|
|
22
30
|
slot: getLineAnnotationName(annotation),
|
|
23
31
|
children: renderAnnotation(annotation)
|
|
@@ -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_METADATA_SLOT_ID,\n HEADER_PREFIX_SLOT_ID,\n} from '../../constants';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type { FileContents } from '../../types';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { GutterUtilitySlotStyles } from '../constants';\nimport type { FileProps } from '../types';\n\ninterface RenderFileChildrenProps<LAnnotation> {\n file: FileContents;\n renderCustomHeader: FileProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: FileProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderMetadata: FileProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: FileProps<LAnnotation>['renderAnnotation'];\n lineAnnotations: FileProps<LAnnotation>['lineAnnotations'];\n renderGutterUtility: FileProps<LAnnotation>['renderGutterUtility'];\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function renderFileChildren<LAnnotation>({\n file,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n}: RenderFileChildrenProps<LAnnotation>): ReactNode {\n const customHeader = renderCustomHeader?.(file);\n const prefix = renderHeaderPrefix?.(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 {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={getLineAnnotationName(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":";;;;;
|
|
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 } from '../../types';\nimport { getLineAnnotationName } from '../../utils/getLineAnnotationName';\nimport { GutterUtilitySlotStyles } from '../constants';\nimport type { FileProps } from '../types';\n\ninterface RenderFileChildrenProps<LAnnotation> {\n file: FileContents;\n renderCustomHeader: FileProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: FileProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix?: FileProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: FileProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: FileProps<LAnnotation>['renderAnnotation'];\n lineAnnotations: FileProps<LAnnotation>['lineAnnotations'];\n renderGutterUtility: FileProps<LAnnotation>['renderGutterUtility'];\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function renderFileChildren<LAnnotation>({\n file,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n lineAnnotations,\n renderGutterUtility,\n getHoveredLine,\n}: RenderFileChildrenProps<LAnnotation>): 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={getLineAnnotationName(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":";;;;;AA0BA,SAAgB,mBAAgC,EAC9C,MACA,oBACA,oBACA,4BACA,sBACA,kBACA,iBACA,qBACA,kBACkD;CAClD,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;aAAwB;EAAkB,CAAA,IAErD,qBAAA,UAAA,EAAA,UAAA;GACG,UAAU,QAAQ,oBAAC,OAAD;IAAK,MAAA;cAA8B;GAAY,CAAA;GACjE,UAAU,QACT,oBAAC,OAAD;IAAK,MAAA;cAAuC;GAAY,CAAA;GAEzD,YAAY,QACX,oBAAC,OAAD;IAAK,MAAA;cAAgC;GAAc,CAAA;EAErD,EAAA,CAAA;EAEH,oBAAoB,QACnB,iBAAiB,KAAK,YAAY,UAChC,oBAAC,OAAD;GAAiB,MAAM,sBAAsB,UAAU;aACpD,iBAAiB,UAAU;EACzB,GAFK,KAEL,CACN;EACF,uBAAuB,QACtB,oBAAC,OAAD;GAAK,MAAK;GAAsB,OAAO;aACpC,oBAAoB,cAAc;EAChC,CAAA;CAEP,EAAA,CAAA;AAEN"}
|
|
@@ -13,6 +13,7 @@ interface UseFileDiffInstanceProps<LAnnotation> {
|
|
|
13
13
|
hasGutterRenderUtility: boolean;
|
|
14
14
|
hasCustomHeader: boolean;
|
|
15
15
|
disableWorkerPool: boolean;
|
|
16
|
+
contentEditable: boolean;
|
|
16
17
|
}
|
|
17
18
|
interface UseFileDiffInstanceReturn {
|
|
18
19
|
ref(node: HTMLElement | null): void;
|
|
@@ -27,7 +28,8 @@ declare function useFileDiffInstance<LAnnotation>({
|
|
|
27
28
|
metrics,
|
|
28
29
|
hasGutterRenderUtility,
|
|
29
30
|
hasCustomHeader,
|
|
30
|
-
disableWorkerPool
|
|
31
|
+
disableWorkerPool,
|
|
32
|
+
contentEditable
|
|
31
33
|
}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn;
|
|
32
34
|
//#endregion
|
|
33
35
|
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":";;;;;UA2BU,wBAAA;EACR,QAAA,EAAU,gBAAA;EACV,OAAA,EAAS,eAAA,CAAgB,WAAA;EACzB,eAAA,EAAiB,kBAAA,CAAmB,WAAA;EACpC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,eAAA;AAAA;AAAA,UAGQ,yBAAA;EACR,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAoB;AAAA;AAAA,iBAGxB,mBAAA;EACd,QAAA;EACA,OAAA;EACA,eAAA;EACA,aAAA;EACA,eAAA;EACA,OAAA;EACA,sBAAA;EACA,eAAA;EACA,iBAAA;EACA;AAAA,GACC,wBAAA,CAAyB,WAAA,IAAe,yBAAA"}
|
|
@@ -4,27 +4,33 @@ import { VirtualizedFileDiff } from "../../components/VirtualizedFileDiff.js";
|
|
|
4
4
|
import { noopRender } from "../constants.js";
|
|
5
5
|
import { useStableCallback } from "./useStableCallback.js";
|
|
6
6
|
import { WorkerPoolContext } from "../WorkerPoolContext.js";
|
|
7
|
+
import { useEditor } from "../EditContext.js";
|
|
7
8
|
import { useVirtualizer } from "../Virtualizer.js";
|
|
8
9
|
import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
|
|
9
10
|
//#region src/react/utils/useFileDiffInstance.ts
|
|
10
11
|
const useIsometricEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
11
|
-
function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }) {
|
|
12
|
+
function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, contentEditable }) {
|
|
12
13
|
const simpleVirtualizer = useVirtualizer();
|
|
13
14
|
const controlledSelection = selectedLines !== void 0;
|
|
14
15
|
const poolManager = useContext(WorkerPoolContext);
|
|
16
|
+
const editor = useEditor();
|
|
15
17
|
const instanceRef = useRef(null);
|
|
16
18
|
const ref = useStableCallback((fileContainer) => {
|
|
17
19
|
if (fileContainer != null) {
|
|
18
20
|
if (instanceRef.current != null) throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");
|
|
19
21
|
if (simpleVirtualizer != null) instanceRef.current = new VirtualizedFileDiff(mergeFileDiffOptions({
|
|
20
22
|
controlledSelection,
|
|
23
|
+
contentEditable,
|
|
21
24
|
hasCustomHeader,
|
|
25
|
+
hasEditor: editor !== void 0,
|
|
22
26
|
hasGutterRenderUtility,
|
|
23
27
|
options
|
|
24
28
|
}), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
|
|
25
29
|
else instanceRef.current = new FileDiff(mergeFileDiffOptions({
|
|
26
30
|
controlledSelection,
|
|
31
|
+
contentEditable,
|
|
27
32
|
hasCustomHeader,
|
|
33
|
+
hasEditor: editor !== void 0,
|
|
28
34
|
hasGutterRenderUtility,
|
|
29
35
|
options
|
|
30
36
|
}), !disableWorkerPool ? poolManager : void 0, true);
|
|
@@ -45,7 +51,9 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
|
|
|
45
51
|
if (instance == null) return;
|
|
46
52
|
const newOptions = mergeFileDiffOptions({
|
|
47
53
|
controlledSelection,
|
|
54
|
+
contentEditable,
|
|
48
55
|
hasCustomHeader,
|
|
56
|
+
hasEditor: editor !== void 0,
|
|
49
57
|
hasGutterRenderUtility,
|
|
50
58
|
options
|
|
51
59
|
});
|
|
@@ -58,6 +66,12 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
|
|
|
58
66
|
});
|
|
59
67
|
if (selectedLines !== void 0) instance.setSelectedLines(selectedLines);
|
|
60
68
|
});
|
|
69
|
+
useIsometricEffect(() => {
|
|
70
|
+
if (contentEditable && instanceRef.current != null) {
|
|
71
|
+
if (editor === void 0) throw new Error("FileDiff: Editor is not attached");
|
|
72
|
+
return editor.edit(instanceRef.current);
|
|
73
|
+
}
|
|
74
|
+
}, [contentEditable, editor]);
|
|
61
75
|
return {
|
|
62
76
|
ref,
|
|
63
77
|
getHoveredLine: useCallback(() => {
|
|
@@ -65,13 +79,23 @@ function useFileDiffInstance({ fileDiff, options, lineAnnotations, selectedLines
|
|
|
65
79
|
}, [])
|
|
66
80
|
};
|
|
67
81
|
}
|
|
68
|
-
function mergeFileDiffOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility }) {
|
|
69
|
-
|
|
82
|
+
function mergeFileDiffOptions({ options, controlledSelection, contentEditable, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
|
|
83
|
+
const needsEditorOptions = contentEditable && hasEditor;
|
|
84
|
+
const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
|
|
85
|
+
if (!needsReactOverrides && !needsEditorOptions) return options;
|
|
70
86
|
return {
|
|
71
87
|
...options,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
...needsReactOverrides ? {
|
|
89
|
+
controlledSelection,
|
|
90
|
+
renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
|
|
91
|
+
renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
|
|
92
|
+
} : null,
|
|
93
|
+
...needsEditorOptions ? {
|
|
94
|
+
useTokenTransformer: true,
|
|
95
|
+
enableGutterUtility: false,
|
|
96
|
+
enableLineSelection: false,
|
|
97
|
+
lineHoverHighlight: "disabled"
|
|
98
|
+
} : null
|
|
75
99
|
};
|
|
76
100
|
}
|
|
77
101
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { FileDiff, type FileDiffOptions } from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\n\nexport function useFileDiffInstance<LAnnotation>({\n fileDiff,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<\n FileDiff<LAnnotation> | VirtualizedFileDiff<LAnnotation> | null\n >(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n fileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n forceRender,\n fileDiff,\n lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return {
|
|
1
|
+
{"version":3,"file":"useFileDiffInstance.js","names":[],"sources":["../../../src/react/utils/useFileDiffInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { FileDiff, type FileDiffOptions } from '../../components/FileDiff';\nimport { VirtualizedFileDiff } from '../../components/VirtualizedFileDiff';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n DiffLineAnnotation,\n FileDiffMetadata,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileDiffInstanceProps<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options: FileDiffOptions<LAnnotation> | undefined;\n lineAnnotations: DiffLineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n contentEditable: boolean;\n}\n\ninterface UseFileDiffInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'diff'> | undefined;\n}\n\nexport function useFileDiffInstance<LAnnotation>({\n fileDiff,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n contentEditable,\n}: UseFileDiffInstanceProps<LAnnotation>): UseFileDiffInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const editor = useEditor<LAnnotation>();\n const instanceRef = useRef<\n FileDiff<LAnnotation> | VirtualizedFileDiff<LAnnotation> | null\n >(null);\n const ref = useStableCallback((fileContainer: HTMLElement | null) => {\n if (fileContainer != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'useFileDiffInstance: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new FileDiff(\n mergeFileDiffOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n fileDiff,\n fileContainer,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error(\n 'useFileDiffInstance: A FileDiff instance should exist when unmounting'\n );\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n const { current: instance } = instanceRef;\n if (instance == null) return;\n const newOptions = mergeFileDiffOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(instance.options, newOptions);\n instance.setOptions(newOptions);\n void instance.render({\n forceRender,\n fileDiff,\n lineAnnotations,\n });\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines);\n }\n });\n\n useIsometricEffect(() => {\n if (contentEditable && instanceRef.current != null) {\n if (editor === undefined) {\n throw new Error('FileDiff: Editor is not attached');\n }\n return editor.edit(instanceRef.current);\n }\n return undefined;\n }, [contentEditable, editor]);\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'diff'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n\n return {\n ref,\n getHoveredLine,\n };\n}\n\ninterface MergeFileDiffOptionsProps<LAnnotation> {\n controlledSelection: boolean;\n contentEditable: boolean;\n hasEditor: boolean;\n hasCustomHeader: boolean;\n hasGutterRenderUtility: boolean;\n options: FileDiffOptions<LAnnotation> | undefined;\n}\n\nfunction mergeFileDiffOptions<LAnnotation>({\n options,\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor,\n hasGutterRenderUtility,\n}: MergeFileDiffOptionsProps<LAnnotation>):\n | FileDiffOptions<LAnnotation>\n | undefined {\n const needsEditorOptions = contentEditable && hasEditor;\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides && !needsEditorOptions) {\n return options;\n }\n\n return {\n ...options,\n ...(needsReactOverrides\n ? {\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n }\n : null),\n ...(needsEditorOptions\n ? {\n useTokenTransformer: true,\n enableGutterUtility: false,\n enableLineSelection: false,\n lineHoverHighlight: 'disabled',\n }\n : null),\n };\n}\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAoB9C,SAAgB,oBAAiC,EAC/C,UACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,mBACmE;CACnE,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,SAAS,UAAuB;CACtC,MAAM,cAAc,OAElB,IAAI;CACN,MAAM,MAAM,mBAAmB,kBAAsC;EACnE,IAAI,iBAAiB,MAAM;GACzB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,kFACF;GAEF,IAAI,qBAAqB,MACvB,YAAY,UAAU,IAAI,oBACxB,qBAAqB;IACnB;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,SACxB,qBAAqB;IACnB;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;GAEF,YAAiB,QAAQ,QAAQ;IAC/B;IACA;IACA;IACA;GACF,CAAC;EACH,OAAO;GACL,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,uEACF;GAEF,YAAY,QAAQ,QAAQ;GAC5B,YAAY,UAAU;EACxB;CACF,CAAC;CAED,yBAAyB;EACvB,MAAM,EAAE,SAAS,aAAa;EAC9B,IAAI,YAAY,MAAM;EACtB,MAAM,aAAa,qBAAqB;GACtC;GACA;GACA;GACA,WAAW,WAAW,KAAA;GACtB;GACA;EACF,CAAC;EACD,MAAM,cAAc,CAAC,gBAAgB,SAAS,SAAS,UAAU;EACjE,SAAS,WAAW,UAAU;EAC9B,SAAc,OAAO;GACnB;GACA;GACA;EACF,CAAC;EACD,IAAI,kBAAkB,KAAA,GACpB,SAAS,iBAAiB,aAAa;CAE3C,CAAC;CAED,yBAAyB;EACvB,IAAI,mBAAmB,YAAY,WAAW,MAAM;GAClD,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,kCAAkC;GAEpD,OAAO,OAAO,KAAK,YAAY,OAAO;EACxC;CAEF,GAAG,CAAC,iBAAiB,MAAM,CAAC;CAQ5B,OAAO;EACL;EACA,gBARqB,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CAIW;CACf;AACF;AAWA,SAAS,qBAAkC,EACzC,SACA,qBACA,iBACA,iBACA,WACA,0BAGY;CACZ,MAAM,qBAAqB,mBAAmB;CAC9C,MAAM,sBACJ,uBAAuB,0BAA0B;CAEnD,IAAI,CAAC,uBAAuB,CAAC,oBAC3B,OAAO;CAGT,OAAO;EACL,GAAG;EACH,GAAI,sBACA;GACE;GACA,oBAAoB,kBAChB,aACA,SAAS;GACb,qBAAqB,yBACjB,aACA,SAAS;EACf,IACA;EACJ,GAAI,qBACA;GACE,qBAAqB;GACrB,qBAAqB;GACrB,qBAAqB;GACrB,oBAAoB;EACtB,IACA;CACN;AACF"}
|
|
@@ -13,6 +13,8 @@ interface UseFileInstanceProps<LAnnotation> {
|
|
|
13
13
|
hasGutterRenderUtility: boolean;
|
|
14
14
|
hasCustomHeader: boolean;
|
|
15
15
|
disableWorkerPool: boolean;
|
|
16
|
+
contentEditable: boolean;
|
|
17
|
+
onChange?: (file: FileContents, lineAnnotations?: LineAnnotation<LAnnotation>[]) => void;
|
|
16
18
|
}
|
|
17
19
|
interface UseFileInstanceReturn {
|
|
18
20
|
ref(node: HTMLElement | null): void;
|
|
@@ -27,7 +29,8 @@ declare function useFileInstance<LAnnotation>({
|
|
|
27
29
|
metrics,
|
|
28
30
|
hasGutterRenderUtility,
|
|
29
31
|
hasCustomHeader,
|
|
30
|
-
disableWorkerPool
|
|
32
|
+
disableWorkerPool,
|
|
33
|
+
contentEditable
|
|
31
34
|
}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn;
|
|
32
35
|
//#endregion
|
|
33
36
|
export { useFileInstance };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useFileInstance.d.ts","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"mappings":";;;;;UA2BU,oBAAA;EACR,IAAA,EAAM,YAAA;EACN,OAAA,EAAS,WAAA,CAAY,WAAA;EACrB,eAAA,EAAiB,cAAA,CAAe,WAAA;EAChC,aAAA,EAAe,iBAAA;EACf,eAAA;EACA,OAAA,GAAU,kBAAA;EACV,sBAAA;EACA,eAAA;EACA,iBAAA;EACA,eAAA;EACA,QAAA,IACE,IAAA,EAAM,YAAA,EACN,eAAA,GAAkB,cAAA,CAAe,WAAA;AAAA;AAAA,UAI3B,qBAAA;EACR,GAAA,CAAI,IAAA,EAAM,WAAA;EACV,cAAA,IAAkB,oBAAoB;AAAA;AAAA,iBAGxB,eAAA;EACd,IAAA;EACA,OAAA;EACA,eAAA;EACA,aAAA;EACA,eAAA;EACA,OAAA;EACA,sBAAA;EACA,eAAA;EACA,iBAAA;EACA;AAAA,GACC,oBAAA,CAAqB,WAAA,IAAe,qBAAA"}
|
|
@@ -4,27 +4,33 @@ import { VirtualizedFile } from "../../components/VirtualizedFile.js";
|
|
|
4
4
|
import { noopRender } from "../constants.js";
|
|
5
5
|
import { useStableCallback } from "./useStableCallback.js";
|
|
6
6
|
import { WorkerPoolContext } from "../WorkerPoolContext.js";
|
|
7
|
+
import { useEditor } from "../EditContext.js";
|
|
7
8
|
import { useVirtualizer } from "../Virtualizer.js";
|
|
8
9
|
import { useCallback, useContext, useEffect, useLayoutEffect, useRef } from "react";
|
|
9
10
|
//#region src/react/utils/useFileInstance.ts
|
|
10
11
|
const useIsometricEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
11
|
-
function useFileInstance({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool }) {
|
|
12
|
+
function useFileInstance({ file, options, lineAnnotations, selectedLines, prerenderedHTML, metrics, hasGutterRenderUtility, hasCustomHeader, disableWorkerPool, contentEditable }) {
|
|
12
13
|
const simpleVirtualizer = useVirtualizer();
|
|
13
14
|
const controlledSelection = selectedLines !== void 0;
|
|
14
15
|
const poolManager = useContext(WorkerPoolContext);
|
|
16
|
+
const editor = useEditor();
|
|
15
17
|
const instanceRef = useRef(null);
|
|
16
18
|
const ref = useStableCallback((node) => {
|
|
17
19
|
if (node != null) {
|
|
18
20
|
if (instanceRef.current != null) throw new Error("File: An instance should not already exist when a node is created");
|
|
19
21
|
if (simpleVirtualizer != null) instanceRef.current = new VirtualizedFile(mergeFileOptions({
|
|
20
22
|
controlledSelection,
|
|
23
|
+
contentEditable,
|
|
21
24
|
hasCustomHeader,
|
|
25
|
+
hasEditor: editor !== void 0,
|
|
22
26
|
hasGutterRenderUtility,
|
|
23
27
|
options
|
|
24
28
|
}), simpleVirtualizer, metrics, !disableWorkerPool ? poolManager : void 0, true);
|
|
25
29
|
else instanceRef.current = new File(mergeFileOptions({
|
|
26
30
|
controlledSelection,
|
|
31
|
+
contentEditable,
|
|
27
32
|
hasCustomHeader,
|
|
33
|
+
hasEditor: editor !== void 0,
|
|
28
34
|
hasGutterRenderUtility,
|
|
29
35
|
options
|
|
30
36
|
}), !disableWorkerPool ? poolManager : void 0, true);
|
|
@@ -44,7 +50,9 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
|
|
|
44
50
|
if (instanceRef.current == null) return;
|
|
45
51
|
const newOptions = mergeFileOptions({
|
|
46
52
|
controlledSelection,
|
|
53
|
+
contentEditable,
|
|
47
54
|
hasCustomHeader,
|
|
55
|
+
hasEditor: editor !== void 0,
|
|
48
56
|
hasGutterRenderUtility,
|
|
49
57
|
options
|
|
50
58
|
});
|
|
@@ -57,6 +65,12 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
|
|
|
57
65
|
});
|
|
58
66
|
if (selectedLines !== void 0) instanceRef.current.setSelectedLines(selectedLines);
|
|
59
67
|
});
|
|
68
|
+
useIsometricEffect(() => {
|
|
69
|
+
if (contentEditable && instanceRef.current != null) {
|
|
70
|
+
if (editor === void 0) throw new Error("File: Editor is not attached");
|
|
71
|
+
return editor.edit(instanceRef.current);
|
|
72
|
+
}
|
|
73
|
+
}, [contentEditable, editor]);
|
|
60
74
|
return {
|
|
61
75
|
ref,
|
|
62
76
|
getHoveredLine: useCallback(() => {
|
|
@@ -64,14 +78,25 @@ function useFileInstance({ file, options, lineAnnotations, selectedLines, preren
|
|
|
64
78
|
}, [])
|
|
65
79
|
};
|
|
66
80
|
}
|
|
67
|
-
function mergeFileOptions({ options, controlledSelection, hasCustomHeader, hasGutterRenderUtility }) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
function mergeFileOptions({ options, controlledSelection, contentEditable, hasCustomHeader, hasEditor, hasGutterRenderUtility }) {
|
|
82
|
+
const needsEditorOptions = contentEditable && hasEditor;
|
|
83
|
+
const needsReactOverrides = controlledSelection || hasGutterRenderUtility || hasCustomHeader;
|
|
84
|
+
if (!needsReactOverrides && !needsEditorOptions) return options;
|
|
85
|
+
let merged = { ...options };
|
|
86
|
+
if (needsReactOverrides) merged = {
|
|
87
|
+
...merged,
|
|
71
88
|
controlledSelection,
|
|
72
89
|
renderCustomHeader: hasCustomHeader ? noopRender : options?.renderCustomHeader,
|
|
73
90
|
renderGutterUtility: hasGutterRenderUtility ? noopRender : options?.renderGutterUtility
|
|
74
91
|
};
|
|
92
|
+
if (needsEditorOptions) merged = {
|
|
93
|
+
...merged,
|
|
94
|
+
useTokenTransformer: true,
|
|
95
|
+
enableGutterUtility: false,
|
|
96
|
+
enableLineSelection: false,
|
|
97
|
+
lineHoverHighlight: "disabled"
|
|
98
|
+
};
|
|
99
|
+
return merged;
|
|
75
100
|
}
|
|
76
101
|
//#endregion
|
|
77
102
|
export { useFileInstance };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { File, type FileOptions } from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n}\n\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function useFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const instanceRef = useRef<\n File<LAnnotation> | VirtualizedFile<LAnnotation> | null\n >(null);\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(\n instanceRef.current.options,\n newOptions\n );\n instanceRef.current.setOptions(newOptions);\n void instanceRef.current.render({ file, lineAnnotations, forceRender });\n if (selectedLines !== undefined) {\n instanceRef.current.setSelectedLines(selectedLines);\n }\n });\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileOptionsProps<LAnnotation> {\n options: FileOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeFileOptions<LAnnotation>({\n options,\n controlledSelection,\n hasCustomHeader,\n hasGutterRenderUtility,\n}: MergeFileOptionsProps<LAnnotation>): FileOptions<LAnnotation> | undefined {\n
|
|
1
|
+
{"version":3,"file":"useFileInstance.js","names":[],"sources":["../../../src/react/utils/useFileInstance.ts"],"sourcesContent":["import {\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n} from 'react';\n\nimport { File, type FileOptions } from '../../components/File';\nimport { VirtualizedFile } from '../../components/VirtualizedFile';\nimport type { GetHoveredLineResult } from '../../managers/InteractionManager';\nimport type {\n FileContents,\n LineAnnotation,\n SelectedLineRange,\n VirtualFileMetrics,\n} from '../../types';\nimport { areOptionsEqual } from '../../utils/areOptionsEqual';\nimport { noopRender } from '../constants';\nimport { useEditor } from '../EditContext';\nimport { useVirtualizer } from '../Virtualizer';\nimport { WorkerPoolContext } from '../WorkerPoolContext';\nimport { useStableCallback } from './useStableCallback';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ninterface UseFileInstanceProps<LAnnotation> {\n file: FileContents;\n options: FileOptions<LAnnotation> | undefined;\n lineAnnotations: LineAnnotation<LAnnotation>[] | undefined;\n selectedLines: SelectedLineRange | null | undefined;\n prerenderedHTML: string | undefined;\n metrics?: VirtualFileMetrics;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n disableWorkerPool: boolean;\n contentEditable: boolean;\n onChange?: (\n file: FileContents,\n lineAnnotations?: LineAnnotation<LAnnotation>[]\n ) => void;\n}\n\ninterface UseFileInstanceReturn {\n ref(node: HTMLElement | null): void;\n getHoveredLine(): GetHoveredLineResult<'file'> | undefined;\n}\n\nexport function useFileInstance<LAnnotation>({\n file,\n options,\n lineAnnotations,\n selectedLines,\n prerenderedHTML,\n metrics,\n hasGutterRenderUtility,\n hasCustomHeader,\n disableWorkerPool,\n contentEditable,\n}: UseFileInstanceProps<LAnnotation>): UseFileInstanceReturn {\n const simpleVirtualizer = useVirtualizer();\n const controlledSelection = selectedLines !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const editor = useEditor<LAnnotation>();\n const instanceRef = useRef<\n File<LAnnotation> | VirtualizedFile<LAnnotation> | null\n >(null);\n const ref = useStableCallback((node: HTMLElement | null) => {\n if (node != null) {\n if (instanceRef.current != null) {\n throw new Error(\n 'File: An instance should not already exist when a node is created'\n );\n }\n if (simpleVirtualizer != null) {\n instanceRef.current = new VirtualizedFile(\n mergeFileOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n simpleVirtualizer,\n metrics,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n } else {\n instanceRef.current = new File(\n mergeFileOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n }),\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n }\n void instanceRef.current.hydrate({\n file,\n fileContainer: node,\n lineAnnotations,\n prerenderedHTML,\n });\n } else {\n if (instanceRef.current == null) {\n throw new Error('File: A File instance should exist when unmounting');\n }\n instanceRef.current.cleanUp();\n instanceRef.current = null;\n }\n });\n\n useIsometricEffect(() => {\n if (instanceRef.current == null) return;\n const newOptions = mergeFileOptions({\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor: editor !== undefined,\n hasGutterRenderUtility,\n options,\n });\n const forceRender = !areOptionsEqual(\n instanceRef.current.options,\n newOptions\n );\n instanceRef.current.setOptions(newOptions);\n void instanceRef.current.render({ file, lineAnnotations, forceRender });\n if (selectedLines !== undefined) {\n instanceRef.current.setSelectedLines(selectedLines);\n }\n });\n\n useIsometricEffect(() => {\n if (contentEditable && instanceRef.current != null) {\n if (editor === undefined) {\n throw new Error('File: Editor is not attached');\n }\n return editor.edit(instanceRef.current);\n }\n return undefined;\n }, [contentEditable, editor]);\n\n const getHoveredLine = useCallback(():\n | GetHoveredLineResult<'file'>\n | undefined => {\n return instanceRef.current?.getHoveredLine();\n }, []);\n return { ref, getHoveredLine };\n}\n\ninterface MergeFileOptionsProps<LAnnotation> {\n options: FileOptions<LAnnotation> | undefined;\n controlledSelection: boolean;\n contentEditable: boolean;\n hasEditor: boolean;\n hasGutterRenderUtility: boolean;\n hasCustomHeader: boolean;\n}\n\nfunction mergeFileOptions<LAnnotation>({\n options,\n controlledSelection,\n contentEditable,\n hasCustomHeader,\n hasEditor,\n hasGutterRenderUtility,\n}: MergeFileOptionsProps<LAnnotation>): FileOptions<LAnnotation> | undefined {\n const needsEditorOptions = contentEditable && hasEditor;\n const needsReactOverrides =\n controlledSelection || hasGutterRenderUtility || hasCustomHeader;\n\n if (!needsReactOverrides && !needsEditorOptions) {\n return options;\n }\n\n let merged: FileOptions<LAnnotation> = { ...options };\n\n if (needsReactOverrides) {\n merged = {\n ...merged,\n controlledSelection,\n renderCustomHeader: hasCustomHeader\n ? noopRender\n : options?.renderCustomHeader,\n renderGutterUtility: hasGutterRenderUtility\n ? noopRender\n : options?.renderGutterUtility,\n };\n }\n\n if (needsEditorOptions) {\n merged = {\n ...merged,\n useTokenTransformer: true,\n enableGutterUtility: false,\n enableLineSelection: false,\n lineHoverHighlight: 'disabled',\n };\n }\n\n return merged;\n}\n"],"mappings":";;;;;;;;;;AAwBA,MAAM,qBACJ,OAAO,WAAW,cAAc,YAAY;AAwB9C,SAAgB,gBAA6B,EAC3C,MACA,SACA,iBACA,eACA,iBACA,SACA,wBACA,iBACA,mBACA,mBAC2D;CAC3D,MAAM,oBAAoB,eAAe;CACzC,MAAM,sBAAsB,kBAAkB,KAAA;CAC9C,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,SAAS,UAAuB;CACtC,MAAM,cAAc,OAElB,IAAI;CACN,MAAM,MAAM,mBAAmB,SAA6B;EAC1D,IAAI,QAAQ,MAAM;GAChB,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MACR,mEACF;GAEF,IAAI,qBAAqB,MACvB,YAAY,UAAU,IAAI,gBACxB,iBAAiB;IACf;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,mBACA,SACA,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;QAEA,YAAY,UAAU,IAAI,KACxB,iBAAiB;IACf;IACA;IACA;IACA,WAAW,WAAW,KAAA;IACtB;IACA;GACF,CAAC,GACD,CAAC,oBAAoB,cAAc,KAAA,GACnC,IACF;GAEF,YAAiB,QAAQ,QAAQ;IAC/B;IACA,eAAe;IACf;IACA;GACF,CAAC;EACH,OAAO;GACL,IAAI,YAAY,WAAW,MACzB,MAAM,IAAI,MAAM,oDAAoD;GAEtE,YAAY,QAAQ,QAAQ;GAC5B,YAAY,UAAU;EACxB;CACF,CAAC;CAED,yBAAyB;EACvB,IAAI,YAAY,WAAW,MAAM;EACjC,MAAM,aAAa,iBAAiB;GAClC;GACA;GACA;GACA,WAAW,WAAW,KAAA;GACtB;GACA;EACF,CAAC;EACD,MAAM,cAAc,CAAC,gBACnB,YAAY,QAAQ,SACpB,UACF;EACA,YAAY,QAAQ,WAAW,UAAU;EACzC,YAAiB,QAAQ,OAAO;GAAE;GAAM;GAAiB;EAAY,CAAC;EACtE,IAAI,kBAAkB,KAAA,GACpB,YAAY,QAAQ,iBAAiB,aAAa;CAEtD,CAAC;CAED,yBAAyB;EACvB,IAAI,mBAAmB,YAAY,WAAW,MAAM;GAClD,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,8BAA8B;GAEhD,OAAO,OAAO,KAAK,YAAY,OAAO;EACxC;CAEF,GAAG,CAAC,iBAAiB,MAAM,CAAC;CAO5B,OAAO;EAAE;EAAK,gBALS,kBAEN;GACf,OAAO,YAAY,SAAS,eAAe;EAC7C,GAAG,CAAC,CACuB;CAAE;AAC/B;AAWA,SAAS,iBAA8B,EACrC,SACA,qBACA,iBACA,iBACA,WACA,0BAC2E;CAC3E,MAAM,qBAAqB,mBAAmB;CAC9C,MAAM,sBACJ,uBAAuB,0BAA0B;CAEnD,IAAI,CAAC,uBAAuB,CAAC,oBAC3B,OAAO;CAGT,IAAI,SAAmC,EAAE,GAAG,QAAQ;CAEpD,IAAI,qBACF,SAAS;EACP,GAAG;EACH;EACA,oBAAoB,kBAChB,aACA,SAAS;EACb,qBAAqB,yBACjB,aACA,SAAS;CACf;CAGF,IAAI,oBACF,SAAS;EACP,GAAG;EACH,qBAAqB;EACrB,qBAAqB;EACrB,qBAAqB;EACrB,oBAAoB;CACtB;CAGF,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Element, ElementContent, Properties } from "../node_modules/.pnpm/@types_hast@3.0.4/node_modules/@types/hast/index.js";
|
|
2
|
-
import { BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from "../types.js";
|
|
2
|
+
import { BaseDiffOptions, BaseDiffOptionsWithDefaults, CustomPreProperties, DiffLineAnnotation, DiffsHighlighter, DiffsTextDocument, ExpansionDirections, FileDiffMetadata, FileHeaderRenderMode, HighlightedToken, HunkData, HunkExpansionRegion, LineTypes, RenderDiffOptions, RenderRange, ThemedDiffResult } from "../types.js";
|
|
3
3
|
import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
|
|
4
4
|
import { DiffLineMetadata } from "../utils/iterateOverDiff.js";
|
|
5
5
|
|
|
@@ -81,16 +81,42 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
|
|
|
81
81
|
private additionAnnotations;
|
|
82
82
|
private computedLang;
|
|
83
83
|
private renderCache;
|
|
84
|
+
private editSessionActive;
|
|
85
|
+
private editSessionLines;
|
|
84
86
|
constructor(options?: DiffHunksRendererOptions, onRenderUpdate?: (() => unknown) | undefined, workerManager?: WorkerPoolManager | undefined);
|
|
85
87
|
cleanUp(): void;
|
|
86
88
|
recycle(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Enter edit-session mode: hunk updates preserve the current region
|
|
91
|
+
* skeleton instead of recomputing hunks. Called on every editor attach,
|
|
92
|
+
* including a re-attach after recycle, which losslessly re-seeds the pass
|
|
93
|
+
* snapshot because both hunk-update paths keep `diff.additionLines`
|
|
94
|
+
* current.
|
|
95
|
+
*/
|
|
96
|
+
beginEditSession(diff: FileDiffMetadata | undefined): void;
|
|
97
|
+
/** Leave edit-session mode. The exit recompute is the host's concern. */
|
|
98
|
+
endEditSession(): void;
|
|
99
|
+
get diffCache(): FileDiffMetadata | undefined;
|
|
87
100
|
clearRenderCache(): void;
|
|
88
101
|
setOptions(options: DiffHunksRendererOptions): void;
|
|
89
102
|
mergeOptions(options: Partial<DiffHunksRendererOptions>): void;
|
|
90
103
|
expandHunk(index: number, direction: ExpansionDirections, expansionLineCount?: number): void;
|
|
91
104
|
getExpandedHunk(hunkIndex: number): HunkExpansionRegion;
|
|
92
105
|
getExpandedHunksMap(): Map<number, HunkExpansionRegion>;
|
|
106
|
+
/** Replace the whole expansion map (session-exit expansion remapping). */
|
|
107
|
+
setExpandedHunksMap(expandedHunks: Map<number, HunkExpansionRegion>): void;
|
|
93
108
|
setLineAnnotations(lineAnnotations: DiffLineAnnotation<LAnnotation>[]): void;
|
|
109
|
+
/**
|
|
110
|
+
* Returns true when a session-mode pass changed the region skeleton itself
|
|
111
|
+
* (a gap edit synthesized or merged regions), which changes the rendered
|
|
112
|
+
* row set without a line-count change — the host must escalate to a full
|
|
113
|
+
* re-render instead of its cheap refresh path.
|
|
114
|
+
*/
|
|
115
|
+
updateRenderCache(dirtyLines: Map<number, Array<HighlightedToken>>, themeType: 'dark' | 'light', lineCountChangeInFlight?: boolean): boolean;
|
|
116
|
+
private applyExpansionRemaps;
|
|
117
|
+
applyDocumentChange(textDocument: DiffsTextDocument): void;
|
|
118
|
+
private applySessionDocumentChange;
|
|
119
|
+
private markEditSessionPass;
|
|
94
120
|
protected getUnifiedLineDecoration({
|
|
95
121
|
lineType
|
|
96
122
|
}: UnifiedLineDecorationProps): LineDecoration;
|
|
@@ -102,7 +128,7 @@ declare class DiffHunksRenderer<LAnnotation = undefined> {
|
|
|
102
128
|
protected getUnifiedInjectedRowsForLine?: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;
|
|
103
129
|
protected getSplitInjectedRowsForLine?: (ctx: RenderedLineContext) => SplitInjectedRowPlacement | undefined;
|
|
104
130
|
protected getOptionsWithDefaults(): DiffHunksRendererOptionsWithDefaults;
|
|
105
|
-
|
|
131
|
+
initializeHighlighter(): Promise<DiffsHighlighter>;
|
|
106
132
|
hydrate(diff: FileDiffMetadata | undefined): void;
|
|
107
133
|
private getRenderOptions;
|
|
108
134
|
renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"DiffHunksRenderer.d.ts","names":[],"sources":["../../src/renderers/DiffHunksRenderer.ts"],"mappings":"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"}
|