@pierre/diffs 1.3.0-beta.9 → 1.3.0-rc.2
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/README.md +9 -0
- package/dist/components/CodeView.d.ts +12 -13
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +50 -58
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +10 -3
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +41 -10
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +37 -6
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +202 -19
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +7 -2
- package/dist/components/UnresolvedFile.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 +27 -2
- 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 +53 -12
- 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 +977 -241
- 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.map +1 -1
- package/dist/editor/searchPanel.js +9 -2
- 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} +170 -50
- 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 +4 -3
- package/dist/index.js +6 -5
- 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.map +1 -1
- package/dist/managers/UniversalRenderingManager.js +1 -2
- 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 +37 -28
- 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 +24 -34
- 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 +23 -33
- package/dist/react/utils/useFileInstance.js.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +4 -4
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +41 -1
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +167 -29
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +20 -1
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +119 -29
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +3 -1
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/ssr/preloadFile.d.ts.map +1 -1
- package/dist/ssr/preloadFile.js +2 -0
- package/dist/ssr/preloadFile.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/types.d.ts +192 -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/getDiffHunksRendererOptions.d.ts.map +1 -1
- package/dist/utils/getDiffHunksRendererOptions.js +2 -1
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -1
- package/dist/utils/getFileRendererOptions.d.ts.map +1 -1
- package/dist/utils/getFileRendererOptions.js +2 -1
- package/dist/utils/getFileRendererOptions.js.map +1 -1
- 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/shouldUseTokenTransformer.d.ts +7 -3
- package/dist/utils/shouldUseTokenTransformer.d.ts.map +1 -1
- package/dist/utils/shouldUseTokenTransformer.js +1 -1
- package/dist/utils/shouldUseTokenTransformer.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 +2 -1
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +3 -0
- package/dist/worker/WorkerPoolManager.js.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 +10 -7
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeView.d.ts","names":[],"sources":["../../src/react/CodeView.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CodeView.d.ts","names":[],"sources":["../../src/react/CodeView.tsx"],"mappings":";;;;;;;KA+CK,2BAAA,UACM,oBAAA,+BACA,oBAAoB;AAAA,KAEnB,oBAAA,4BAAgD,IAAA,CAC1D,eAAA,CAAgB,WAAA;AAAA,UAIR,iBAAA;EACR,OAAA,GAAU,oBAAA,CAAqB,WAAA;;;AArBf;;EA0BhB,aAAA,GAAgB,IAAA,CAAK,aAAA,CAAc,WAAA;EACnC,SAAA;EACA,KAAA,GAAQ,aAAA;EACR,YAAA,GAAe,GAAA,CAAI,cAAA;EACnB,iBAAA;EACA,aAAA,GAAgB,qBAAA;EAChB,qBAAA,EAAuB,SAAA,EAAW,qBAAA;EAClC,QAAA,EAAU,SAAA,UAAmB,MAAA,EAAQ,UAAA,CAAc,WAAA;EAlBO;;EAqB1D,oBAAA,KAAyB,SAAA;EArBM;;EAwB/B,oBAAA,KAAyB,SAAA;EAvBT;EAyBhB,gBAAA,EACE,IAAA,EAAM,YAAA,CAAa,WAAA,GACnB,IAAA,EAAM,YAAA,EACN,eAAA,GACI,cAAA,CAAe,WAAA,MACf,kBAAA,CAAmB,WAAA;EA9BE;AAE3B;;;;;;EAqCA,kBAAA,EACE,IAAA,EAAM,YAAA,CAAa,WAAA,GACnB,IAAA,EAAM,YAAA,EACN,eAAA,GACI,cAAA,CAAe,WAAA,MACf,kBAAA,CAAmB,WAAA;EAEzB,kBAAA,EAAoB,IAAA,EAAM,YAAA,CAAa,WAAA,IAAe,SAAA;EACtD,kBAAA,EAAoB,IAAA,EAAM,YAAA,CAAa,WAAA,IAAe,SAAA;EACtD,0BAAA,EAA4B,IAAA,EAAM,YAAA,CAAa,WAAA,IAAe,SAAA;EAC9D,oBAAA,EAAsB,IAAA,EAAM,YAAA,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.js";
|
|
3
3
|
import { areOptionsEqual } from "../utils/areOptionsEqual.js";
|
|
4
4
|
import { CodeView as CodeView$1 } from "../components/CodeView.js";
|
|
5
|
+
import { useStableCallback } from "./utils/useStableCallback.js";
|
|
6
|
+
import { useCreateEditor } from "./EditContext.js";
|
|
5
7
|
import { renderDiffChildren } from "./utils/renderDiffChildren.js";
|
|
6
8
|
import { renderFileChildren } from "./utils/renderFileChildren.js";
|
|
7
|
-
import { useStableCallback } from "./utils/useStableCallback.js";
|
|
8
9
|
import { WorkerPoolContext } from "./WorkerPoolContext.js";
|
|
9
10
|
import { forwardRef, memo, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
10
11
|
import { createPortal, flushSync } from "react-dom";
|
|
11
12
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
13
|
//#region src/react/CodeView.tsx
|
|
13
|
-
const
|
|
14
|
+
const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
|
|
14
15
|
function createDefaultCache(controlled) {
|
|
15
16
|
return {
|
|
16
17
|
instance: void 0,
|
|
@@ -22,8 +23,9 @@ function createDefaultCache(controlled) {
|
|
|
22
23
|
};
|
|
23
24
|
}
|
|
24
25
|
function CodeViewInner(props, ref) {
|
|
25
|
-
const { className, containerRef,
|
|
26
|
+
const { className, containerRef, disableWorkerPool = false, editorOptions, initialItems, items: controlledItems, onItemEditChange, onItemEditComplete, onScroll, onSelectedLinesChange, options, renderAnnotation, renderCodeViewFooter, renderCodeViewHeader, renderCustomHeader, renderGutterUtility, renderHeaderFilenameSuffix, renderHeaderMetadata, renderHeaderPrefix, selectedLines, style } = props;
|
|
26
27
|
const controlled = controlledItems !== void 0;
|
|
28
|
+
const contextCreateEditor = useCreateEditor();
|
|
27
29
|
const poolManager = useContext(WorkerPoolContext);
|
|
28
30
|
const cachedDataRef = useRef(createDefaultCache(controlled));
|
|
29
31
|
const hasCustomHeader = renderCustomHeader != null;
|
|
@@ -37,7 +39,15 @@ function CodeViewInner(props, ref) {
|
|
|
37
39
|
onSelectedLinesChange?.(selection);
|
|
38
40
|
});
|
|
39
41
|
const controlledSelection = selectedLines !== void 0;
|
|
40
|
-
const
|
|
42
|
+
const createEditor = useStableCallback((options) => {
|
|
43
|
+
if (contextCreateEditor == null) throw new Error("CodeView: EditContext is not attached");
|
|
44
|
+
const editor = contextCreateEditor({
|
|
45
|
+
...editorOptions,
|
|
46
|
+
...options
|
|
47
|
+
});
|
|
48
|
+
if (editor == null) throw new Error("CodeView: EditProvider.createEditor must return an editor instance");
|
|
49
|
+
return editor;
|
|
50
|
+
});
|
|
41
51
|
const emitItemEditChange = useStableCallback((item, file, lineAnnotations) => {
|
|
42
52
|
onItemEditChange?.(item, file, lineAnnotations);
|
|
43
53
|
});
|
|
@@ -52,24 +62,24 @@ function CodeViewInner(props, ref) {
|
|
|
52
62
|
hasCodeViewFooter,
|
|
53
63
|
onSelectedLinesChange: onSelectedLinesChange != null ? emitSelectedLinesChange : void 0,
|
|
54
64
|
controlledSelection,
|
|
55
|
-
createEditor:
|
|
65
|
+
createEditor: contextCreateEditor != null ? createEditor : void 0,
|
|
56
66
|
onItemEditChange: onItemEditChange != null ? emitItemEditChange : void 0,
|
|
57
67
|
onItemEditComplete: onItemEditComplete != null ? emitItemEditComplete : void 0
|
|
58
68
|
}), [
|
|
59
|
-
|
|
60
|
-
hasCustomHeader,
|
|
61
|
-
hasGutterRenderer,
|
|
62
|
-
hasCodeViewHeader,
|
|
63
|
-
hasCodeViewFooter,
|
|
64
|
-
onSelectedLinesChange,
|
|
65
|
-
emitSelectedLinesChange,
|
|
69
|
+
contextCreateEditor,
|
|
66
70
|
controlledSelection,
|
|
67
71
|
createEditor,
|
|
68
|
-
stableCreateEditor,
|
|
69
|
-
onItemEditChange,
|
|
70
72
|
emitItemEditChange,
|
|
73
|
+
emitItemEditComplete,
|
|
74
|
+
emitSelectedLinesChange,
|
|
75
|
+
hasCodeViewFooter,
|
|
76
|
+
hasCodeViewHeader,
|
|
77
|
+
hasCustomHeader,
|
|
78
|
+
hasGutterRenderer,
|
|
79
|
+
onItemEditChange,
|
|
71
80
|
onItemEditComplete,
|
|
72
|
-
|
|
81
|
+
onSelectedLinesChange,
|
|
82
|
+
options
|
|
73
83
|
]);
|
|
74
84
|
const [slotContentStore] = useState(() => createSlotContentStore());
|
|
75
85
|
const [, forceUpdate] = useState({});
|
|
@@ -108,10 +118,10 @@ function CodeViewInner(props, ref) {
|
|
|
108
118
|
hasCodeViewHeader,
|
|
109
119
|
hasCodeViewFooter
|
|
110
120
|
]);
|
|
111
|
-
|
|
121
|
+
useIsomorphicLayoutEffect(() => {
|
|
112
122
|
return onScroll != null ? cachedDataRef.current.instance?.subscribeToScroll(onScroll) : void 0;
|
|
113
123
|
});
|
|
114
|
-
|
|
124
|
+
useIsomorphicLayoutEffect(() => {
|
|
115
125
|
const { instance, controlled: prevControlled, items: prevItems, managedOptions: prevManagedOptions, slotCoordinator: prevSlotCoordinator } = cachedDataRef.current;
|
|
116
126
|
if (instance == null) return;
|
|
117
127
|
try {
|
|
@@ -283,20 +293,19 @@ function createSlotContentStore() {
|
|
|
283
293
|
};
|
|
284
294
|
}
|
|
285
295
|
function createManagedCodeViewOptions({ options, hasCustomHeader, hasGutterRenderer, hasCodeViewHeader, hasCodeViewFooter, onSelectedLinesChange, controlledSelection, createEditor, onItemEditChange, onItemEditComplete }) {
|
|
286
|
-
|
|
287
|
-
options = {
|
|
296
|
+
const managedOptions = {
|
|
288
297
|
...options,
|
|
289
298
|
controlledSelection,
|
|
290
|
-
onSelectedLinesChange
|
|
299
|
+
onSelectedLinesChange,
|
|
300
|
+
createEditor
|
|
291
301
|
};
|
|
292
|
-
if (
|
|
293
|
-
if (
|
|
294
|
-
if (
|
|
295
|
-
if (
|
|
296
|
-
if (
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
return options;
|
|
302
|
+
if (onItemEditChange != null) managedOptions.onItemEditChange = onItemEditChange;
|
|
303
|
+
if (onItemEditComplete != null) managedOptions.onItemEditComplete = onItemEditComplete;
|
|
304
|
+
if (hasCustomHeader) managedOptions.renderCustomHeader = noopRender;
|
|
305
|
+
if (hasGutterRenderer) managedOptions.renderGutterUtility = noopRender;
|
|
306
|
+
if (hasCodeViewHeader) managedOptions.renderCodeViewHeader = noopRender;
|
|
307
|
+
if (hasCodeViewFooter) managedOptions.renderCodeViewFooter = noopRender;
|
|
308
|
+
return managedOptions;
|
|
300
309
|
}
|
|
301
310
|
const SlotPortals = memo(function SlotPortals({ managedContentStore, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderAnnotation, renderGutterUtility, renderCodeViewHeader, renderCodeViewFooter }) {
|
|
302
311
|
"use no memo";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeView.js","names":["CodeViewClass"],"sources":["../../src/react/CodeView.tsx"],"sourcesContent":["'use client';\n\nimport {\n type CSSProperties,\n forwardRef,\n memo,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal, flushSync } from 'react-dom';\n\nimport {\n areOptionsEqual,\n CodeView as CodeViewClass,\n type CodeViewCoordinator,\n type CodeViewCreateEditorOptions,\n type CodeViewItem,\n type CodeViewLineSelection,\n type CodeViewOptions,\n type CodeViewRenderedItem,\n type CodeViewScrollTarget,\n type CodeViewSlotSnapshot,\n type DiffLineAnnotation,\n type DiffsEditorHost,\n type FileContents,\n type GetHoveredLineResult,\n type LineAnnotation,\n} from '../index';\nimport { areManagedSnapshotsEqual } from '../utils/areManagedSnapshotsEqual';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { useStableCallback } from './utils/useStableCallback';\nimport { WorkerPoolContext } from './WorkerPoolContext';\n\nconst useIsometricEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ntype CodeViewGutterUtilityGetter =\n | (() => GetHoveredLineResult<'file'> | undefined)\n | (() => GetHoveredLineResult<'diff'> | undefined);\n\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewOptions<LAnnotation>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n /** Render a non-virtualized node at the very start of the scroll content,\n * before the first item. Always rendered; scrolls with the content. */\n renderCodeViewHeader?(): ReactNode;\n /** Render a non-virtualized node at the very end of the scroll content, after\n * the last item. Always rendered; scrolls with the content. */\n renderCodeViewFooter?(): ReactNode;\n /**\n * Enables editing for items with `edit: true`. Pass the given options into\n * the editor constructor — `new Editor(options)` from `@pierre/diffs/editor`\n * — so document changes route to `onItemEditChange` and\n * `onItemEditComplete`. CodeView owns the returned editor's lifecycle.\n */\n createEditor?(\n options: CodeViewCreateEditorOptions<LAnnotation>\n ): DiffsEditorHost<LAnnotation> | undefined;\n /** Called with the owning item on every edited-document change. */\n onItemEditChange?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ): void;\n /**\n * Called once with the final contents when an item's edit session ends\n * (edit turned off, item removed or collapsed). Not called for sessions\n * that produced no changes. Committing is user-space: make one combined\n * item write carrying the new file/fileDiff (with a fresh `cacheKey`,\n * since the contents changed) along with `edit: false`.\n */\n onItemEditComplete?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderFilenameSuffix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getEditor(id: string): DiffsEditorHost<LAnnotation> | undefined;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\n\ntype CodeViewComponent = <LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n }\n) => React.JSX.Element;\n\ntype SlotPortalsComponent = <LAnnotation = undefined>(\n props: SlotPortalsProps<LAnnotation>\n) => React.JSX.Element;\n\ninterface ManagedContentStore<LAnnotation> {\n getSnapshot(): CodeViewSlotSnapshot<LAnnotation> | undefined;\n publish(snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined): void;\n subscribe(listener: () => void): () => void;\n}\n\ninterface CachedDataRef<LAnnotation> {\n instance: CodeViewClass<LAnnotation> | undefined;\n items: readonly CodeViewItem<LAnnotation>[] | undefined;\n controlled: boolean;\n managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nfunction createDefaultCache<LAnnotation>(\n controlled: boolean\n): CachedDataRef<LAnnotation> {\n return {\n instance: undefined,\n items: undefined,\n controlled,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n };\n}\n\nfunction CodeViewInner<LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const {\n className,\n containerRef,\n createEditor,\n disableWorkerPool = false,\n initialItems,\n items: controlledItems,\n onItemEditChange,\n onItemEditComplete,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCodeViewFooter,\n renderCodeViewHeader,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderHeaderPrefix,\n selectedLines,\n style,\n } = props;\n const controlled = controlledItems !== undefined;\n const poolManager = useContext(WorkerPoolContext);\n const cachedDataRef = useRef<CachedDataRef<LAnnotation>>(\n createDefaultCache<LAnnotation>(controlled)\n );\n const hasCustomHeader = renderCustomHeader != null;\n const hasAnnotationRenderer = renderAnnotation != null;\n const hasGutterRenderer = renderGutterUtility != null;\n const hasHeaderRenderers =\n hasCustomHeader ||\n renderHeaderPrefix != null ||\n renderHeaderFilenameSuffix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const hasCodeViewHeader = renderCodeViewHeader != null;\n const hasCodeViewFooter = renderCodeViewFooter != null;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n // Stable identities for the editor callbacks so inline props don't churn\n // managedOptions (a changed options object forces a full item re-render).\n const stableCreateEditor = useStableCallback(\n (editorOptions: CodeViewCreateEditorOptions<LAnnotation>) =>\n createEditor?.(editorOptions)\n );\n const emitItemEditChange = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditChange?.(item, file, lineAnnotations);\n }\n );\n const emitItemEditComplete = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?: DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditComplete?.(item, file, lineAnnotations);\n }\n );\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n createEditor: createEditor != null ? stableCreateEditor : undefined,\n onItemEditChange:\n onItemEditChange != null ? emitItemEditChange : undefined,\n onItemEditComplete:\n onItemEditComplete != null ? emitItemEditComplete : undefined,\n }),\n [\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange,\n emitSelectedLinesChange,\n controlledSelection,\n createEditor,\n stableCreateEditor,\n onItemEditChange,\n emitItemEditChange,\n onItemEditComplete,\n emitItemEditComplete,\n ]\n );\n\n const [slotContentStore] = useState<ManagedContentStore<LAnnotation>>(() =>\n createSlotContentStore()\n );\n const [, forceUpdate] = useState<unknown>({});\n\n const nodeRef = useStableCallback((node: HTMLDivElement | null) => {\n // If we have a pre-existing instance and there's no node or the node being\n // passed in is NOT the same as before, then we need to clean up and\n // garbage collect the old instance\n if (\n cachedDataRef.current.instance != null &&\n (node == null ||\n node !== cachedDataRef.current.instance.getContainerElement())\n ) {\n cachedDataRef.current.instance.cleanUp();\n slotContentStore.publish(undefined);\n cachedDataRef.current = createDefaultCache<LAnnotation>(controlled);\n }\n\n // If our node matches the existing node then we should not attempt to\n // setup. This is a case that should never be possible to hit, but just in\n // case, lets make sure we don't re-setup an instance that is already setup\n // properly\n if (\n node != null &&\n node !== cachedDataRef.current.instance?.getContainerElement()\n ) {\n cachedDataRef.current.instance = new CodeViewClass<LAnnotation>(\n managedOptions,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n cachedDataRef.current.instance.setup(node);\n }\n\n if (typeof containerRef === 'function') {\n containerRef(node);\n } else if (containerRef != null) {\n containerRef.current = node;\n }\n });\n\n const onSnapshotChange = useStableCallback(\n (snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined) => {\n if (cachedDataRef.current.disableFlushSync) {\n slotContentStore.publish(snapshot);\n } else {\n flushSync(() => {\n slotContentStore.publish(snapshot);\n });\n }\n }\n );\n\n const slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined =\n useMemo(() => {\n // A coordinator is needed whenever React portals anything — per-item\n // slots and codeview header and footer\n if (\n !hasHeaderRenderers &&\n !hasAnnotationRenderer &&\n !hasGutterRenderer &&\n !hasCodeViewHeader &&\n !hasCodeViewFooter\n ) {\n return undefined;\n } else {\n return {\n hasHeaderRenderers,\n hasAnnotationRenderer,\n hasGutterRenderer,\n onSnapshotChange,\n };\n }\n }, [\n onSnapshotChange,\n hasAnnotationRenderer,\n hasGutterRenderer,\n hasHeaderRenderers,\n hasCodeViewHeader,\n hasCodeViewFooter,\n ]);\n\n useIsometricEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsometricEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n updateItemId(oldId, newId) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItemId');\n if (instance == null) {\n console.error(\n 'CodeView.updateItemId: no valid instance to update item id with',\n oldId,\n newId\n );\n return false;\n }\n\n return instance.updateItemId(oldId, newId);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getEditor(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getEditor: no valid instance exists', id);\n return undefined;\n }\n\n return instance.getEditor(id);\n },\n getInstance() {\n return cachedDataRef.current.instance;\n },\n }),\n [emitSelectedLinesChange]\n );\n\n return (\n <>\n <div ref={nodeRef} className={className} style={style} />\n {(hasRenderers || hasCodeViewHeader || hasCodeViewFooter) && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderFilenameSuffix={renderHeaderFilenameSuffix}\n renderHeaderMetadata={renderHeaderMetadata}\n renderAnnotation={renderAnnotation}\n renderGutterUtility={renderGutterUtility}\n renderCodeViewHeader={renderCodeViewHeader}\n renderCodeViewFooter={renderCodeViewFooter}\n />\n )}\n </>\n );\n}\n\n// React was a mistake\nexport const CodeView = forwardRef(CodeViewInner) as CodeViewComponent;\n\nfunction isAppendOnlyItemUpdate<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): previousItems is readonly CodeViewItem<LAnnotation>[] {\n if (previousItems == null || nextItems.length <= previousItems.length) {\n return false;\n }\n\n if (previousItems.length === 0) {\n return true;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (nextItems[index] !== previousItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction areItemListsEqual<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): boolean {\n if (previousItems == null || previousItems.length !== nextItems.length) {\n return false;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (previousItems[index] !== nextItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction assertUncontrolledCodeViewAction(\n controlled: boolean,\n action: string\n): void {\n if (!controlled) {\n return;\n }\n\n throw new Error(\n `CodeView.${action} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`\n );\n}\n\nfunction createSlotContentStore<\n LAnnotation,\n>(): ManagedContentStore<LAnnotation> {\n let snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined;\n const listeners = new Set<() => void>();\n\n return {\n getSnapshot() {\n return snapshot;\n },\n publish(nextSnapshot) {\n if (areManagedSnapshotsEqual(snapshot, nextSnapshot)) {\n return;\n }\n\n snapshot = nextSnapshot;\n for (const listener of listeners) {\n listener();\n }\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\ninterface CreateManagedCodeViewOptionsProps<LAnnotation> {\n options: CodeViewOptions<LAnnotation> | undefined;\n hasCustomHeader: boolean;\n hasGutterRenderer: boolean;\n hasCodeViewHeader: boolean;\n hasCodeViewFooter: boolean;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n controlledSelection: boolean;\n createEditor: CodeViewOptions<LAnnotation>['createEditor'];\n onItemEditChange: CodeViewOptions<LAnnotation>['onItemEditChange'];\n onItemEditComplete: CodeViewOptions<LAnnotation>['onItemEditComplete'];\n}\n\nfunction createManagedCodeViewOptions<LAnnotation>({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange,\n controlledSelection,\n createEditor,\n onItemEditChange,\n onItemEditComplete,\n}: CreateManagedCodeViewOptionsProps<LAnnotation>):\n | CodeViewOptions<LAnnotation>\n | undefined {\n if (\n !hasCustomHeader &&\n !hasGutterRenderer &&\n !hasCodeViewHeader &&\n !hasCodeViewFooter &&\n onSelectedLinesChange == null &&\n !controlledSelection &&\n createEditor == null &&\n onItemEditChange == null &&\n onItemEditComplete == null\n ) {\n return options ?? {};\n }\n options = { ...options, controlledSelection, onSelectedLinesChange };\n\n // Prop-level editor callbacks win over their options-object counterparts,\n // but an absent prop must not clobber a value provided via `options`.\n if (createEditor != null) {\n options.createEditor = createEditor;\n }\n if (onItemEditChange != null) {\n options.onItemEditChange = onItemEditChange;\n }\n if (onItemEditComplete != null) {\n options.onItemEditComplete = onItemEditComplete;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // switch file and diff headers into custom-slot mode. React portals\n // provide the actual header content, so this placeholder\n // intentionally returns nothing.\n if (hasCustomHeader) {\n options.renderCustomHeader = noopRender;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // create the custom gutter utility slot. React portals provide the\n // actual content, so this placeholder intentionally returns nothing.\n if (hasGutterRenderer) {\n options.renderGutterUtility = noopRender;\n }\n\n // The imperative CodeView adapters use these callbacks' presence to create the\n // header/footer host elements. React portals the actual content into them (via\n // the slot snapshot), so these placeholders intentionally return nothing.\n if (hasCodeViewHeader) {\n options.renderCodeViewHeader = noopRender;\n }\n if (hasCodeViewFooter) {\n options.renderCodeViewFooter = noopRender;\n }\n\n return options;\n}\n\ninterface RenderCodeViewItemChildrenProps<LAnnotation> {\n renderedItem: CodeViewRenderedItem<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\ninterface SlotPortalsProps<LAnnotation> {\n managedContentStore: ManagedContentStore<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n renderCodeViewHeader: CodeViewBaseProps<LAnnotation>['renderCodeViewHeader'];\n renderCodeViewFooter: CodeViewBaseProps<LAnnotation>['renderCodeViewFooter'];\n}\n\nconst SlotPortals = memo(function SlotPortals<LAnnotation>({\n managedContentStore,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n renderCodeViewHeader,\n renderCodeViewFooter,\n}: SlotPortalsProps<LAnnotation>) {\n 'use no memo';\n const subscribe = useStableCallback((listener: () => void) =>\n managedContentStore.subscribe(listener)\n );\n const getSnapshot = useStableCallback(() =>\n managedContentStore.getSnapshot()\n );\n const snapshot = useSyncExternalStore<\n CodeViewSlotSnapshot<LAnnotation> | undefined\n >(subscribe, getSnapshot, getSnapshot);\n let itemKeys = '';\n for (const item of snapshot?.items ?? []) {\n itemKeys += `${item.id}:${item.version}:${item.type}`;\n }\n // NOTE(amadeus): And just like that, the react compiler do be failing us\n // lol... we need to pre-render everything for items, headers and footers to\n // not trigger needless renders while scrolling\n const renderedItems = useMemo(\n () => {\n return snapshot?.items?.map((renderedItem) =>\n createPortal(\n renderCodeViewItemChildren({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n }),\n renderedItem.element,\n renderedItem.id\n )\n );\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps\n [\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n itemKeys,\n ]\n );\n const renderedHeader = useMemo(() => {\n return renderCodeViewHeader != null && snapshot?.header != null\n ? createPortal(renderCodeViewHeader(), snapshot.header)\n : null;\n }, [renderCodeViewHeader, snapshot?.header]);\n const renderedFooter = useMemo(() => {\n return renderCodeViewFooter != null && snapshot?.footer != null\n ? createPortal(renderCodeViewFooter(), snapshot.footer)\n : null;\n }, [renderCodeViewFooter, snapshot?.footer]);\n return (\n <>\n {renderedItems}\n {renderedHeader}\n {renderedFooter}\n </>\n );\n}) as SlotPortalsComponent;\n\nfunction renderCodeViewItemChildren<LAnnotation>({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: RenderCodeViewItemChildrenProps<LAnnotation>): ReactNode {\n if (renderedItem.type === 'diff') {\n const { item, instance } = renderedItem;\n return renderDiffChildren({\n fileDiff: item.fileDiff,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n } else {\n const { item, instance } = renderedItem;\n return renderFileChildren({\n file: item.file,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n }\n}\n\nfunction noopRender() {\n return undefined;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B,2BAA2B,IAAI,IACrC,KAAA;GACN,sBACE,wBAAwB,aACd,qBAAqB,IAAI,IAC/B,KAAA;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,IAAI,IACjD,KAAA;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,IAAI,IAC5D,KAAA;GACN,gBAAgB,SAAS;EAC3B,CAAC;CACH;AACF;AAEA,SAAS,aAAa,CAEtB"}
|
|
1
|
+
{"version":3,"file":"CodeView.js","names":["CodeViewClass"],"sources":["../../src/react/CodeView.tsx"],"sourcesContent":["'use client';\n\nimport {\n type CSSProperties,\n forwardRef,\n memo,\n type ReactNode,\n type Ref,\n useContext,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal, flushSync } from 'react-dom';\n\nimport type { EditorOptions } from '../edit';\nimport {\n areOptionsEqual,\n CodeView as CodeViewClass,\n type CodeViewCoordinator,\n type CodeViewCreateEditorOptions,\n type CodeViewItem,\n type CodeViewLineSelection,\n type CodeViewOptions,\n type CodeViewRenderedItem,\n type CodeViewScrollTarget,\n type CodeViewSlotSnapshot,\n type DiffLineAnnotation,\n type DiffsEditor,\n type FileContents,\n type GetHoveredLineResult,\n type LineAnnotation,\n} from '../index';\nimport { areManagedSnapshotsEqual } from '../utils/areManagedSnapshotsEqual';\nimport { useCreateEditor } from './EditContext';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { useStableCallback } from './utils/useStableCallback';\nimport { WorkerPoolContext } from './WorkerPoolContext';\n\nconst useIsomorphicLayoutEffect =\n typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\ntype CodeViewGutterUtilityGetter =\n | (() => GetHoveredLineResult<'file'> | undefined)\n | (() => GetHoveredLineResult<'diff'> | undefined);\n\nexport type CodeViewReactOptions<LAnnotation = undefined> = Omit<\n CodeViewOptions<LAnnotation>,\n 'controlledSelection' | 'createEditor' | 'onSelectedLinesChange'\n>;\n\ninterface CodeViewBaseProps<LAnnotation> {\n options?: CodeViewReactOptions<LAnnotation>;\n /**\n * Creation-time options passed to the nearest EditProvider factory.\n * CodeView supplies its item-specific change callback.\n */\n editorOptions?: Omit<EditorOptions<LAnnotation>, 'onChange'>;\n className?: string;\n style?: CSSProperties;\n containerRef?: Ref<HTMLDivElement>;\n disableWorkerPool?: boolean;\n selectedLines?: CodeViewLineSelection | null;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n onScroll?(scrollTop: number, viewer: CodeViewClass<LAnnotation>): void;\n /** Render a non-virtualized node at the very start of the scroll content,\n * before the first item. Always rendered; scrolls with the content. */\n renderCodeViewHeader?(): ReactNode;\n /** Render a non-virtualized node at the very end of the scroll content, after\n * the last item. Always rendered; scrolls with the content. */\n renderCodeViewFooter?(): ReactNode;\n /** Called with the owning item on every edited-document change. */\n onItemEditChange?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ): void;\n /**\n * Called once with the final contents when an item's edit session ends\n * (edit turned off, item removed or collapsed). Not called for sessions\n * that produced no changes. Committing is user-space: make one combined\n * item write carrying the new file/fileDiff (with a fresh `cacheKey`,\n * since the contents changed) along with `edit: false`.\n */\n onItemEditComplete?(\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ): void;\n renderCustomHeader?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderPrefix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderFilenameSuffix?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderHeaderMetadata?(item: CodeViewItem<LAnnotation>): ReactNode;\n renderAnnotation?(\n annotation: LineAnnotation<LAnnotation> | DiffLineAnnotation<LAnnotation>,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n renderGutterUtility?(\n getHoveredLine: CodeViewGutterUtilityGetter,\n item: CodeViewItem<LAnnotation>\n ): ReactNode;\n}\n\nexport interface ControlledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n items: readonly CodeViewItem<LAnnotation>[];\n initialItems?: never;\n}\n\nexport interface UncontrolledCodeViewProps<\n LAnnotation,\n> extends CodeViewBaseProps<LAnnotation> {\n // Seeds the imperative CodeView instance once. Later item changes should go\n // through the ref API instead of being reconciled from React props.\n initialItems?: readonly CodeViewItem<LAnnotation>[];\n items?: never;\n}\n\nexport type CodeViewProps<LAnnotation = undefined> =\n | ControlledCodeViewProps<LAnnotation>\n | UncontrolledCodeViewProps<LAnnotation>;\n\nexport interface CodeViewHandle<LAnnotation> {\n addItems(items: readonly CodeViewItem<LAnnotation>[]): void;\n getItem(id: string): CodeViewItem<LAnnotation> | undefined;\n updateItem(item: CodeViewItem<LAnnotation>): boolean;\n updateItemId(oldId: string, newId: string): boolean;\n scrollTo(target: CodeViewScrollTarget): void;\n setSelectedLines(selection: CodeViewLineSelection | null): void;\n getSelectedLines(): CodeViewLineSelection | null;\n clearSelectedLines(): void;\n getEditor(id: string): DiffsEditor<LAnnotation> | undefined;\n getInstance(): CodeViewClass<LAnnotation> | undefined;\n}\n\ntype CodeViewComponent = <LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation> & {\n ref?: React.Ref<CodeViewHandle<LAnnotation>>;\n }\n) => React.JSX.Element;\n\ntype SlotPortalsComponent = <LAnnotation = undefined>(\n props: SlotPortalsProps<LAnnotation>\n) => React.JSX.Element;\n\ninterface ManagedContentStore<LAnnotation> {\n getSnapshot(): CodeViewSlotSnapshot<LAnnotation> | undefined;\n publish(snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined): void;\n subscribe(listener: () => void): () => void;\n}\n\ninterface CachedDataRef<LAnnotation> {\n instance: CodeViewClass<LAnnotation> | undefined;\n items: readonly CodeViewItem<LAnnotation>[] | undefined;\n controlled: boolean;\n managedOptions: CodeViewOptions<LAnnotation> | undefined;\n disableFlushSync: boolean;\n slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined;\n}\n\nfunction createDefaultCache<LAnnotation>(\n controlled: boolean\n): CachedDataRef<LAnnotation> {\n return {\n instance: undefined,\n items: undefined,\n controlled,\n managedOptions: undefined,\n disableFlushSync: false,\n slotCoordinator: undefined,\n };\n}\n\nfunction CodeViewInner<LAnnotation = undefined>(\n props: CodeViewProps<LAnnotation>,\n ref: React.ForwardedRef<CodeViewHandle<LAnnotation>>\n): React.JSX.Element {\n const {\n className,\n containerRef,\n disableWorkerPool = false,\n editorOptions,\n initialItems,\n items: controlledItems,\n onItemEditChange,\n onItemEditComplete,\n onScroll,\n onSelectedLinesChange,\n options,\n renderAnnotation,\n renderCodeViewFooter,\n renderCodeViewHeader,\n renderCustomHeader,\n renderGutterUtility,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderHeaderPrefix,\n selectedLines,\n style,\n } = props;\n const controlled = controlledItems !== undefined;\n const contextCreateEditor = useCreateEditor<LAnnotation>();\n const poolManager = useContext(WorkerPoolContext);\n const cachedDataRef = useRef<CachedDataRef<LAnnotation>>(\n createDefaultCache<LAnnotation>(controlled)\n );\n const hasCustomHeader = renderCustomHeader != null;\n const hasAnnotationRenderer = renderAnnotation != null;\n const hasGutterRenderer = renderGutterUtility != null;\n const hasHeaderRenderers =\n hasCustomHeader ||\n renderHeaderPrefix != null ||\n renderHeaderFilenameSuffix != null ||\n renderHeaderMetadata != null;\n const hasRenderers =\n hasHeaderRenderers || hasAnnotationRenderer || hasGutterRenderer;\n const hasCodeViewHeader = renderCodeViewHeader != null;\n const hasCodeViewFooter = renderCodeViewFooter != null;\n const emitSelectedLinesChange = useStableCallback(\n (selection: CodeViewLineSelection | null) => {\n onSelectedLinesChange?.(selection);\n }\n );\n const controlledSelection = selectedLines !== undefined;\n\n // Keep the adapter stable so provider and editor-option changes affect the\n // next item edit session without forcing CodeView to reconcile active editors.\n const createEditor = useStableCallback(\n (\n options: CodeViewCreateEditorOptions<LAnnotation>\n ): DiffsEditor<LAnnotation> => {\n if (contextCreateEditor == null) {\n throw new Error('CodeView: EditContext is not attached');\n }\n\n const editor = contextCreateEditor({\n ...editorOptions,\n ...options,\n });\n if (editor == null) {\n throw new Error(\n 'CodeView: EditProvider.createEditor must return an editor instance'\n );\n }\n return editor;\n }\n );\n const emitItemEditChange = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditChange?.(item, file, lineAnnotations);\n }\n );\n const emitItemEditComplete = useStableCallback(\n (\n item: CodeViewItem<LAnnotation>,\n file: FileContents,\n lineAnnotations?:\n | LineAnnotation<LAnnotation>[]\n | DiffLineAnnotation<LAnnotation>[]\n ) => {\n onItemEditComplete?.(item, file, lineAnnotations);\n }\n );\n\n const managedOptions = useMemo(\n () =>\n createManagedCodeViewOptions({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange:\n onSelectedLinesChange != null ? emitSelectedLinesChange : undefined,\n controlledSelection,\n createEditor: contextCreateEditor != null ? createEditor : undefined,\n onItemEditChange:\n onItemEditChange != null ? emitItemEditChange : undefined,\n onItemEditComplete:\n onItemEditComplete != null ? emitItemEditComplete : undefined,\n }),\n [\n contextCreateEditor,\n controlledSelection,\n createEditor,\n emitItemEditChange,\n emitItemEditComplete,\n emitSelectedLinesChange,\n hasCodeViewFooter,\n hasCodeViewHeader,\n hasCustomHeader,\n hasGutterRenderer,\n onItemEditChange,\n onItemEditComplete,\n onSelectedLinesChange,\n options,\n ]\n );\n\n const [slotContentStore] = useState<ManagedContentStore<LAnnotation>>(() =>\n createSlotContentStore()\n );\n const [, forceUpdate] = useState<unknown>({});\n\n const nodeRef = useStableCallback((node: HTMLDivElement | null) => {\n // If we have a pre-existing instance and there's no node or the node being\n // passed in is NOT the same as before, then we need to clean up and\n // garbage collect the old instance\n if (\n cachedDataRef.current.instance != null &&\n (node == null ||\n node !== cachedDataRef.current.instance.getContainerElement())\n ) {\n cachedDataRef.current.instance.cleanUp();\n slotContentStore.publish(undefined);\n cachedDataRef.current = createDefaultCache<LAnnotation>(controlled);\n }\n\n // If our node matches the existing node then we should not attempt to\n // setup. This is a case that should never be possible to hit, but just in\n // case, lets make sure we don't re-setup an instance that is already setup\n // properly\n if (\n node != null &&\n node !== cachedDataRef.current.instance?.getContainerElement()\n ) {\n cachedDataRef.current.instance = new CodeViewClass<LAnnotation>(\n managedOptions,\n !disableWorkerPool ? poolManager : undefined,\n true\n );\n cachedDataRef.current.instance.setup(node);\n }\n\n if (typeof containerRef === 'function') {\n containerRef(node);\n } else if (containerRef != null) {\n containerRef.current = node;\n }\n });\n\n const onSnapshotChange = useStableCallback(\n (snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined) => {\n if (cachedDataRef.current.disableFlushSync) {\n slotContentStore.publish(snapshot);\n } else {\n flushSync(() => {\n slotContentStore.publish(snapshot);\n });\n }\n }\n );\n\n const slotCoordinator: CodeViewCoordinator<LAnnotation> | undefined =\n useMemo(() => {\n // A coordinator is needed whenever React portals anything — per-item\n // slots and codeview header and footer\n if (\n !hasHeaderRenderers &&\n !hasAnnotationRenderer &&\n !hasGutterRenderer &&\n !hasCodeViewHeader &&\n !hasCodeViewFooter\n ) {\n return undefined;\n } else {\n return {\n hasHeaderRenderers,\n hasAnnotationRenderer,\n hasGutterRenderer,\n onSnapshotChange,\n };\n }\n }, [\n onSnapshotChange,\n hasAnnotationRenderer,\n hasGutterRenderer,\n hasHeaderRenderers,\n hasCodeViewHeader,\n hasCodeViewFooter,\n ]);\n\n useIsomorphicLayoutEffect(() => {\n return onScroll != null\n ? cachedDataRef.current.instance?.subscribeToScroll(onScroll)\n : undefined;\n });\n\n useIsomorphicLayoutEffect(() => {\n const {\n instance,\n controlled: prevControlled,\n items: prevItems,\n managedOptions: prevManagedOptions,\n slotCoordinator: prevSlotCoordinator,\n } = cachedDataRef.current;\n if (instance == null) {\n return;\n }\n\n try {\n cachedDataRef.current.disableFlushSync = true;\n let shouldRender = false;\n\n if (!areOptionsEqual(managedOptions, prevManagedOptions)) {\n cachedDataRef.current.managedOptions = managedOptions;\n instance.setOptions(managedOptions);\n shouldRender = true;\n }\n\n if (prevControlled !== controlled) {\n console.error(\n 'CodeView: cannot switch between controlled and uncontrolled modes. Remount with a new key instead.'\n );\n return;\n }\n\n if (controlled) {\n if (controlledItems !== prevItems) {\n if (areItemListsEqual(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n } else if (isAppendOnlyItemUpdate(prevItems, controlledItems)) {\n cachedDataRef.current.items = controlledItems;\n instance.addItems(controlledItems.slice(prevItems.length));\n } else {\n cachedDataRef.current.items = controlledItems;\n instance.setItems(controlledItems);\n shouldRender = true;\n }\n }\n }\n // If uncontrolled, we should only ever set items once, and just depend\n // on imperative instance changes going forward\n else if (prevItems == null) {\n const seedItems = initialItems ?? [];\n cachedDataRef.current.items = seedItems;\n if (seedItems.length > 0) {\n instance.setItems(seedItems);\n shouldRender = true;\n }\n }\n\n if (selectedLines !== undefined) {\n instance.setSelectedLines(selectedLines, { notify: false });\n }\n\n const slotPublish = instance.setSlotCoordinator(slotCoordinator);\n let forceInlinePublish = false;\n if (slotCoordinator !== prevSlotCoordinator) {\n if (slotCoordinator == null || prevSlotCoordinator == null) {\n forceInlinePublish = true;\n }\n cachedDataRef.current.slotCoordinator = slotCoordinator;\n }\n\n if (shouldRender || slotPublish) {\n instance.render(true);\n }\n\n // FIXME(amadeus): This feels kinda bad and flakey with regards to how\n // other things are working... it makes me think that we should\n // re-architect the slotCoordinator a bit, and maybe DON'T make it an\n // undefineable thing...\n if (slotPublish && slotCoordinator == null) {\n slotContentStore.publish(undefined);\n }\n\n if (forceInlinePublish) {\n forceUpdate({});\n }\n } finally {\n cachedDataRef.current.disableFlushSync = false;\n }\n });\n\n // Setup the ref handler\n useImperativeHandle(\n ref,\n (): CodeViewHandle<LAnnotation> => ({\n addItems(items) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'addItems');\n if (instance == null) {\n console.error(\n 'CodeView.addItems: no valid instance to append items with',\n items\n );\n } else {\n instance.addItems(items);\n }\n },\n getItem(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getItem: no valid instance exists', id);\n return undefined;\n } else {\n return instance.getItem(id);\n }\n },\n updateItem(item) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItem');\n if (instance == null) {\n console.error(\n 'CodeView.updateItem: no valid instance to update item with',\n item\n );\n return false;\n }\n\n return instance.updateItem(item);\n },\n updateItemId(oldId, newId) {\n const { controlled, instance } = cachedDataRef.current;\n assertUncontrolledCodeViewAction(controlled, 'updateItemId');\n if (instance == null) {\n console.error(\n 'CodeView.updateItemId: no valid instance to update item id with',\n oldId,\n newId\n );\n return false;\n }\n\n return instance.updateItemId(oldId, newId);\n },\n scrollTo(target) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.scrollTo: no valid instance to scroll with',\n target\n );\n } else {\n instance.scrollTo(target);\n }\n },\n setSelectedLines(selection) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.setSelectedLines: no valid instance to update selection with',\n selection\n );\n } else {\n instance.setSelectedLines(selection, { notify: false });\n emitSelectedLinesChange(selection);\n }\n },\n getSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getSelectedLines: no valid instance exists');\n return null;\n } else {\n return instance.getSelectedLines();\n }\n },\n clearSelectedLines() {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error(\n 'CodeView.clearSelectedLines: no valid instance to update selection with'\n );\n } else {\n instance.clearSelectedLines({ notify: false });\n emitSelectedLinesChange(null);\n }\n },\n getEditor(id) {\n const { instance } = cachedDataRef.current;\n if (instance == null) {\n console.error('CodeView.getEditor: no valid instance exists', id);\n return undefined;\n }\n\n return instance.getEditor(id);\n },\n getInstance() {\n return cachedDataRef.current.instance;\n },\n }),\n [emitSelectedLinesChange]\n );\n\n return (\n <>\n <div ref={nodeRef} className={className} style={style} />\n {(hasRenderers || hasCodeViewHeader || hasCodeViewFooter) && (\n <SlotPortals<LAnnotation>\n managedContentStore={slotContentStore}\n renderCustomHeader={renderCustomHeader}\n renderHeaderPrefix={renderHeaderPrefix}\n renderHeaderFilenameSuffix={renderHeaderFilenameSuffix}\n renderHeaderMetadata={renderHeaderMetadata}\n renderAnnotation={renderAnnotation}\n renderGutterUtility={renderGutterUtility}\n renderCodeViewHeader={renderCodeViewHeader}\n renderCodeViewFooter={renderCodeViewFooter}\n />\n )}\n </>\n );\n}\n\n// React was a mistake\nexport const CodeView = forwardRef(CodeViewInner) as CodeViewComponent;\n\nfunction isAppendOnlyItemUpdate<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): previousItems is readonly CodeViewItem<LAnnotation>[] {\n if (previousItems == null || nextItems.length <= previousItems.length) {\n return false;\n }\n\n if (previousItems.length === 0) {\n return true;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (nextItems[index] !== previousItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction areItemListsEqual<LAnnotation>(\n previousItems: readonly CodeViewItem<LAnnotation>[] | undefined,\n nextItems: readonly CodeViewItem<LAnnotation>[]\n): boolean {\n if (previousItems == null || previousItems.length !== nextItems.length) {\n return false;\n }\n\n for (let index = 0; index < previousItems.length; index++) {\n if (previousItems[index] !== nextItems[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nfunction assertUncontrolledCodeViewAction(\n controlled: boolean,\n action: string\n): void {\n if (!controlled) {\n return;\n }\n\n throw new Error(\n `CodeView.${action} cannot be used when CodeView is controlled. Use initialItems for imperative item updates.`\n );\n}\n\nfunction createSlotContentStore<\n LAnnotation,\n>(): ManagedContentStore<LAnnotation> {\n let snapshot: CodeViewSlotSnapshot<LAnnotation> | undefined;\n const listeners = new Set<() => void>();\n\n return {\n getSnapshot() {\n return snapshot;\n },\n publish(nextSnapshot) {\n if (areManagedSnapshotsEqual(snapshot, nextSnapshot)) {\n return;\n }\n\n snapshot = nextSnapshot;\n for (const listener of listeners) {\n listener();\n }\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n\ninterface CreateManagedCodeViewOptionsProps<LAnnotation> {\n options: CodeViewReactOptions<LAnnotation> | undefined;\n hasCustomHeader: boolean;\n hasGutterRenderer: boolean;\n hasCodeViewHeader: boolean;\n hasCodeViewFooter: boolean;\n onSelectedLinesChange?(selection: CodeViewLineSelection | null): void;\n controlledSelection: boolean;\n createEditor: CodeViewOptions<LAnnotation>['createEditor'];\n onItemEditChange: CodeViewOptions<LAnnotation>['onItemEditChange'];\n onItemEditComplete: CodeViewOptions<LAnnotation>['onItemEditComplete'];\n}\n\nfunction createManagedCodeViewOptions<LAnnotation>({\n options,\n hasCustomHeader,\n hasGutterRenderer,\n hasCodeViewHeader,\n hasCodeViewFooter,\n onSelectedLinesChange,\n controlledSelection,\n createEditor,\n onItemEditChange,\n onItemEditComplete,\n}: CreateManagedCodeViewOptionsProps<LAnnotation>): CodeViewOptions<LAnnotation> {\n const managedOptions: CodeViewOptions<LAnnotation> = {\n ...options,\n controlledSelection,\n onSelectedLinesChange,\n createEditor,\n };\n\n // Prop-level editor callbacks win over their options-object counterparts,\n // but an absent prop must not clobber a value provided via `options`.\n if (onItemEditChange != null) {\n managedOptions.onItemEditChange = onItemEditChange;\n }\n if (onItemEditComplete != null) {\n managedOptions.onItemEditComplete = onItemEditComplete;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // switch file and diff headers into custom-slot mode. React portals\n // provide the actual header content, so this placeholder\n // intentionally returns nothing.\n if (hasCustomHeader) {\n managedOptions.renderCustomHeader = noopRender;\n }\n\n // The imperative CodeView adapters use this callback's presence to\n // create the custom gutter utility slot. React portals provide the\n // actual content, so this placeholder intentionally returns nothing.\n if (hasGutterRenderer) {\n managedOptions.renderGutterUtility = noopRender;\n }\n\n // The imperative CodeView adapters use these callbacks' presence to create the\n // header/footer host elements. React portals the actual content into them (via\n // the slot snapshot), so these placeholders intentionally return nothing.\n if (hasCodeViewHeader) {\n managedOptions.renderCodeViewHeader = noopRender;\n }\n if (hasCodeViewFooter) {\n managedOptions.renderCodeViewFooter = noopRender;\n }\n\n return managedOptions;\n}\n\ninterface RenderCodeViewItemChildrenProps<LAnnotation> {\n renderedItem: CodeViewRenderedItem<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n}\n\ninterface SlotPortalsProps<LAnnotation> {\n managedContentStore: ManagedContentStore<LAnnotation>;\n renderCustomHeader: CodeViewBaseProps<LAnnotation>['renderCustomHeader'];\n renderHeaderPrefix: CodeViewBaseProps<LAnnotation>['renderHeaderPrefix'];\n renderHeaderFilenameSuffix: CodeViewBaseProps<LAnnotation>['renderHeaderFilenameSuffix'];\n renderHeaderMetadata: CodeViewBaseProps<LAnnotation>['renderHeaderMetadata'];\n renderAnnotation: CodeViewBaseProps<LAnnotation>['renderAnnotation'];\n renderGutterUtility: CodeViewBaseProps<LAnnotation>['renderGutterUtility'];\n renderCodeViewHeader: CodeViewBaseProps<LAnnotation>['renderCodeViewHeader'];\n renderCodeViewFooter: CodeViewBaseProps<LAnnotation>['renderCodeViewFooter'];\n}\n\nconst SlotPortals = memo(function SlotPortals<LAnnotation>({\n managedContentStore,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n renderCodeViewHeader,\n renderCodeViewFooter,\n}: SlotPortalsProps<LAnnotation>) {\n 'use no memo';\n const subscribe = useStableCallback((listener: () => void) =>\n managedContentStore.subscribe(listener)\n );\n const getSnapshot = useStableCallback(() =>\n managedContentStore.getSnapshot()\n );\n const snapshot = useSyncExternalStore<\n CodeViewSlotSnapshot<LAnnotation> | undefined\n >(subscribe, getSnapshot, getSnapshot);\n let itemKeys = '';\n for (const item of snapshot?.items ?? []) {\n itemKeys += `${item.id}:${item.version}:${item.type}`;\n }\n // NOTE(amadeus): And just like that, the react compiler do be failing us\n // lol... we need to pre-render everything for items, headers and footers to\n // not trigger needless renders while scrolling\n const renderedItems = useMemo(\n () => {\n return snapshot?.items?.map((renderedItem) =>\n createPortal(\n renderCodeViewItemChildren({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n }),\n renderedItem.element,\n renderedItem.id\n )\n );\n },\n // oxlint-disable-next-line react-hooks/exhaustive-deps\n [\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n itemKeys,\n ]\n );\n const renderedHeader = useMemo(() => {\n return renderCodeViewHeader != null && snapshot?.header != null\n ? createPortal(renderCodeViewHeader(), snapshot.header)\n : null;\n }, [renderCodeViewHeader, snapshot?.header]);\n const renderedFooter = useMemo(() => {\n return renderCodeViewFooter != null && snapshot?.footer != null\n ? createPortal(renderCodeViewFooter(), snapshot.footer)\n : null;\n }, [renderCodeViewFooter, snapshot?.footer]);\n return (\n <>\n {renderedItems}\n {renderedHeader}\n {renderedFooter}\n </>\n );\n}) as SlotPortalsComponent;\n\nfunction renderCodeViewItemChildren<LAnnotation>({\n renderedItem,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderAnnotation,\n renderGutterUtility,\n}: RenderCodeViewItemChildrenProps<LAnnotation>): ReactNode {\n if (renderedItem.type === 'diff') {\n const { item, instance } = renderedItem;\n return renderDiffChildren({\n fileDiff: item.fileDiff,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n } else {\n const { item, instance } = renderedItem;\n return renderFileChildren({\n file: item.file,\n renderCustomHeader:\n renderCustomHeader != null ? () => renderCustomHeader(item) : undefined,\n renderHeaderPrefix:\n renderHeaderPrefix != null ? () => renderHeaderPrefix(item) : undefined,\n renderHeaderFilenameSuffix:\n renderHeaderFilenameSuffix != null\n ? () => renderHeaderFilenameSuffix(item)\n : undefined,\n renderHeaderMetadata:\n renderHeaderMetadata != null\n ? () => renderHeaderMetadata(item)\n : undefined,\n renderAnnotation:\n renderAnnotation != null\n ? (annotation) => renderAnnotation(annotation, item)\n : undefined,\n lineAnnotations: item.annotations,\n renderGutterUtility:\n renderGutterUtility != null\n ? (getHoveredLine) => renderGutterUtility(getHoveredLine, item)\n : undefined,\n getHoveredLine: instance.getHoveredLine,\n });\n }\n}\n\nfunction noopRender() {\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;AA4CA,MAAM,4BACJ,OAAO,WAAW,cAAc,YAAY;AA6H9C,SAAS,mBACP,YAC4B;CAC5B,OAAO;EACL,UAAU,KAAA;EACV,OAAO,KAAA;EACP;EACA,gBAAgB,KAAA;EAChB,kBAAkB;EAClB,iBAAiB,KAAA;CACnB;AACF;AAEA,SAAS,cACP,OACA,KACmB;CACnB,MAAM,EACJ,WACA,cACA,oBAAoB,OACpB,eACA,cACA,OAAO,iBACP,kBACA,oBACA,UACA,uBACA,SACA,kBACA,sBACA,sBACA,oBACA,qBACA,4BACA,sBACA,oBACA,eACA,UACE;CACJ,MAAM,aAAa,oBAAoB,KAAA;CACvC,MAAM,sBAAsB,gBAA6B;CACzD,MAAM,cAAc,WAAW,iBAAiB;CAChD,MAAM,gBAAgB,OACpB,mBAAgC,UAAU,CAC5C;CACA,MAAM,kBAAkB,sBAAsB;CAC9C,MAAM,wBAAwB,oBAAoB;CAClD,MAAM,oBAAoB,uBAAuB;CACjD,MAAM,qBACJ,mBACA,sBAAsB,QACtB,8BAA8B,QAC9B,wBAAwB;CAC1B,MAAM,eACJ,sBAAsB,yBAAyB;CACjD,MAAM,oBAAoB,wBAAwB;CAClD,MAAM,oBAAoB,wBAAwB;CAClD,MAAM,0BAA0B,mBAC7B,cAA4C;EAC3C,wBAAwB,SAAS;CACnC,CACF;CACA,MAAM,sBAAsB,kBAAkB,KAAA;CAI9C,MAAM,eAAe,mBAEjB,YAC6B;EAC7B,IAAI,uBAAuB,MACzB,MAAM,IAAI,MAAM,uCAAuC;EAGzD,MAAM,SAAS,oBAAoB;GACjC,GAAG;GACH,GAAG;EACL,CAAC;EACD,IAAI,UAAU,MACZ,MAAM,IAAI,MACR,oEACF;EAEF,OAAO;CACT,CACF;CACA,MAAM,qBAAqB,mBAEvB,MACA,MACA,oBAGG;EACH,mBAAmB,MAAM,MAAM,eAAe;CAChD,CACF;CACA,MAA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B,IAAI,IAAI,KAAA;GAChE,4BACE,8BAA8B,aACpB,2BAA2B,IAAI,IACrC,KAAA;GACN,sBACE,wBAAwB,aACd,qBAAqB,IAAI,IAC/B,KAAA;GACN,kBACE,oBAAoB,QACf,eAAe,iBAAiB,YAAY,IAAI,IACjD,KAAA;GACN,iBAAiB,KAAK;GACtB,qBACE,uBAAuB,QAClB,mBAAmB,oBAAoB,gBAAgB,IAAI,IAC5D,KAAA;GACN,gBAAgB,SAAS;EAC3B,CAAC;CACH;AACF;AAEA,SAAS,aAAa,CAEtB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DiffsEditor } from "../types.js";
|
|
2
|
+
import { EditorOptions } from "../editor/editor.js";
|
|
3
|
+
import { Context, PropsWithChildren } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/react/EditContext.d.ts
|
|
6
|
+
/** Creates an Editor. Components manage the instance lifecycle. */
|
|
7
|
+
type CreateEditor<LAnnotation> = (options: EditorOptions<LAnnotation>) => DiffsEditor<LAnnotation>;
|
|
8
|
+
interface EditProviderProps<LAnnotation> {
|
|
9
|
+
/** Combines shared defaults with the supplied per-surface options. */
|
|
10
|
+
createEditor: CreateEditor<LAnnotation>;
|
|
11
|
+
}
|
|
12
|
+
declare const EditContext: Context<CreateEditor<any> | undefined>;
|
|
13
|
+
declare function EditProvider<LAnnotation>({
|
|
14
|
+
children,
|
|
15
|
+
createEditor
|
|
16
|
+
}: PropsWithChildren<EditProviderProps<LAnnotation>>): React.JSX.Element;
|
|
17
|
+
declare function useCreateEditor<LAnnotation>(): CreateEditor<LAnnotation> | undefined;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { CreateEditor, EditContext, EditProvider, EditProviderProps, useCreateEditor };
|
|
20
|
+
//# sourceMappingURL=EditContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditContext.d.ts","names":[],"sources":["../../src/react/EditContext.tsx"],"mappings":";;;;;;KAWY,YAAA,iBACV,OAAA,EAAS,aAAA,CAAc,WAAA,MACpB,WAAA,CAAY,WAAA;AAAA,UAEA,iBAAA;EAJL;EAMV,YAAA,EAAc,YAAY,CAAC,WAAA;AAAA;AAAA,cAGhB,WAAA,EAAa,OAAO,CAAC,YAAA;AAAA,iBAGlB,YAAA;EACd,QAAA;EACA;AAAA,GACC,iBAAA,CAAkB,iBAAA,CAAkB,WAAA,KAAgB,KAAA,CAAM,GAAA,CAAI,OAAA;AAAA,iBASjD,eAAA,iBACZ,YAAY,CAAC,WAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useStableCallback } from "./utils/useStableCallback.js";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
//#region src/react/EditContext.tsx
|
|
6
|
+
const EditContext = createContext(void 0);
|
|
7
|
+
function EditProvider({ children, createEditor }) {
|
|
8
|
+
const stableCreateEditor = useStableCallback(createEditor);
|
|
9
|
+
return /* @__PURE__ */ jsx(EditContext.Provider, {
|
|
10
|
+
value: stableCreateEditor,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function useCreateEditor() {
|
|
15
|
+
return useContext(EditContext);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { EditContext, EditProvider, useCreateEditor };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=EditContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditContext.js","names":[],"sources":["../../src/react/EditContext.tsx"],"sourcesContent":["// oxlint-disable typescript/no-explicit-any\n'use client';\n\nimport type { Context, PropsWithChildren } from 'react';\nimport { createContext, useContext } from 'react';\n\nimport type { EditorOptions } from '../edit';\nimport type { DiffsEditor } from '../types';\nimport { useStableCallback } from './utils/useStableCallback';\n\n/** Creates an Editor. Components manage the instance lifecycle. */\nexport type CreateEditor<LAnnotation> = (\n options: EditorOptions<LAnnotation>\n) => DiffsEditor<LAnnotation>;\n\nexport interface EditProviderProps<LAnnotation> {\n /** Combines shared defaults with the supplied per-surface options. */\n createEditor: CreateEditor<LAnnotation>;\n}\n\nexport const EditContext: Context<CreateEditor<any> | undefined> =\n createContext<CreateEditor<any> | undefined>(undefined);\n\nexport function EditProvider<LAnnotation>({\n children,\n createEditor,\n}: PropsWithChildren<EditProviderProps<LAnnotation>>): React.JSX.Element {\n const stableCreateEditor = useStableCallback(createEditor);\n return (\n <EditContext.Provider value={stableCreateEditor}>\n {children}\n </EditContext.Provider>\n );\n}\n\nexport function useCreateEditor<LAnnotation>():\n | CreateEditor<LAnnotation>\n | undefined {\n return useContext(EditContext);\n}\n"],"mappings":";;;;;AAoBA,MAAa,cACX,cAA6C,KAAA,CAAS;AAExD,SAAgB,aAA0B,EACxC,UACA,gBACuE;CACvE,MAAM,qBAAqB,kBAAkB,YAAY;CACzD,OACE,oBAAC,YAAY,UAAb;EAAsB,OAAO;EAC1B;CACmB,CAAA;AAE1B;AAEA,SAAgB,kBAEF;CACZ,OAAO,WAAW,WAAW;AAC/B"}
|
package/dist/react/File.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ declare function File<LAnnotation = undefined>({
|
|
|
7
7
|
lineAnnotations,
|
|
8
8
|
selectedLines,
|
|
9
9
|
options,
|
|
10
|
+
editorOptions,
|
|
10
11
|
metrics,
|
|
11
12
|
className,
|
|
12
13
|
style,
|
|
@@ -18,7 +19,7 @@ declare function File<LAnnotation = undefined>({
|
|
|
18
19
|
prerenderedHTML,
|
|
19
20
|
renderGutterUtility,
|
|
20
21
|
disableWorkerPool,
|
|
21
|
-
|
|
22
|
+
edit
|
|
22
23
|
}: FileProps<LAnnotation>): React.JSX.Element;
|
|
23
24
|
//#endregion
|
|
24
25
|
export { File, type FileOptions };
|
package/dist/react/File.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.d.ts","names":[],"sources":["../../src/react/File.tsx"],"mappings":";;;;iBAWgB,IAAA;EACd,IAAA;EACA,eAAA;EACA,aAAA;EACA,OAAA;EACA,OAAA;EACA,SAAA;EACA,KAAA;EACA,gBAAA;EACA,kBAAA;EACA,kBAAA;EACA,0BAAA;EACA,oBAAA;EACA,eAAA;EACA,mBAAA;EACA,iBAAA;EACA;AAAA,GACC,SAAA,CAAU,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,OAAA"}
|
|
1
|
+
{"version":3,"file":"File.d.ts","names":[],"sources":["../../src/react/File.tsx"],"mappings":";;;;iBAWgB,IAAA;EACd,IAAA;EACA,eAAA;EACA,aAAA;EACA,OAAA;EACA,aAAA;EACA,OAAA;EACA,SAAA;EACA,KAAA;EACA,gBAAA;EACA,kBAAA;EACA,kBAAA;EACA,0BAAA;EACA,oBAAA;EACA,eAAA;EACA,mBAAA;EACA,iBAAA;EACA;AAAA,GACC,SAAA,CAAU,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,OAAA"}
|
package/dist/react/File.js
CHANGED
|
@@ -5,10 +5,11 @@ import { templateRender } from "./utils/templateRender.js";
|
|
|
5
5
|
import { useFileInstance } from "./utils/useFileInstance.js";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/react/File.tsx
|
|
8
|
-
function File({ file, lineAnnotations, selectedLines, options, metrics, className, style, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, prerenderedHTML, renderGutterUtility, disableWorkerPool = false,
|
|
8
|
+
function File({ file, lineAnnotations, selectedLines, options, editorOptions, metrics, className, style, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, prerenderedHTML, renderGutterUtility, disableWorkerPool = false, edit = false }) {
|
|
9
9
|
const { ref, getHoveredLine } = useFileInstance({
|
|
10
10
|
file,
|
|
11
11
|
options,
|
|
12
|
+
editorOptions,
|
|
12
13
|
metrics,
|
|
13
14
|
lineAnnotations,
|
|
14
15
|
selectedLines,
|
|
@@ -16,7 +17,7 @@ function File({ file, lineAnnotations, selectedLines, options, metrics, classNam
|
|
|
16
17
|
hasGutterRenderUtility: renderGutterUtility != null,
|
|
17
18
|
hasCustomHeader: renderCustomHeader != null,
|
|
18
19
|
disableWorkerPool,
|
|
19
|
-
|
|
20
|
+
edit
|
|
20
21
|
});
|
|
21
22
|
return /* @__PURE__ */ jsx(DIFFS_TAG_NAME, {
|
|
22
23
|
ref,
|
package/dist/react/File.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"File.js","names":[],"sources":["../../src/react/File.tsx"],"sourcesContent":["'use client';\n\nimport { type FileOptions } from '../components/File';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileProps } from './types';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileInstance } from './utils/useFileInstance';\n\nexport type { FileOptions };\n\nexport function File<LAnnotation = undefined>({\n file,\n lineAnnotations,\n selectedLines,\n options,\n metrics,\n className,\n style,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n prerenderedHTML,\n renderGutterUtility,\n disableWorkerPool = false,\n
|
|
1
|
+
{"version":3,"file":"File.js","names":[],"sources":["../../src/react/File.tsx"],"sourcesContent":["'use client';\n\nimport { type FileOptions } from '../components/File';\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileProps } from './types';\nimport { renderFileChildren } from './utils/renderFileChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileInstance } from './utils/useFileInstance';\n\nexport type { FileOptions };\n\nexport function File<LAnnotation = undefined>({\n file,\n lineAnnotations,\n selectedLines,\n options,\n editorOptions,\n metrics,\n className,\n style,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n prerenderedHTML,\n renderGutterUtility,\n disableWorkerPool = false,\n edit = false,\n}: FileProps<LAnnotation>): React.JSX.Element {\n const { ref, getHoveredLine } = useFileInstance({\n file,\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 = renderFileChildren({\n file,\n renderAnnotation,\n renderCustomHeader,\n renderHeaderPrefix,\n renderHeaderFilenameSuffix,\n renderHeaderMetadata,\n renderGutterUtility,\n lineAnnotations,\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":";;;;;;;AAWA,SAAgB,KAA8B,EAC5C,MACA,iBACA,eACA,SACA,eACA,SACA,WACA,OACA,kBACA,oBACA,oBACA,4BACA,sBACA,iBACA,qBACA,oBAAoB,OACpB,OAAO,SACqC;CAC5C,MAAM,EAAE,KAAK,mBAAmB,gBAAgB;EAC9C;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"}
|
package/dist/react/FileDiff.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ import { DiffBasePropsReact } from "./types.js";
|
|
|
5
5
|
interface FileDiffProps<LAnnotation> extends DiffBasePropsReact<LAnnotation> {
|
|
6
6
|
fileDiff: FileDiffMetadata;
|
|
7
7
|
disableWorkerPool?: boolean;
|
|
8
|
-
contentEditable?: boolean;
|
|
9
8
|
}
|
|
10
9
|
declare function FileDiff<LAnnotation = undefined>({
|
|
11
10
|
fileDiff,
|
|
12
11
|
options,
|
|
12
|
+
editorOptions,
|
|
13
13
|
metrics,
|
|
14
14
|
lineAnnotations,
|
|
15
15
|
selectedLines,
|
|
@@ -23,7 +23,7 @@ declare function FileDiff<LAnnotation = undefined>({
|
|
|
23
23
|
renderHeaderMetadata,
|
|
24
24
|
renderGutterUtility,
|
|
25
25
|
disableWorkerPool,
|
|
26
|
-
|
|
26
|
+
edit
|
|
27
27
|
}: FileDiffProps<LAnnotation>): React.JSX.Element;
|
|
28
28
|
//#endregion
|
|
29
29
|
export { FileDiff, type FileDiffMetadata, FileDiffProps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDiff.d.ts","names":[],"sources":["../../src/react/FileDiff.tsx"],"mappings":";;;;UAWiB,aAAA,sBAEP,kBAAA,CAAmB,WAAA;EAC3B,QAAA,EAAU,gBAAA;EACV,iBAAA;
|
|
1
|
+
{"version":3,"file":"FileDiff.d.ts","names":[],"sources":["../../src/react/FileDiff.tsx"],"mappings":";;;;UAWiB,aAAA,sBAEP,kBAAA,CAAmB,WAAA;EAC3B,QAAA,EAAU,gBAAA;EACV,iBAAA;AAAA;AAAA,iBAGc,QAAA;EACd,QAAA;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,aAAA,CAAc,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,OAAA"}
|
package/dist/react/FileDiff.js
CHANGED
|
@@ -5,10 +5,11 @@ import { templateRender } from "./utils/templateRender.js";
|
|
|
5
5
|
import { useFileDiffInstance } from "./utils/useFileDiffInstance.js";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
7
7
|
//#region src/react/FileDiff.tsx
|
|
8
|
-
function FileDiff({ fileDiff, options, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false,
|
|
8
|
+
function FileDiff({ fileDiff, options, editorOptions, metrics, lineAnnotations, selectedLines, className, style, prerenderedHTML, renderAnnotation, renderCustomHeader, renderHeaderPrefix, renderHeaderFilenameSuffix, renderHeaderMetadata, renderGutterUtility, disableWorkerPool = false, edit = false }) {
|
|
9
9
|
const { ref, getHoveredLine } = useFileDiffInstance({
|
|
10
10
|
fileDiff,
|
|
11
11
|
options,
|
|
12
|
+
editorOptions,
|
|
12
13
|
metrics,
|
|
13
14
|
lineAnnotations,
|
|
14
15
|
selectedLines,
|
|
@@ -16,7 +17,7 @@ function FileDiff({ fileDiff, options, metrics, lineAnnotations, selectedLines,
|
|
|
16
17
|
hasGutterRenderUtility: renderGutterUtility != null,
|
|
17
18
|
hasCustomHeader: renderCustomHeader != null,
|
|
18
19
|
disableWorkerPool,
|
|
19
|
-
|
|
20
|
+
edit
|
|
20
21
|
});
|
|
21
22
|
return /* @__PURE__ */ jsx(DIFFS_TAG_NAME, {
|
|
22
23
|
ref,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDiff.js","names":[],"sources":["../../src/react/FileDiff.tsx"],"sourcesContent":["'use client';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport type { FileDiffMetadata };\n\nexport interface FileDiffProps<\n LAnnotation,\n> extends DiffBasePropsReact<LAnnotation> {\n fileDiff: FileDiffMetadata;\n disableWorkerPool?: boolean;\n
|
|
1
|
+
{"version":3,"file":"FileDiff.js","names":[],"sources":["../../src/react/FileDiff.tsx"],"sourcesContent":["'use client';\n\nimport { DIFFS_TAG_NAME } from '../constants';\nimport type { FileDiffMetadata } from '../types';\nimport type { DiffBasePropsReact } from './types';\nimport { renderDiffChildren } from './utils/renderDiffChildren';\nimport { templateRender } from './utils/templateRender';\nimport { useFileDiffInstance } from './utils/useFileDiffInstance';\n\nexport type { FileDiffMetadata };\n\nexport interface FileDiffProps<\n LAnnotation,\n> extends DiffBasePropsReact<LAnnotation> {\n fileDiff: FileDiffMetadata;\n disableWorkerPool?: boolean;\n}\n\nexport function FileDiff<LAnnotation = undefined>({\n fileDiff,\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}: FileDiffProps<LAnnotation>): React.JSX.Element {\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 renderGutterUtility,\n lineAnnotations,\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":";;;;;;;AAkBA,SAAgB,SAAkC,EAChD,UACA,SACA,eACA,SACA,iBACA,eACA,WACA,OACA,iBACA,kBACA,oBACA,oBACA,4BACA,sBACA,qBACA,oBAAoB,OACpB,OAAO,SACyC;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,13 +4,13 @@ import { DiffBasePropsReact } from "./types.js";
|
|
|
4
4
|
//#region src/react/MultiFileDiff.d.ts
|
|
5
5
|
interface MultiFileDiffBaseProps<LAnnotation> extends DiffBasePropsReact<LAnnotation> {
|
|
6
6
|
disableWorkerPool?: boolean;
|
|
7
|
-
contentEditable?: boolean;
|
|
8
7
|
}
|
|
9
8
|
type MultiFileDiffProps<LAnnotation> = MultiFileDiffBaseProps<LAnnotation> & DiffFileInput;
|
|
10
9
|
declare function MultiFileDiff<LAnnotation = undefined>({
|
|
11
10
|
oldFile,
|
|
12
11
|
newFile,
|
|
13
12
|
options,
|
|
13
|
+
editorOptions,
|
|
14
14
|
metrics,
|
|
15
15
|
lineAnnotations,
|
|
16
16
|
selectedLines,
|
|
@@ -24,7 +24,7 @@ declare function MultiFileDiff<LAnnotation = undefined>({
|
|
|
24
24
|
renderHeaderMetadata,
|
|
25
25
|
renderGutterUtility,
|
|
26
26
|
disableWorkerPool,
|
|
27
|
-
|
|
27
|
+
edit
|
|
28
28
|
}: MultiFileDiffProps<LAnnotation>): React.JSX.Element;
|
|
29
29
|
//#endregion
|
|
30
30
|
export { type FileContents, MultiFileDiff, MultiFileDiffProps };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiFileDiff.d.ts","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"mappings":";;;;UAcU,sBAAA,sBAEA,kBAAkB,CAAC,WAAA;EAC3B,iBAAA;
|
|
1
|
+
{"version":3,"file":"MultiFileDiff.d.ts","names":[],"sources":["../../src/react/MultiFileDiff.tsx"],"mappings":";;;;UAcU,sBAAA,sBAEA,kBAAkB,CAAC,WAAA;EAC3B,iBAAA;AAAA;AAAA,KAGU,kBAAA,gBACV,sBAAA,CAAuB,WAAA,IAAe,aAAA;AAAA,iBAExB,aAAA;EACd,OAAA;EACA,OAAA;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,kBAAA,CAAmB,WAAA,IAAe,KAAA,CAAM,GAAA,CAAI,OAAA"}
|
|
@@ -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"}
|