@pierre/diffs 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CodeView.d.ts +22 -7
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +202 -105
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +2 -0
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +13 -9
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +2 -0
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +12 -6
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.d.ts +4 -2
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +23 -6
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +9 -8
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +329 -142
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/react/index.d.ts +2 -2
- package/dist/renderers/DiffHunksRenderer.d.ts +1 -0
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +19 -9
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +1 -0
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +12 -6
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/types.d.ts +7 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.d.ts +28 -0
- package/dist/utils/computeEstimatedDiffHeights.d.ts.map +1 -0
- package/dist/utils/computeEstimatedDiffHeights.js +111 -0
- package/dist/utils/computeEstimatedDiffHeights.js.map +1 -0
- package/dist/utils/getDiffHunksRendererOptions.d.ts +8 -0
- package/dist/utils/getDiffHunksRendererOptions.d.ts.map +1 -0
- package/dist/utils/getDiffHunksRendererOptions.js +31 -0
- package/dist/utils/getDiffHunksRendererOptions.js.map +1 -0
- package/dist/utils/getFileRendererOptions.d.ts +8 -0
- package/dist/utils/getFileRendererOptions.d.ts.map +1 -0
- package/dist/utils/getFileRendererOptions.js +24 -0
- package/dist/utils/getFileRendererOptions.js.map +1 -0
- package/dist/utils/iterateOverDiff.js +29 -30
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/parsePatchFiles.js +8 -1
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/virtualDiffLayout.d.ts +65 -0
- package/dist/utils/virtualDiffLayout.d.ts.map +1 -0
- package/dist/utils/virtualDiffLayout.js +94 -0
- package/dist/utils/virtualDiffLayout.js.map +1 -0
- package/dist/worker/WorkerPoolManager.d.ts +4 -1
- package/dist/worker/WorkerPoolManager.d.ts.map +1 -1
- package/dist/worker/WorkerPoolManager.js +49 -24
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/types.d.ts +2 -0
- package/dist/worker/types.d.ts.map +1 -1
- package/dist/worker/worker-portable.js +163 -40
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +60 -30
- package/dist/worker/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/worker/worker.js
CHANGED
|
@@ -710,6 +710,38 @@ function getLineNodes(nodes) {
|
|
|
710
710
|
throw new Error("getLineNodes: Unable to find children");
|
|
711
711
|
}
|
|
712
712
|
|
|
713
|
+
//#endregion
|
|
714
|
+
//#region src/utils/virtualDiffLayout.ts
|
|
715
|
+
function getExpandedRegion({ isPartial, rangeSize, expandedHunks, hunkIndex, collapsedContextThreshold }) {
|
|
716
|
+
const normalizedRangeSize = Math.max(rangeSize, 0);
|
|
717
|
+
if (normalizedRangeSize === 0 || isPartial) return {
|
|
718
|
+
fromStart: 0,
|
|
719
|
+
fromEnd: 0,
|
|
720
|
+
rangeSize: normalizedRangeSize,
|
|
721
|
+
collapsedLines: normalizedRangeSize,
|
|
722
|
+
renderAll: false
|
|
723
|
+
};
|
|
724
|
+
if (expandedHunks === true || normalizedRangeSize <= collapsedContextThreshold) return {
|
|
725
|
+
fromStart: normalizedRangeSize,
|
|
726
|
+
fromEnd: 0,
|
|
727
|
+
rangeSize: normalizedRangeSize,
|
|
728
|
+
collapsedLines: 0,
|
|
729
|
+
renderAll: true
|
|
730
|
+
};
|
|
731
|
+
const region = expandedHunks?.get(hunkIndex);
|
|
732
|
+
const fromStart = Math.min(Math.max(region?.fromStart ?? 0, 0), normalizedRangeSize);
|
|
733
|
+
const fromEnd = Math.min(Math.max(region?.fromEnd ?? 0, 0), normalizedRangeSize);
|
|
734
|
+
const expandedCount = fromStart + fromEnd;
|
|
735
|
+
const renderAll = expandedCount >= normalizedRangeSize;
|
|
736
|
+
return {
|
|
737
|
+
fromStart: renderAll ? normalizedRangeSize : fromStart,
|
|
738
|
+
fromEnd: renderAll ? 0 : fromEnd,
|
|
739
|
+
rangeSize: normalizedRangeSize,
|
|
740
|
+
collapsedLines: Math.max(normalizedRangeSize - expandedCount, 0),
|
|
741
|
+
renderAll
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
|
|
713
745
|
//#endregion
|
|
714
746
|
//#region src/utils/iterateOverDiff.ts
|
|
715
747
|
function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infinity, expandedHunks, collapsedContextThreshold = DEFAULT_COLLAPSED_CONTEXT_THRESHOLD, callback }) {
|
|
@@ -772,14 +804,26 @@ function iterateOverDiff({ diff, diffStyle, startingLine = 0, totalLines = Infin
|
|
|
772
804
|
const hunk = diff.hunks[hunkIndex];
|
|
773
805
|
if (hunk == null) throw new Error("iterateOverDiff: invalid hunk index");
|
|
774
806
|
if (state.shouldBreak()) break;
|
|
775
|
-
const leadingRegion = getExpandedRegion(
|
|
807
|
+
const leadingRegion = getExpandedRegion({
|
|
808
|
+
isPartial: diff.isPartial,
|
|
809
|
+
rangeSize: hunk.collapsedBefore,
|
|
810
|
+
expandedHunks,
|
|
811
|
+
hunkIndex,
|
|
812
|
+
collapsedContextThreshold
|
|
813
|
+
});
|
|
776
814
|
const trailingRegion = (() => {
|
|
777
815
|
if (hunk !== state.finalHunk || !hasFinalCollapsedHunk(diff)) return;
|
|
778
816
|
const additionRemaining = diff.additionLines.length - (hunk.additionLineIndex + hunk.additionCount);
|
|
779
817
|
const deletionRemaining = diff.deletionLines.length - (hunk.deletionLineIndex + hunk.deletionCount);
|
|
780
818
|
if (additionRemaining !== deletionRemaining) throw new Error(`iterateOverDiff: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${diff.name}`);
|
|
781
819
|
const trailingRangeSize = Math.min(additionRemaining, deletionRemaining);
|
|
782
|
-
return getExpandedRegion(
|
|
820
|
+
return getExpandedRegion({
|
|
821
|
+
isPartial: diff.isPartial,
|
|
822
|
+
rangeSize: trailingRangeSize,
|
|
823
|
+
expandedHunks,
|
|
824
|
+
hunkIndex: diff.hunks.length,
|
|
825
|
+
collapsedContextThreshold
|
|
826
|
+
});
|
|
783
827
|
})();
|
|
784
828
|
const expandedLineCount = leadingRegion.fromStart + leadingRegion.fromEnd;
|
|
785
829
|
function getTrailingCollapsedAfter(unifiedLineIndex$1, splitLineIndex$1) {
|
|
@@ -1063,13 +1107,25 @@ function getHunkPrefixCounts({ diff, expandedHunks, collapsedContextThreshold })
|
|
|
1063
1107
|
for (let index = 0; index < diff.hunks.length; index++) {
|
|
1064
1108
|
const hunk = diff.hunks[index];
|
|
1065
1109
|
if (hunk == null) throw new Error("iterateOverDiff: invalid hunk summary index");
|
|
1066
|
-
const leadingRegion = getExpandedRegion(
|
|
1110
|
+
const leadingRegion = getExpandedRegion({
|
|
1111
|
+
isPartial: diff.isPartial,
|
|
1112
|
+
rangeSize: hunk.collapsedBefore,
|
|
1113
|
+
expandedHunks,
|
|
1114
|
+
hunkIndex: index,
|
|
1115
|
+
collapsedContextThreshold
|
|
1116
|
+
});
|
|
1067
1117
|
const leadingCount = leadingRegion.fromStart + leadingRegion.fromEnd;
|
|
1068
1118
|
splitCount += leadingCount + hunk.splitLineCount;
|
|
1069
1119
|
unifiedCount += leadingCount + hunk.unifiedLineCount;
|
|
1070
1120
|
if (index === finalHunkIndex && hasFinalCollapsedHunk(diff)) {
|
|
1071
1121
|
const trailingRangeSize = getTrailingRangeSize(diff, hunk);
|
|
1072
|
-
const trailingRegion = getExpandedRegion(
|
|
1122
|
+
const trailingRegion = getExpandedRegion({
|
|
1123
|
+
isPartial: diff.isPartial,
|
|
1124
|
+
rangeSize: trailingRangeSize,
|
|
1125
|
+
expandedHunks,
|
|
1126
|
+
hunkIndex: diff.hunks.length,
|
|
1127
|
+
collapsedContextThreshold
|
|
1128
|
+
});
|
|
1073
1129
|
const trailingCount = trailingRegion.fromStart + trailingRegion.fromEnd;
|
|
1074
1130
|
splitCount += trailingCount;
|
|
1075
1131
|
unifiedCount += trailingCount;
|
|
@@ -1107,32 +1163,6 @@ function getTrailingRangeSize(diff, hunk) {
|
|
|
1107
1163
|
if (additionRemaining !== deletionRemaining) throw new Error(`iterateOverDiff: trailing context mismatch (additions=${additionRemaining}, deletions=${deletionRemaining}) for ${diff.name}`);
|
|
1108
1164
|
return Math.min(additionRemaining, deletionRemaining);
|
|
1109
1165
|
}
|
|
1110
|
-
function getExpandedRegion(isPartial, rangeSize, expandedHunks, hunkIndex, collapsedContextThreshold) {
|
|
1111
|
-
rangeSize = Math.max(rangeSize, 0);
|
|
1112
|
-
if (rangeSize === 0 || isPartial) return {
|
|
1113
|
-
fromStart: 0,
|
|
1114
|
-
fromEnd: 0,
|
|
1115
|
-
rangeSize,
|
|
1116
|
-
collapsedLines: Math.max(rangeSize, 0)
|
|
1117
|
-
};
|
|
1118
|
-
if (expandedHunks === true || rangeSize <= collapsedContextThreshold) return {
|
|
1119
|
-
fromStart: rangeSize,
|
|
1120
|
-
fromEnd: 0,
|
|
1121
|
-
rangeSize,
|
|
1122
|
-
collapsedLines: 0
|
|
1123
|
-
};
|
|
1124
|
-
const region = expandedHunks?.get(hunkIndex);
|
|
1125
|
-
const fromStart = Math.min(Math.max(region?.fromStart ?? 0, 0), rangeSize);
|
|
1126
|
-
const fromEnd = Math.min(Math.max(region?.fromEnd ?? 0, 0), rangeSize);
|
|
1127
|
-
const expandedCount = fromStart + fromEnd;
|
|
1128
|
-
const renderAll = expandedCount >= rangeSize;
|
|
1129
|
-
return {
|
|
1130
|
-
fromStart: renderAll ? rangeSize : fromStart,
|
|
1131
|
-
fromEnd: renderAll ? 0 : fromEnd,
|
|
1132
|
-
rangeSize,
|
|
1133
|
-
collapsedLines: Math.max(rangeSize - expandedCount, 0)
|
|
1134
|
-
};
|
|
1135
|
-
}
|
|
1136
1166
|
function hasFinalCollapsedHunk(diff) {
|
|
1137
1167
|
const lastHunk = diff.hunks.at(-1);
|
|
1138
1168
|
if (lastHunk == null || diff.isPartial || diff.additionLines.length === 0 || diff.deletionLines.length === 0) return false;
|