@pierre/diffs 1.1.2 → 1.1.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/File.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.d.ts +18 -9
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +155 -52
- package/dist/components/UnresolvedFile.js.map +1 -1
- package/dist/constants.d.ts +5 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +5 -4
- package/dist/react/UnresolvedFile.d.ts +3 -1
- package/dist/react/UnresolvedFile.d.ts.map +1 -1
- package/dist/react/UnresolvedFile.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/utils/renderDiffChildren.d.ts +1 -1
- package/dist/react/utils/renderDiffChildren.d.ts.map +1 -1
- package/dist/react/utils/renderDiffChildren.js +6 -4
- package/dist/react/utils/renderDiffChildren.js.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.d.ts +3 -2
- package/dist/react/utils/useUnresolvedFileInstance.d.ts.map +1 -1
- package/dist/react/utils/useUnresolvedFileInstance.js +15 -12
- package/dist/react/utils/useUnresolvedFileInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +15 -7
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +9 -7
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts +11 -16
- package/dist/renderers/UnresolvedFileHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/UnresolvedFileHunksRenderer.js +68 -75
- package/dist/renderers/UnresolvedFileHunksRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts +2 -2
- package/dist/ssr/preloadDiffs.d.ts.map +1 -1
- package/dist/ssr/preloadDiffs.js +4 -3
- package/dist/ssr/preloadDiffs.js.map +1 -1
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +41 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/areMergeConflictActionsEqual.js +1 -1
- package/dist/utils/areMergeConflictActionsEqual.js.map +1 -1
- package/dist/utils/diffAcceptRejectHunk.d.ts +3 -2
- package/dist/utils/diffAcceptRejectHunk.d.ts.map +1 -1
- package/dist/utils/diffAcceptRejectHunk.js +24 -89
- package/dist/utils/diffAcceptRejectHunk.js.map +1 -1
- package/dist/utils/getMergeConflictActionSlotName.d.ts +4 -6
- package/dist/utils/getMergeConflictActionSlotName.d.ts.map +1 -1
- package/dist/utils/getMergeConflictActionSlotName.js +2 -2
- package/dist/utils/getMergeConflictActionSlotName.js.map +1 -1
- package/dist/utils/getMergeConflictLineTypes.d.ts +1 -2
- package/dist/utils/getMergeConflictLineTypes.d.ts.map +1 -1
- package/dist/utils/getMergeConflictLineTypes.js +7 -12
- package/dist/utils/getMergeConflictLineTypes.js.map +1 -1
- package/dist/utils/normalizeDiffResolution.d.ts +7 -0
- package/dist/utils/normalizeDiffResolution.d.ts.map +1 -0
- package/dist/utils/normalizeDiffResolution.js +11 -0
- package/dist/utils/normalizeDiffResolution.js.map +1 -0
- package/dist/utils/parseMergeConflictDiffFromFile.d.ts +16 -12
- package/dist/utils/parseMergeConflictDiffFromFile.d.ts.map +1 -1
- package/dist/utils/parseMergeConflictDiffFromFile.js +474 -117
- package/dist/utils/parseMergeConflictDiffFromFile.js.map +1 -1
- package/dist/utils/resolveConflict.d.ts +7 -0
- package/dist/utils/resolveConflict.d.ts.map +1 -0
- package/dist/utils/resolveConflict.js +23 -0
- package/dist/utils/resolveConflict.js.map +1 -0
- package/dist/utils/resolveRegion.d.ts +14 -0
- package/dist/utils/resolveRegion.d.ts.map +1 -0
- package/dist/utils/resolveRegion.js +215 -0
- package/dist/utils/resolveRegion.js.map +1 -0
- package/dist/utils/trimPatchContext.js +19 -20
- package/dist/utils/trimPatchContext.js.map +1 -1
- package/dist/worker/worker-portable.js +4 -0
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js.map +1 -1
- package/package.json +2 -1
- package/dist/utils/resolveMergeConflict.d.ts +0 -7
- package/dist/utils/resolveMergeConflict.d.ts.map +0 -1
- package/dist/utils/resolveMergeConflict.js +0 -30
- package/dist/utils/resolveMergeConflict.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseDiffOptions, BaseDiffOptionsWithDefaults, FileDiffMetadata, RenderRange } from "../types.js";
|
|
1
|
+
import { BaseDiffOptions, BaseDiffOptionsWithDefaults, FileDiffMetadata, MergeConflictMarkerRow, RenderRange } from "../types.js";
|
|
2
2
|
import { WorkerPoolManager } from "../worker/WorkerPoolManager.js";
|
|
3
3
|
import "../worker/index.js";
|
|
4
|
-
import { DiffHunksRenderer, HunksRenderResult,
|
|
4
|
+
import { DiffHunksRenderer, HunksRenderResult, LineDecoration, RenderedLineContext, SplitLineDecorationProps, UnifiedInjectedRowPlacement, UnifiedLineDecorationProps } from "./DiffHunksRenderer.js";
|
|
5
5
|
import { MergeConflictDiffAction } from "../utils/parseMergeConflictDiffFromFile.js";
|
|
6
6
|
import { Element } from "hast";
|
|
7
7
|
|
|
@@ -14,31 +14,26 @@ interface UnresolvedFileHunksRendererOptions extends BaseDiffOptions {
|
|
|
14
14
|
mergeConflictActionsType?: MergeConflictActionsType;
|
|
15
15
|
}
|
|
16
16
|
declare class UnresolvedFileHunksRenderer<LAnnotation = undefined> extends DiffHunksRenderer<LAnnotation> {
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private additionMarkerLookup;
|
|
21
|
-
private deletionMarkerLookup;
|
|
17
|
+
private pendingConflictActions;
|
|
18
|
+
private pendingMarkerRows;
|
|
19
|
+
private injectedRows;
|
|
22
20
|
options: UnresolvedFileHunksRendererOptions;
|
|
23
21
|
constructor(options?: UnresolvedFileHunksRendererOptions, onRenderUpdate?: () => unknown, workerManager?: WorkerPoolManager | undefined);
|
|
24
|
-
|
|
22
|
+
setConflictState(conflictActions: (MergeConflictDiffAction | undefined)[], markerRows: MergeConflictMarkerRow[], diff: FileDiffMetadata): void;
|
|
23
|
+
private syncInjectedRows;
|
|
24
|
+
private addInjectedRow;
|
|
25
25
|
renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;
|
|
26
26
|
asyncRender(diff: FileDiffMetadata, renderRange?: RenderRange): Promise<HunksRenderResult>;
|
|
27
27
|
protected createPreElement(split: boolean, totalLines: number, themeStyles: string, baseThemeType: 'light' | 'dark' | undefined): Element;
|
|
28
28
|
protected getUnifiedLineDecoration({
|
|
29
29
|
type,
|
|
30
|
-
lineType
|
|
31
|
-
additionLineIndex,
|
|
32
|
-
deletionLineIndex
|
|
30
|
+
lineType
|
|
33
31
|
}: UnifiedLineDecorationProps): LineDecoration;
|
|
34
32
|
protected getSplitLineDecoration({
|
|
35
33
|
side,
|
|
36
|
-
type
|
|
37
|
-
lineIndex
|
|
34
|
+
type
|
|
38
35
|
}: SplitLineDecorationProps): LineDecoration;
|
|
39
|
-
protected
|
|
40
|
-
private prepareMarkerLookups;
|
|
41
|
-
private getMergeConflictMarkerTypeAtIndex;
|
|
36
|
+
protected getUnifiedInjectedRowsForLine: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;
|
|
42
37
|
protected getOptionsWithDefaults(): BaseUnresolvedOptionsWithDefaults;
|
|
43
38
|
}
|
|
44
39
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnresolvedFileHunksRenderer.d.ts","names":["Element","HASTElement","BaseDiffOptions","BaseDiffOptionsWithDefaults","FileDiffMetadata","RenderRange","MergeConflictDiffAction","WorkerPoolManager","DiffHunksRenderer","HunksRenderResult","
|
|
1
|
+
{"version":3,"file":"UnresolvedFileHunksRenderer.d.ts","names":["Element","HASTElement","BaseDiffOptions","BaseDiffOptionsWithDefaults","FileDiffMetadata","MergeConflictMarkerRow","RenderRange","MergeConflictDiffAction","WorkerPoolManager","DiffHunksRenderer","HunksRenderResult","LineDecoration","RenderedLineContext","SplitLineDecorationProps","UnifiedInjectedRowPlacement","UnifiedLineDecorationProps","BaseUnresolvedOptionsWithDefaults","MergeConflictActionsType","UnresolvedFileHunksRendererOptions","UnresolvedFileHunksRenderer","LAnnotation","Promise","type","lineType","side"],"sources":["../../src/renderers/UnresolvedFileHunksRenderer.d.ts"],"sourcesContent":["import type { Element as HASTElement } from 'hast';\nimport type { BaseDiffOptions, BaseDiffOptionsWithDefaults, FileDiffMetadata, MergeConflictMarkerRow, RenderRange } from '../types';\nimport { type MergeConflictDiffAction } from '../utils/parseMergeConflictDiffFromFile';\nimport type { WorkerPoolManager } from '../worker';\nimport { DiffHunksRenderer, type HunksRenderResult, type LineDecoration, type RenderedLineContext, type SplitLineDecorationProps, type UnifiedInjectedRowPlacement, type UnifiedLineDecorationProps } from './DiffHunksRenderer';\ninterface BaseUnresolvedOptionsWithDefaults extends BaseDiffOptionsWithDefaults {\n mergeConflictActionsType: MergeConflictActionsType;\n}\ntype MergeConflictActionsType = 'none' | 'default' | 'custom';\nexport interface UnresolvedFileHunksRendererOptions extends BaseDiffOptions {\n mergeConflictActionsType?: MergeConflictActionsType;\n}\nexport declare class UnresolvedFileHunksRenderer<LAnnotation = undefined> extends DiffHunksRenderer<LAnnotation> {\n private pendingConflictActions;\n private pendingMarkerRows;\n private injectedRows;\n options: UnresolvedFileHunksRendererOptions;\n constructor(options?: UnresolvedFileHunksRendererOptions, onRenderUpdate?: () => unknown, workerManager?: WorkerPoolManager | undefined);\n setConflictState(conflictActions: (MergeConflictDiffAction | undefined)[], markerRows: MergeConflictMarkerRow[], diff: FileDiffMetadata): void;\n private syncInjectedRows;\n private addInjectedRow;\n renderDiff(diff?: FileDiffMetadata | undefined, renderRange?: RenderRange): HunksRenderResult | undefined;\n asyncRender(diff: FileDiffMetadata, renderRange?: RenderRange): Promise<HunksRenderResult>;\n protected createPreElement(split: boolean, totalLines: number, themeStyles: string, baseThemeType: 'light' | 'dark' | undefined): HASTElement;\n protected getUnifiedLineDecoration({ type, lineType }: UnifiedLineDecorationProps): LineDecoration;\n protected getSplitLineDecoration({ side, type }: SplitLineDecorationProps): LineDecoration;\n protected getUnifiedInjectedRowsForLine: (ctx: RenderedLineContext) => UnifiedInjectedRowPlacement | undefined;\n protected getOptionsWithDefaults(): BaseUnresolvedOptionsWithDefaults;\n}\nexport {};\n//# sourceMappingURL=UnresolvedFileHunksRenderer.d.ts.map"],"mappings":";;;;;;;;UAKUgB,iCAAAA,SAA0Cb;4BACtBc;;AAFmM,KAI5NA,wBAAAA,GAHKD,MAAAA,GAAiC,SAAA,GACbC,QAAAA;AAEzBA,UACYC,kCAAAA,SAA2ChB,eAD/B,CAAA;EACZgB,wBAAAA,CAAAA,EACcD,wBAAAA;AAE/B;AAAoGG,cAA/ED,2BAA+EC,CAAAA,cAAAA,SAAAA,CAAAA,SAAlBX,iBAAkBW,CAAAA,WAAAA,CAAAA,CAAAA;EAIvFF,QAAAA,sBAAAA;EACaA,QAAAA,iBAAAA;EAAoFV,QAAAA,YAAAA;EACvED,OAAAA,EAF1BW,kCAE0BX;EAAoDF,WAAAA,CAAAA,OAAAA,CAAAA,EADjEa,kCACiEb,EAAAA,cAAAA,CAAAA,EAAAA,GAAAA,GAAAA,OAAAA,EAAAA,aAAAA,CAAAA,EADmBG,iBACnBH,GAAAA,SAAAA;EAAgCD,gBAAAA,CAAAA,eAAAA,EAAAA,CAApFG,uBAAoFH,GAAAA,SAAAA,CAAAA,EAAAA,EAAAA,UAAAA,EAAhCC,sBAAgCD,EAAAA,EAAAA,IAAAA,EAAAA,gBAAAA,CAAAA,EAAAA,IAAAA;EAGrGA,QAAAA,gBAAAA;EAA4CE,QAAAA,cAAAA;EAAcI,UAAAA,CAAAA,IAAAA,CAAAA,EAA1DN,gBAA0DM,GAAAA,SAAAA,EAAAA,WAAAA,CAAAA,EAAdJ,WAAcI,CAAAA,EAAAA,iBAAAA,GAAAA,SAAAA;EAC1DN,WAAAA,CAAAA,IAAAA,EAAAA,gBAAAA,EAAAA,WAAAA,CAAAA,EAAgCE,WAAhCF,CAAAA,EAA8CiB,OAA9CjB,CAAsDM,iBAAtDN,CAAAA;EAAgCE,UAAAA,gBAAAA,CAAAA,KAAAA,EAAAA,OAAAA,EAAAA,UAAAA,EAAAA,MAAAA,EAAAA,WAAAA,EAAAA,MAAAA,EAAAA,aAAAA,EAAAA,OAAAA,GAAAA,MAAAA,GAAAA,SAAAA,CAAAA,EACgFL,OADhFK;EAAsBI,UAAAA,wBAAAA,CAAAA;IAAAA,IAAAA;IAAAA;EAAAA,CAAAA,EAEjBK,0BAFiBL,CAAAA,EAEYC,cAFZD;EAARW,UAAAA,sBAAAA,CAAAA;IAAAA,IAAAA;IAAAA;EAAAA,CAAAA,EAGfR,wBAHeQ,CAAAA,EAGYV,cAHZU;EACkEpB,UAAAA,6BAAAA,EAAAA,CAAAA,GAAAA,EAGnFW,mBAHmFX,EAAAA,GAG3Da,2BAH2Db,GAAAA,SAAAA;EAC7FqB,UAAAA,sBAAAA,CAAAA,CAAAA,EAGDN,iCAHCM"}
|
|
@@ -5,96 +5,96 @@ import { getMergeConflictActionSlotName } from "../utils/getMergeConflictActionS
|
|
|
5
5
|
import { getMergeConflictActionAnchor } from "../utils/parseMergeConflictDiffFromFile.js";
|
|
6
6
|
|
|
7
7
|
//#region src/renderers/UnresolvedFileHunksRenderer.ts
|
|
8
|
-
const START_MARKER = /^<{7,}(?:\s.*)?$/;
|
|
9
|
-
const BASE_MARKER = /^\|{7,}(?:\s.*)?$/;
|
|
10
|
-
const SEPARATOR_MARKER = /^={7,}(?:\s.*)?$/;
|
|
11
|
-
const END_MARKER = /^>{7,}(?:\s.*)?$/;
|
|
12
8
|
var UnresolvedFileHunksRenderer = class extends DiffHunksRenderer {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
additionMarkerLookup = [];
|
|
17
|
-
deletionMarkerLookup = [];
|
|
9
|
+
pendingConflictActions = [];
|
|
10
|
+
pendingMarkerRows = [];
|
|
11
|
+
injectedRows = /* @__PURE__ */ new Map();
|
|
18
12
|
options;
|
|
19
13
|
constructor(options = { theme: DEFAULT_THEMES }, onRenderUpdate, workerManager) {
|
|
20
14
|
super(void 0, onRenderUpdate, workerManager);
|
|
21
15
|
this.options = options;
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
this.conflictActions
|
|
17
|
+
setConflictState(conflictActions, markerRows, diff) {
|
|
18
|
+
this.pendingConflictActions = conflictActions;
|
|
19
|
+
this.pendingMarkerRows = markerRows;
|
|
20
|
+
this.syncInjectedRows(conflictActions, markerRows, diff);
|
|
21
|
+
}
|
|
22
|
+
syncInjectedRows(conflictActions, markerRows, diff) {
|
|
23
|
+
this.injectedRows.clear();
|
|
25
24
|
for (const action of conflictActions) {
|
|
26
|
-
const anchor = getMergeConflictActionAnchor(action);
|
|
27
|
-
if (anchor == null) continue;
|
|
25
|
+
const anchor = action != null ? getMergeConflictActionAnchor(action, diff) : void 0;
|
|
26
|
+
if (action == null || anchor == null) continue;
|
|
28
27
|
const row = {
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
type: "actions",
|
|
29
|
+
hunkIndex: anchor.hunkIndex,
|
|
30
|
+
lineIndex: anchor.lineIndex,
|
|
31
31
|
conflictIndex: action.conflictIndex
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
const rows = this.conflictActions.get(key);
|
|
35
|
-
if (rows == null) this.conflictActions.set(key, [row]);
|
|
36
|
-
else rows.push(row);
|
|
33
|
+
this.addInjectedRow(row);
|
|
37
34
|
}
|
|
35
|
+
for (const row of markerRows) this.addInjectedRow(row);
|
|
36
|
+
}
|
|
37
|
+
addInjectedRow(row) {
|
|
38
|
+
const key = `${row.hunkIndex}:${row.lineIndex}`;
|
|
39
|
+
const rows = this.injectedRows.get(key);
|
|
40
|
+
if (rows == null) this.injectedRows.set(key, [row]);
|
|
41
|
+
else rows.push(row);
|
|
38
42
|
}
|
|
39
43
|
renderDiff(diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
40
|
-
if (diff != null) this.
|
|
44
|
+
if (diff != null) this.syncInjectedRows(this.pendingConflictActions, this.pendingMarkerRows, diff);
|
|
41
45
|
return super.renderDiff(diff, renderRange);
|
|
42
46
|
}
|
|
43
47
|
async asyncRender(diff, renderRange = DEFAULT_RENDER_RANGE) {
|
|
44
|
-
this.
|
|
48
|
+
this.syncInjectedRows(this.pendingConflictActions, this.pendingMarkerRows, diff);
|
|
45
49
|
return super.asyncRender(diff, renderRange);
|
|
46
50
|
}
|
|
47
51
|
createPreElement(split, totalLines, themeStyles, baseThemeType) {
|
|
48
52
|
return super.createPreElement(split, totalLines, themeStyles, baseThemeType, { "data-has-merge-conflict": "" });
|
|
49
53
|
}
|
|
50
|
-
getUnifiedLineDecoration({ type, lineType
|
|
51
|
-
const mergeConflictType = type === "change" ? lineType === "change-deletion" ? "current" : "incoming" :
|
|
54
|
+
getUnifiedLineDecoration({ type, lineType }) {
|
|
55
|
+
const mergeConflictType = type === "change" ? lineType === "change-deletion" ? "current" : "incoming" : void 0;
|
|
52
56
|
return {
|
|
53
57
|
gutterLineType: type === "change" ? "context" : lineType,
|
|
54
58
|
gutterProperties: getMergeConflictGutterProperties(mergeConflictType),
|
|
55
59
|
contentProperties: getMergeConflictContentProperties(type, mergeConflictType)
|
|
56
60
|
};
|
|
57
61
|
}
|
|
58
|
-
getSplitLineDecoration({ side, type
|
|
59
|
-
const mergeConflictType = type === "change" ? side === "deletions" ? "current" : "incoming" :
|
|
62
|
+
getSplitLineDecoration({ side, type }) {
|
|
63
|
+
const mergeConflictType = type === "change" ? side === "deletions" ? "current" : "incoming" : void 0;
|
|
60
64
|
return {
|
|
61
65
|
gutterLineType: type === "change" ? "context" : type,
|
|
62
66
|
gutterProperties: getMergeConflictGutterProperties(mergeConflictType),
|
|
63
67
|
contentProperties: getMergeConflictContentProperties(type, mergeConflictType)
|
|
64
68
|
};
|
|
65
69
|
}
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const lineNumber = side === "deletions" ? ctx.deletionLine?.lineNumber : ctx.additionLine?.lineNumber;
|
|
69
|
-
if (lineNumber == null) return;
|
|
70
|
-
const rows = this.conflictActions.get(`${side}:${lineNumber}`);
|
|
70
|
+
getUnifiedInjectedRowsForLine = (ctx) => {
|
|
71
|
+
const rows = this.injectedRows.get(`${ctx.hunkIndex}:${ctx.lineIndex}`);
|
|
71
72
|
if (rows == null || rows.length === 0) return;
|
|
72
73
|
const { mergeConflictActionsType } = this.getOptionsWithDefaults();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
const before = [];
|
|
75
|
+
const after = [];
|
|
76
|
+
for (const row of rows) {
|
|
77
|
+
if (row.type === "actions") {
|
|
78
|
+
before.push({
|
|
79
|
+
content: createMergeConflictActionsRowElement({
|
|
80
|
+
row,
|
|
81
|
+
includeDefaultActions: mergeConflictActionsType === "default",
|
|
82
|
+
includeSlot: true
|
|
83
|
+
}),
|
|
84
|
+
gutter: createMergeConflictGutterGap("action")
|
|
85
|
+
});
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
(row.type === "marker-end" ? after : before).push({
|
|
89
|
+
content: createMergeConflictMarkerRowElement(row),
|
|
90
|
+
gutter: createMergeConflictGutterGap("marker", row.type)
|
|
91
|
+
});
|
|
90
92
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return value === "none" ? void 0 : value;
|
|
97
|
-
}
|
|
93
|
+
return {
|
|
94
|
+
before: before.length > 0 ? before : void 0,
|
|
95
|
+
after: after.length > 0 ? after : void 0
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
98
|
getOptionsWithDefaults() {
|
|
99
99
|
const options = super.getOptionsWithDefaults();
|
|
100
100
|
options.diffStyle = "unified";
|
|
@@ -117,26 +117,9 @@ function getMergeConflictContentProperties(type, mergeConflictType) {
|
|
|
117
117
|
}
|
|
118
118
|
if (mergeConflictType === "marker-start" || mergeConflictType === "marker-base" || mergeConflictType === "marker-separator" || mergeConflictType === "marker-end") return { "data-merge-conflict": mergeConflictType };
|
|
119
119
|
}
|
|
120
|
-
function
|
|
121
|
-
if (line == null) return;
|
|
122
|
-
const trimmed = line.replace(/(?:\r\n|\n|\r)$/, "");
|
|
123
|
-
if (START_MARKER.test(trimmed)) return "marker-start";
|
|
124
|
-
if (BASE_MARKER.test(trimmed)) return "marker-base";
|
|
125
|
-
if (SEPARATOR_MARKER.test(trimmed)) return "marker-separator";
|
|
126
|
-
if (END_MARKER.test(trimmed)) return "marker-end";
|
|
127
|
-
}
|
|
128
|
-
function buildMarkerLookup(lines) {
|
|
129
|
-
const markerLookup = new Array(lines.length);
|
|
130
|
-
for (let index = 0; index < lines.length; index++) markerLookup[index] = getMergeConflictMarkerType(lines[index]) ?? "none";
|
|
131
|
-
return markerLookup;
|
|
132
|
-
}
|
|
133
|
-
function getUnifiedRenderedSide(ctx) {
|
|
134
|
-
if (ctx.type === "change" && ctx.deletionLine != null && ctx.additionLine == null) return "deletions";
|
|
135
|
-
return "additions";
|
|
136
|
-
}
|
|
137
|
-
function createMergeConflictGutterGap() {
|
|
120
|
+
function createMergeConflictGutterGap(type, markerType) {
|
|
138
121
|
const gap = createGutterGap(void 0, "annotation", 1);
|
|
139
|
-
gap.properties["data-gutter-buffer"] = "merge-conflict-action"
|
|
122
|
+
gap.properties["data-gutter-buffer"] = type === "action" ? "merge-conflict-action" : `merge-conflict-${markerType ?? "marker"}`;
|
|
140
123
|
return gap;
|
|
141
124
|
}
|
|
142
125
|
function createMergeConflictActionsRowElement({ row, includeDefaultActions, includeSlot }) {
|
|
@@ -145,8 +128,8 @@ function createMergeConflictActionsRowElement({ row, includeDefaultActions, incl
|
|
|
145
128
|
tagName: "slot",
|
|
146
129
|
properties: {
|
|
147
130
|
name: getMergeConflictActionSlotName({
|
|
148
|
-
|
|
149
|
-
|
|
131
|
+
hunkIndex: row.hunkIndex,
|
|
132
|
+
lineIndex: row.lineIndex,
|
|
150
133
|
conflictIndex: row.conflictIndex
|
|
151
134
|
}),
|
|
152
135
|
"data-merge-conflict-action-slot": ""
|
|
@@ -162,6 +145,16 @@ function createMergeConflictActionsRowElement({ row, includeDefaultActions, incl
|
|
|
162
145
|
})]
|
|
163
146
|
});
|
|
164
147
|
}
|
|
148
|
+
function createMergeConflictMarkerRowElement(row) {
|
|
149
|
+
return createHastElement({
|
|
150
|
+
tagName: "div",
|
|
151
|
+
properties: {
|
|
152
|
+
"data-merge-conflict": row.type,
|
|
153
|
+
"data-merge-conflict-marker-row": ""
|
|
154
|
+
},
|
|
155
|
+
children: [createTextNodeElement(row.lineText.replace(/(?:\r\n|\n|\r)$/, ""))]
|
|
156
|
+
});
|
|
157
|
+
}
|
|
165
158
|
function createMergeConflictActionsContent(conflictIndex) {
|
|
166
159
|
return [
|
|
167
160
|
createMergeConflictActionButton({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnresolvedFileHunksRenderer.js","names":["markerLookup: MergeConflictMarkerLookup[]","contentChildren: HASTElement[]"],"sources":["../../src/renderers/UnresolvedFileHunksRenderer.ts"],"sourcesContent":["import type { Element as HASTElement, Properties } from 'hast';\n\nimport { DEFAULT_RENDER_RANGE, DEFAULT_THEMES } from '../constants';\nimport type {\n BaseDiffOptions,\n BaseDiffOptionsWithDefaults,\n DiffLineAnnotation,\n FileDiffMetadata,\n MergeConflictResolution,\n RenderRange,\n} from '../types';\nimport { getMergeConflictActionSlotName } from '../utils/getMergeConflictActionSlotName';\nimport {\n createGutterGap,\n createHastElement,\n createTextNodeElement,\n} from '../utils/hast_utils';\nimport {\n getMergeConflictActionAnchor,\n type MergeConflictDiffAction,\n} from '../utils/parseMergeConflictDiffFromFile';\nimport type { WorkerPoolManager } from '../worker';\nimport {\n DiffHunksRenderer,\n type HunksRenderResult,\n type InlineRow,\n type LineDecoration,\n type RenderedLineContext,\n type SplitLineDecorationProps,\n type UnifiedLineDecorationProps,\n} from './DiffHunksRenderer';\n\ntype MergeConflictMarkerType =\n | 'marker-start'\n | 'marker-base'\n | 'marker-separator'\n | 'marker-end'\n | 'current'\n | 'incoming';\ntype MergeConflictMarkerLookup = MergeConflictMarkerType | 'none';\n\ninterface MergeConflictActionRowData {\n side: DiffLineAnnotation<undefined>['side'];\n lineNumber: number;\n conflictIndex: number;\n}\n\ninterface BaseUnresolvedOptionsWithDefaults extends BaseDiffOptionsWithDefaults {\n mergeConflictActionsType: MergeConflictActionsType;\n}\n\ntype MergeConflictActionsType = 'none' | 'default' | 'custom';\n\nexport interface UnresolvedFileHunksRendererOptions extends BaseDiffOptions {\n mergeConflictActionsType?: MergeConflictActionsType;\n}\n\nconst START_MARKER = /^<{7,}(?:\\s.*)?$/;\nconst BASE_MARKER = /^\\|{7,}(?:\\s.*)?$/;\nconst SEPARATOR_MARKER = /^={7,}(?:\\s.*)?$/;\nconst END_MARKER = /^>{7,}(?:\\s.*)?$/;\n\nexport class UnresolvedFileHunksRenderer<\n LAnnotation = undefined,\n> extends DiffHunksRenderer<LAnnotation> {\n private cachedAdditionLines: string[] | undefined;\n private cachedDeletionLines: string[] | undefined;\n private conflictActions = new Map<string, MergeConflictActionRowData[]>();\n private additionMarkerLookup: MergeConflictMarkerLookup[] = [];\n private deletionMarkerLookup: MergeConflictMarkerLookup[] = [];\n public override options: UnresolvedFileHunksRendererOptions;\n\n constructor(\n options: UnresolvedFileHunksRendererOptions = {\n theme: DEFAULT_THEMES,\n },\n onRenderUpdate?: () => unknown,\n workerManager?: WorkerPoolManager | undefined\n ) {\n super(undefined, onRenderUpdate, workerManager);\n this.options = options;\n }\n\n public setConflictActions(conflictActions: MergeConflictDiffAction[]): void {\n this.conflictActions.clear();\n for (const action of conflictActions) {\n const anchor = getMergeConflictActionAnchor(action);\n if (anchor == null) {\n continue;\n }\n const row = {\n side: anchor.side,\n lineNumber: anchor.lineNumber,\n conflictIndex: action.conflictIndex,\n };\n const key = `${row.side}:${row.lineNumber}`;\n const rows = this.conflictActions.get(key);\n if (rows == null) {\n this.conflictActions.set(key, [row]);\n } else {\n rows.push(row);\n }\n }\n }\n\n public override renderDiff(\n diff?: FileDiffMetadata | undefined,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): HunksRenderResult | undefined {\n if (diff != null) {\n this.prepareMarkerLookups(diff);\n }\n return super.renderDiff(diff, renderRange);\n }\n\n public override async asyncRender(\n diff: FileDiffMetadata,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): Promise<HunksRenderResult> {\n this.prepareMarkerLookups(diff);\n return super.asyncRender(diff, renderRange);\n }\n\n protected override createPreElement(\n split: boolean,\n totalLines: number,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ): HASTElement {\n return super.createPreElement(\n split,\n totalLines,\n themeStyles,\n baseThemeType,\n { 'data-has-merge-conflict': '' }\n );\n }\n\n protected override getUnifiedLineDecoration({\n type,\n lineType,\n additionLineIndex,\n deletionLineIndex,\n }: UnifiedLineDecorationProps): LineDecoration {\n const mergeConflictType =\n type === 'change'\n ? lineType === 'change-deletion'\n ? 'current'\n : 'incoming'\n : (this.getMergeConflictMarkerTypeAtIndex(\n 'additions',\n additionLineIndex\n ) ??\n this.getMergeConflictMarkerTypeAtIndex(\n 'deletions',\n deletionLineIndex\n ));\n return {\n gutterLineType: type === 'change' ? 'context' : lineType,\n gutterProperties: getMergeConflictGutterProperties(mergeConflictType),\n contentProperties: getMergeConflictContentProperties(\n type,\n mergeConflictType\n ),\n };\n }\n\n protected override getSplitLineDecoration({\n side,\n type,\n lineIndex,\n }: SplitLineDecorationProps): LineDecoration {\n const mergeConflictType =\n type === 'change'\n ? side === 'deletions'\n ? 'current'\n : 'incoming'\n : this.getMergeConflictMarkerTypeAtIndex(side, lineIndex);\n return {\n gutterLineType: type === 'change' ? 'context' : type,\n gutterProperties: getMergeConflictGutterProperties(mergeConflictType),\n contentProperties: getMergeConflictContentProperties(\n type,\n mergeConflictType\n ),\n };\n }\n\n protected override getUnifiedInlineRowsForLine = (\n ctx: RenderedLineContext\n ): InlineRow[] | undefined => {\n const side = getUnifiedRenderedSide(ctx);\n const lineNumber =\n side === 'deletions'\n ? ctx.deletionLine?.lineNumber\n : ctx.additionLine?.lineNumber;\n if (lineNumber == null) {\n return undefined;\n }\n const rows = this.conflictActions.get(`${side}:${lineNumber}`);\n if (rows == null || rows.length === 0) {\n return undefined;\n }\n const { mergeConflictActionsType } = this.getOptionsWithDefaults();\n return rows.map((row) => ({\n content: createMergeConflictActionsRowElement({\n row,\n includeDefaultActions: mergeConflictActionsType === 'default',\n includeSlot: true,\n }),\n gutter: createMergeConflictGutterGap(),\n }));\n };\n\n private prepareMarkerLookups(diff: FileDiffMetadata): void {\n if (this.cachedAdditionLines !== diff.additionLines) {\n this.cachedAdditionLines = diff.additionLines;\n this.additionMarkerLookup = buildMarkerLookup(diff.additionLines);\n }\n if (this.cachedDeletionLines !== diff.deletionLines) {\n this.cachedDeletionLines = diff.deletionLines;\n this.deletionMarkerLookup = buildMarkerLookup(diff.deletionLines);\n }\n }\n\n private getMergeConflictMarkerTypeAtIndex(\n side: 'additions' | 'deletions',\n lineIndex: number | undefined\n ): MergeConflictMarkerType | undefined {\n if (lineIndex == null) {\n return undefined;\n }\n const value = (\n side === 'additions'\n ? this.additionMarkerLookup\n : this.deletionMarkerLookup\n )[lineIndex];\n if (value == null) {\n return undefined;\n }\n return value === 'none' ? undefined : value;\n }\n\n protected override getOptionsWithDefaults(): BaseUnresolvedOptionsWithDefaults {\n const options = super.getOptionsWithDefaults();\n options.diffStyle = 'unified';\n options.lineDiffType = 'none';\n // NOTE(amadeus): Aint nobody got time for a spread\n (options as BaseUnresolvedOptionsWithDefaults).mergeConflictActionsType =\n this.options.mergeConflictActionsType ?? 'default';\n return options as BaseUnresolvedOptionsWithDefaults;\n }\n}\n\nfunction getMergeConflictGutterProperties(\n mergeConflictType: MergeConflictMarkerType | undefined\n): Properties | undefined {\n return mergeConflictType != null\n ? { 'data-merge-conflict': mergeConflictType }\n : undefined;\n}\n\nfunction getMergeConflictContentProperties(\n type: 'change' | 'context' | 'context-expanded',\n mergeConflictType: MergeConflictMarkerType | undefined\n): Properties | undefined {\n if (mergeConflictType == null) {\n return undefined;\n }\n if (type === 'change') {\n if (mergeConflictType === 'current' || mergeConflictType === 'incoming') {\n return {\n 'data-line-type': 'context',\n 'data-merge-conflict': mergeConflictType,\n };\n }\n return undefined;\n }\n if (\n mergeConflictType === 'marker-start' ||\n mergeConflictType === 'marker-base' ||\n mergeConflictType === 'marker-separator' ||\n mergeConflictType === 'marker-end'\n ) {\n return { 'data-merge-conflict': mergeConflictType };\n }\n return undefined;\n}\n\nfunction getMergeConflictMarkerType(\n line: string | undefined\n): MergeConflictMarkerType | undefined {\n if (line == null) {\n return undefined;\n }\n const trimmed = line.replace(/(?:\\r\\n|\\n|\\r)$/, '');\n if (START_MARKER.test(trimmed)) return 'marker-start';\n if (BASE_MARKER.test(trimmed)) return 'marker-base';\n if (SEPARATOR_MARKER.test(trimmed)) return 'marker-separator';\n if (END_MARKER.test(trimmed)) return 'marker-end';\n return undefined;\n}\n\nfunction buildMarkerLookup(lines: string[]): MergeConflictMarkerLookup[] {\n const markerLookup: MergeConflictMarkerLookup[] = new Array(lines.length);\n for (let index = 0; index < lines.length; index++) {\n markerLookup[index] = getMergeConflictMarkerType(lines[index]) ?? 'none';\n }\n return markerLookup;\n}\n\nfunction getUnifiedRenderedSide(\n ctx: RenderedLineContext\n): DiffLineAnnotation<undefined>['side'] {\n if (\n ctx.type === 'change' &&\n ctx.deletionLine != null &&\n ctx.additionLine == null\n ) {\n return 'deletions';\n }\n return 'additions';\n}\n\nfunction createMergeConflictGutterGap(): HASTElement {\n const gap = createGutterGap(undefined, 'annotation', 1);\n gap.properties['data-gutter-buffer'] = 'merge-conflict-action';\n return gap;\n}\n\ninterface CreateMergeConflictActionsRowElementProps {\n row: MergeConflictActionRowData;\n includeDefaultActions: boolean;\n includeSlot: boolean;\n}\n\nfunction createMergeConflictActionsRowElement({\n row,\n includeDefaultActions,\n includeSlot,\n}: CreateMergeConflictActionsRowElementProps): HASTElement {\n const contentChildren: HASTElement[] = includeDefaultActions\n ? createMergeConflictActionsContent(row.conflictIndex)\n : [];\n if (includeSlot) {\n contentChildren.push(\n createHastElement({\n tagName: 'slot',\n properties: {\n name: getMergeConflictActionSlotName({\n side: row.side,\n lineNumber: row.lineNumber,\n conflictIndex: row.conflictIndex,\n }),\n 'data-merge-conflict-action-slot': '',\n },\n })\n );\n }\n return createHastElement({\n tagName: 'div',\n properties: {\n 'data-merge-conflict-actions': '',\n },\n children: [\n createHastElement({\n tagName: 'div',\n properties: { 'data-merge-conflict-actions-content': '' },\n children: contentChildren,\n }),\n ],\n });\n}\n\nfunction createMergeConflictActionsContent(\n conflictIndex: number\n): HASTElement[] {\n return [\n createMergeConflictActionButton({\n resolution: 'current',\n label: 'Accept current change',\n conflictIndex,\n }),\n createMergeConflictActionSeparator(),\n createMergeConflictActionButton({\n resolution: 'incoming',\n label: 'Accept incoming change',\n conflictIndex,\n }),\n createMergeConflictActionSeparator(),\n createMergeConflictActionButton({\n resolution: 'both',\n label: 'Accept both',\n conflictIndex,\n }),\n ];\n}\n\ninterface CreateMergeConflictActionButtonProps {\n resolution: MergeConflictResolution;\n label: string;\n conflictIndex: number;\n}\n\nfunction createMergeConflictActionButton({\n resolution,\n label,\n conflictIndex,\n}: CreateMergeConflictActionButtonProps): HASTElement {\n return createHastElement({\n tagName: 'button',\n properties: {\n type: 'button',\n 'data-merge-conflict-action': resolution,\n 'data-merge-conflict-conflict-index': `${conflictIndex}`,\n },\n children: [createTextNodeElement(label)],\n });\n}\n\nfunction createMergeConflictActionSeparator(): HASTElement {\n return createHastElement({\n tagName: 'span',\n properties: { 'data-merge-conflict-action-separator': '' },\n children: [createTextNodeElement('|')],\n });\n}\n"],"mappings":";;;;;;;AAyDA,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,mBAAmB;AACzB,MAAM,aAAa;AAEnB,IAAa,8BAAb,cAEU,kBAA+B;CACvC,AAAQ;CACR,AAAQ;CACR,AAAQ,kCAAkB,IAAI,KAA2C;CACzE,AAAQ,uBAAoD,EAAE;CAC9D,AAAQ,uBAAoD,EAAE;CAC9D,AAAgB;CAEhB,YACE,UAA8C,EAC5C,OAAO,gBACR,EACD,gBACA,eACA;AACA,QAAM,QAAW,gBAAgB,cAAc;AAC/C,OAAK,UAAU;;CAGjB,AAAO,mBAAmB,iBAAkD;AAC1E,OAAK,gBAAgB,OAAO;AAC5B,OAAK,MAAM,UAAU,iBAAiB;GACpC,MAAM,SAAS,6BAA6B,OAAO;AACnD,OAAI,UAAU,KACZ;GAEF,MAAM,MAAM;IACV,MAAM,OAAO;IACb,YAAY,OAAO;IACnB,eAAe,OAAO;IACvB;GACD,MAAM,MAAM,GAAG,IAAI,KAAK,GAAG,IAAI;GAC/B,MAAM,OAAO,KAAK,gBAAgB,IAAI,IAAI;AAC1C,OAAI,QAAQ,KACV,MAAK,gBAAgB,IAAI,KAAK,CAAC,IAAI,CAAC;OAEpC,MAAK,KAAK,IAAI;;;CAKpB,AAAgB,WACd,MACA,cAA2B,sBACI;AAC/B,MAAI,QAAQ,KACV,MAAK,qBAAqB,KAAK;AAEjC,SAAO,MAAM,WAAW,MAAM,YAAY;;CAG5C,MAAsB,YACpB,MACA,cAA2B,sBACC;AAC5B,OAAK,qBAAqB,KAAK;AAC/B,SAAO,MAAM,YAAY,MAAM,YAAY;;CAG7C,AAAmB,iBACjB,OACA,Y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B,QACpB,IAAI,gBAAgB,KAEpB,QAAO;AAET,QAAO;;AAGT,SAAS,+BAA4C;CACnD,MAAM,MAAM,gBAAgB,QAAW,cAAc,EAAE;AACvD,KAAI,WAAW,wBAAwB;AACvC,QAAO;;AAST,SAAS,qCAAqC,EAC5C,KACA,uBACA,eACyD;CACzD,MAAMC,kBAAiC,wBACnC,kCAAkC,IAAI,cAAc,GACpD,EAAE;AACN,KAAI,YACF,iBAAgB,KACd,kBAAkB;EAChB,SAAS;EACT,YAAY;GACV,MAAM,+BAA+B;IACnC,MAAM,IAAI;IACV,YAAY,IAAI;IAChB,eAAe,IAAI;IACpB,CAAC;GACF,mCAAmC;GACpC;EACF,CAAC,CACH;AAEH,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY,EACV,+BAA+B,IAChC;EACD,UAAU,CACR,kBAAkB;GAChB,SAAS;GACT,YAAY,EAAE,uCAAuC,IAAI;GACzD,UAAU;GACX,CAAC,CACH;EACF,CAAC;;AAGJ,SAAS,kCACP,eACe;AACf,QAAO;EACL,gCAAgC;GAC9B,YAAY;GACZ,OAAO;GACP;GACD,CAAC;EACF,oCAAoC;EACpC,gCAAgC;GAC9B,YAAY;GACZ,OAAO;GACP;GACD,CAAC;EACF,oCAAoC;EACpC,gCAAgC;GAC9B,YAAY;GACZ,OAAO;GACP;GACD,CAAC;EACH;;AASH,SAAS,gCAAgC,EACvC,YACA,OACA,iBACoD;AACpD,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY;GACV,MAAM;GACN,8BAA8B;GAC9B,sCAAsC,GAAG;GAC1C;EACD,UAAU,CAAC,sBAAsB,MAAM,CAAC;EACzC,CAAC;;AAGJ,SAAS,qCAAkD;AACzD,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY,EAAE,wCAAwC,IAAI;EAC1D,UAAU,CAAC,sBAAsB,IAAI,CAAC;EACvC,CAAC"}
|
|
1
|
+
{"version":3,"file":"UnresolvedFileHunksRenderer.js","names":["row: MergeConflictInjectedRowData","before: InjectedRow[]","after: InjectedRow[]","contentChildren: HASTElement[]"],"sources":["../../src/renderers/UnresolvedFileHunksRenderer.ts"],"sourcesContent":["import type { Element as HASTElement, Properties } from 'hast';\n\nimport { DEFAULT_RENDER_RANGE, DEFAULT_THEMES } from '../constants';\nimport type {\n BaseDiffOptions,\n BaseDiffOptionsWithDefaults,\n FileDiffMetadata,\n MergeConflictMarkerRow,\n MergeConflictResolution,\n RenderRange,\n} from '../types';\nimport { getMergeConflictActionSlotName } from '../utils/getMergeConflictActionSlotName';\nimport {\n createGutterGap,\n createHastElement,\n createTextNodeElement,\n} from '../utils/hast_utils';\nimport {\n getMergeConflictActionAnchor,\n type MergeConflictDiffAction,\n} from '../utils/parseMergeConflictDiffFromFile';\nimport type { WorkerPoolManager } from '../worker';\nimport {\n DiffHunksRenderer,\n type HunksRenderResult,\n type InjectedRow,\n type LineDecoration,\n type RenderedLineContext,\n type SplitLineDecorationProps,\n type UnifiedInjectedRowPlacement,\n type UnifiedLineDecorationProps,\n} from './DiffHunksRenderer';\n\ntype MergeConflictMarkerType =\n | 'marker-start'\n | 'marker-base'\n | 'marker-separator'\n | 'marker-end'\n | 'current'\n | 'incoming';\n\ninterface MergeConflictActionRowData {\n hunkIndex: number;\n lineIndex: number;\n conflictIndex: number;\n}\n\ninterface MergeConflictMarkerInjectedRow extends MergeConflictMarkerRow {\n type: Extract<\n MergeConflictMarkerRow['type'],\n 'marker-start' | 'marker-base' | 'marker-separator' | 'marker-end'\n >;\n lineText: string;\n lineIndex: number;\n}\n\n// NOTE(amadeus): Don't love this, should probably rework into an\n// interface/extender\ntype MergeConflictInjectedRowData =\n | ({ type: 'actions' } & MergeConflictActionRowData)\n | MergeConflictMarkerInjectedRow;\n\ninterface BaseUnresolvedOptionsWithDefaults extends BaseDiffOptionsWithDefaults {\n mergeConflictActionsType: MergeConflictActionsType;\n}\n\ntype MergeConflictActionsType = 'none' | 'default' | 'custom';\n\nexport interface UnresolvedFileHunksRendererOptions extends BaseDiffOptions {\n mergeConflictActionsType?: MergeConflictActionsType;\n}\n\nexport class UnresolvedFileHunksRenderer<\n LAnnotation = undefined,\n> extends DiffHunksRenderer<LAnnotation> {\n private pendingConflictActions: (MergeConflictDiffAction | undefined)[] = [];\n private pendingMarkerRows: MergeConflictMarkerRow[] = [];\n private injectedRows = new Map<string, MergeConflictInjectedRowData[]>();\n public override options: UnresolvedFileHunksRendererOptions;\n\n constructor(\n options: UnresolvedFileHunksRendererOptions = {\n theme: DEFAULT_THEMES,\n },\n onRenderUpdate?: () => unknown,\n workerManager?: WorkerPoolManager | undefined\n ) {\n super(undefined, onRenderUpdate, workerManager);\n this.options = options;\n }\n\n // SELF_REVIEW: I don't love how this is hooked up with `renderDiff` right\n // now, so we definitely need to figure out what the fuck we are gonna do\n // about it...\n // I think at the very least we should keep it like annotations, and just\n // sorta assume there's a disconnect there\n public setConflictState(\n conflictActions: (MergeConflictDiffAction | undefined)[],\n markerRows: MergeConflictMarkerRow[],\n diff: FileDiffMetadata\n ): void {\n this.pendingConflictActions = conflictActions;\n this.pendingMarkerRows = markerRows;\n this.syncInjectedRows(conflictActions, markerRows, diff);\n }\n\n private syncInjectedRows(\n conflictActions: (MergeConflictDiffAction | undefined)[],\n markerRows: MergeConflictMarkerRow[],\n diff: FileDiffMetadata\n ): void {\n this.injectedRows.clear();\n for (const action of conflictActions) {\n const anchor =\n action != null ? getMergeConflictActionAnchor(action, diff) : undefined;\n if (action == null || anchor == null) {\n continue;\n }\n const row: MergeConflictInjectedRowData = {\n type: 'actions',\n hunkIndex: anchor.hunkIndex,\n lineIndex: anchor.lineIndex,\n conflictIndex: action.conflictIndex,\n };\n this.addInjectedRow(row);\n }\n\n for (const row of markerRows) {\n this.addInjectedRow(row);\n }\n }\n\n private addInjectedRow(row: MergeConflictInjectedRowData): void {\n const key = `${row.hunkIndex}:${row.lineIndex}`;\n const rows = this.injectedRows.get(key);\n if (rows == null) {\n this.injectedRows.set(key, [row]);\n } else {\n rows.push(row);\n }\n }\n\n public override renderDiff(\n diff?: FileDiffMetadata | undefined,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): HunksRenderResult | undefined {\n if (diff != null) {\n this.syncInjectedRows(\n this.pendingConflictActions,\n this.pendingMarkerRows,\n diff\n );\n }\n return super.renderDiff(diff, renderRange);\n }\n\n public override async asyncRender(\n diff: FileDiffMetadata,\n renderRange: RenderRange = DEFAULT_RENDER_RANGE\n ): Promise<HunksRenderResult> {\n this.syncInjectedRows(\n this.pendingConflictActions,\n this.pendingMarkerRows,\n diff\n );\n return super.asyncRender(diff, renderRange);\n }\n\n protected override createPreElement(\n split: boolean,\n totalLines: number,\n themeStyles: string,\n baseThemeType: 'light' | 'dark' | undefined\n ): HASTElement {\n return super.createPreElement(\n split,\n totalLines,\n themeStyles,\n baseThemeType,\n { 'data-has-merge-conflict': '' }\n );\n }\n\n protected override getUnifiedLineDecoration({\n type,\n lineType,\n }: UnifiedLineDecorationProps): LineDecoration {\n const mergeConflictType =\n type === 'change'\n ? lineType === 'change-deletion'\n ? 'current'\n : 'incoming'\n : undefined;\n return {\n gutterLineType: type === 'change' ? 'context' : lineType,\n gutterProperties: getMergeConflictGutterProperties(mergeConflictType),\n contentProperties: getMergeConflictContentProperties(\n type,\n mergeConflictType\n ),\n };\n }\n\n protected override getSplitLineDecoration({\n side,\n type,\n }: SplitLineDecorationProps): LineDecoration {\n const mergeConflictType =\n type === 'change'\n ? side === 'deletions'\n ? 'current'\n : 'incoming'\n : undefined;\n return {\n gutterLineType: type === 'change' ? 'context' : type,\n gutterProperties: getMergeConflictGutterProperties(mergeConflictType),\n contentProperties: getMergeConflictContentProperties(\n type,\n mergeConflictType\n ),\n };\n }\n\n protected override getUnifiedInjectedRowsForLine = (\n ctx: RenderedLineContext\n ): UnifiedInjectedRowPlacement | undefined => {\n const rows = this.injectedRows.get(`${ctx.hunkIndex}:${ctx.lineIndex}`);\n if (rows == null || rows.length === 0) {\n return undefined;\n }\n const { mergeConflictActionsType } = this.getOptionsWithDefaults();\n const before: InjectedRow[] = [];\n const after: InjectedRow[] = [];\n for (const row of rows) {\n if (row.type === 'actions') {\n before.push({\n content: createMergeConflictActionsRowElement({\n row,\n includeDefaultActions: mergeConflictActionsType === 'default',\n includeSlot: true,\n }),\n gutter: createMergeConflictGutterGap('action'),\n });\n continue;\n }\n const target = row.type === 'marker-end' ? after : before;\n target.push({\n content: createMergeConflictMarkerRowElement(row),\n gutter: createMergeConflictGutterGap('marker', row.type),\n });\n }\n return {\n before: before.length > 0 ? before : undefined,\n after: after.length > 0 ? after : undefined,\n };\n };\n\n protected override getOptionsWithDefaults(): BaseUnresolvedOptionsWithDefaults {\n const options = super.getOptionsWithDefaults();\n options.diffStyle = 'unified';\n options.lineDiffType = 'none';\n // NOTE(amadeus): Aint nobody got time for a spread\n (options as BaseUnresolvedOptionsWithDefaults).mergeConflictActionsType =\n this.options.mergeConflictActionsType ?? 'default';\n return options as BaseUnresolvedOptionsWithDefaults;\n }\n}\n\nfunction getMergeConflictGutterProperties(\n mergeConflictType: MergeConflictMarkerType | undefined\n): Properties | undefined {\n return mergeConflictType != null\n ? { 'data-merge-conflict': mergeConflictType }\n : undefined;\n}\n\nfunction getMergeConflictContentProperties(\n type: 'change' | 'context' | 'context-expanded',\n mergeConflictType: MergeConflictMarkerType | undefined\n): Properties | undefined {\n if (mergeConflictType == null) {\n return undefined;\n }\n if (type === 'change') {\n if (mergeConflictType === 'current' || mergeConflictType === 'incoming') {\n return {\n 'data-line-type': 'context',\n 'data-merge-conflict': mergeConflictType,\n };\n }\n return undefined;\n }\n if (\n mergeConflictType === 'marker-start' ||\n mergeConflictType === 'marker-base' ||\n mergeConflictType === 'marker-separator' ||\n mergeConflictType === 'marker-end'\n ) {\n return { 'data-merge-conflict': mergeConflictType };\n }\n return undefined;\n}\n\nfunction createMergeConflictGutterGap(\n type: 'action' | 'marker',\n markerType?: MergeConflictMarkerInjectedRow['type']\n): HASTElement {\n const gap = createGutterGap(undefined, 'annotation', 1);\n gap.properties['data-gutter-buffer'] =\n type === 'action'\n ? 'merge-conflict-action'\n : `merge-conflict-${markerType ?? 'marker'}`;\n return gap;\n}\n\ninterface CreateMergeConflictActionsRowElementProps {\n row: MergeConflictActionRowData;\n includeDefaultActions: boolean;\n includeSlot: boolean;\n}\n\nfunction createMergeConflictActionsRowElement({\n row,\n includeDefaultActions,\n includeSlot,\n}: CreateMergeConflictActionsRowElementProps): HASTElement {\n const contentChildren: HASTElement[] = includeDefaultActions\n ? createMergeConflictActionsContent(row.conflictIndex)\n : [];\n if (includeSlot) {\n contentChildren.push(\n createHastElement({\n tagName: 'slot',\n properties: {\n name: getMergeConflictActionSlotName({\n hunkIndex: row.hunkIndex,\n lineIndex: row.lineIndex,\n conflictIndex: row.conflictIndex,\n }),\n 'data-merge-conflict-action-slot': '',\n },\n })\n );\n }\n return createHastElement({\n tagName: 'div',\n properties: {\n 'data-merge-conflict-actions': '',\n },\n children: [\n createHastElement({\n tagName: 'div',\n properties: { 'data-merge-conflict-actions-content': '' },\n children: contentChildren,\n }),\n ],\n });\n}\n\nfunction createMergeConflictMarkerRowElement(\n row: MergeConflictMarkerInjectedRow\n): HASTElement {\n return createHastElement({\n tagName: 'div',\n properties: {\n 'data-merge-conflict': row.type,\n 'data-merge-conflict-marker-row': '',\n },\n children: [\n createTextNodeElement(row.lineText.replace(/(?:\\r\\n|\\n|\\r)$/, '')),\n ],\n });\n}\n\nfunction createMergeConflictActionsContent(\n conflictIndex: number\n): HASTElement[] {\n return [\n createMergeConflictActionButton({\n resolution: 'current',\n label: 'Accept current change',\n conflictIndex,\n }),\n createMergeConflictActionSeparator(),\n createMergeConflictActionButton({\n resolution: 'incoming',\n label: 'Accept incoming change',\n conflictIndex,\n }),\n createMergeConflictActionSeparator(),\n createMergeConflictActionButton({\n resolution: 'both',\n label: 'Accept both',\n conflictIndex,\n }),\n ];\n}\n\ninterface CreateMergeConflictActionButtonProps {\n resolution: MergeConflictResolution;\n label: string;\n conflictIndex: number;\n}\n\nfunction createMergeConflictActionButton({\n resolution,\n label,\n conflictIndex,\n}: CreateMergeConflictActionButtonProps): HASTElement {\n return createHastElement({\n tagName: 'button',\n properties: {\n type: 'button',\n 'data-merge-conflict-action': resolution,\n 'data-merge-conflict-conflict-index': `${conflictIndex}`,\n },\n children: [createTextNodeElement(label)],\n });\n}\n\nfunction createMergeConflictActionSeparator(): HASTElement {\n return createHastElement({\n tagName: 'span',\n properties: { 'data-merge-conflict-action-separator': '' },\n children: [createTextNodeElement('|')],\n });\n}\n"],"mappings":";;;;;;;AAwEA,IAAa,8BAAb,cAEU,kBAA+B;CACvC,AAAQ,yBAAkE,EAAE;CAC5E,AAAQ,oBAA8C,EAAE;CACxD,AAAQ,+BAAe,IAAI,KAA6C;CACxE,AAAgB;CAEhB,YACE,UAA8C,EAC5C,OAAO,gBACR,EACD,gBACA,eACA;AACA,QAAM,QAAW,gBAAgB,cAAc;AAC/C,OAAK,UAAU;;CAQjB,AAAO,iBACL,iBACA,YACA,MACM;AACN,OAAK,yBAAyB;AAC9B,OAAK,oBAAoB;AACzB,OAAK,iBAAiB,iBAAiB,YAAY,KAAK;;CAG1D,AAAQ,iBACN,iBACA,YACA,MACM;AACN,OAAK,aAAa,OAAO;AACzB,OAAK,MAAM,UAAU,iBAAiB;GACpC,MAAM,SACJ,UAAU,OAAO,6BAA6B,QAAQ,KAAK,GAAG;AAChE,OAAI,UAAU,QAAQ,UAAU,KAC9B;GAEF,MAAMA,MAAoC;IACxC,MAAM;IACN,WAAW,OAAO;IAClB,WAAW,OAAO;IAClB,eAAe,OAAO;IACvB;AACD,QAAK,eAAe,IAAI;;AAG1B,OAAK,MAAM,OAAO,WAChB,MAAK,eAAe,IAAI;;CAI5B,AAAQ,eAAe,KAAyC;EAC9D,MAAM,MAAM,GAAG,IAAI,UAAU,GAAG,IAAI;EACpC,MAAM,OAAO,KAAK,aAAa,IAAI,IAAI;AACvC,MAAI,QAAQ,KACV,MAAK,aAAa,IAAI,KAAK,CAAC,IAA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,+BAA+B,IAChC;EACD,UAAU,CACR,kBAAkB;GAChB,SAAS;GACT,YAAY,EAAE,uCAAuC,IAAI;GACzD,UAAU;GACX,CAAC,CACH;EACF,CAAC;;AAGJ,SAAS,oCACP,KACa;AACb,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY;GACV,uBAAuB,IAAI;GAC3B,kCAAkC;GACnC;EACD,UAAU,CACR,sBAAsB,IAAI,SAAS,QAAQ,mBAAmB,GAAG,CAAC,CACnE;EACF,CAAC;;AAGJ,SAAS,kCACP,eACe;AACf,QAAO;EACL,gCAAgC;GAC9B,YAAY;GACZ,OAAO;GACP;GACD,CAAC;EACF,oCAAoC;EACpC,gCAAgC;GAC9B,YAAY;GACZ,OAAO;GACP;GACD,CAAC;EACF,oCAAoC;EACpC,gCAAgC;GAC9B,YAAY;GACZ,OAAO;GACP;GACD,CAAC;EACH;;AASH,SAAS,gCAAgC,EACvC,YACA,OACA,iBACoD;AACpD,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY;GACV,MAAM;GACN,8BAA8B;GAC9B,sCAAsC,GAAG;GAC1C;EACD,UAAU,CAAC,sBAAsB,MAAM,CAAC;EACzC,CAAC;;AAGJ,SAAS,qCAAkD;AACzD,QAAO,kBAAkB;EACvB,SAAS;EACT,YAAY,EAAE,wCAAwC,IAAI;EAC1D,UAAU,CAAC,sBAAsB,IAAI,CAAC;EACvC,CAAC"}
|
package/dist/ssr/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AnnotationLineMap, AnnotationSide, AnnotationSpan, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, ContextContent, CustomPreProperties, DecorationItem, DiffLineAnnotation, DiffLineEventBaseProps, DiffsHighlighter, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffMetadata, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MergeConflictActionPayload, MergeConflictRegion, MergeConflictResolution, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PrePropertiesConfig, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderMetadataCallback, RenderHeaderMetadataProps, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SupportedLanguages, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, VirtualFileMetrics, VirtualWindowSpecs } from "../types.js";
|
|
1
|
+
import { AnnotationLineMap, AnnotationSide, AnnotationSpan, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, ConflictResolverTypes, ContextContent, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffLineAnnotation, DiffLineEventBaseProps, DiffsHighlighter, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffMetadata, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PrePropertiesConfig, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderMetadataCallback, RenderHeaderMetadataProps, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SupportedLanguages, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, VirtualFileMetrics, VirtualWindowSpecs } from "../types.js";
|
|
2
2
|
import { PreloadDiffOptions, PreloadFileDiffOptions, PreloadFileDiffResult, PreloadMultiFileDiffOptions, PreloadMultiFileDiffResult, PreloadPatchDiffOptions, PreloadPatchDiffResult, PreloadUnresolvedFileOptions, PreloadUnresolvedFileResult, preloadDiffHTML, preloadFileDiff, preloadMultiFileDiff, preloadPatchDiff, preloadUnresolvedFile, preloadUnresolvedFileHTML } from "./preloadDiffs.js";
|
|
3
3
|
import { PreloadFileOptions, PreloadedFileResult, preloadFile } from "./preloadFile.js";
|
|
4
4
|
import { PreloadPatchFileOptions, preloadPatchFile } from "./preloadPatchFile.js";
|
|
5
5
|
import { renderHTML } from "./renderHTML.js";
|
|
6
|
-
export { AnnotationLineMap, AnnotationSide, AnnotationSpan, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, ContextContent, CustomPreProperties, DecorationItem, DiffLineAnnotation, DiffLineEventBaseProps, DiffsHighlighter, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffMetadata, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MergeConflictActionPayload, MergeConflictRegion, MergeConflictResolution, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PrePropertiesConfig, PreloadDiffOptions, PreloadFileDiffOptions, PreloadFileDiffResult, PreloadFileOptions, PreloadMultiFileDiffOptions, PreloadMultiFileDiffResult, PreloadPatchDiffOptions, PreloadPatchDiffResult, PreloadPatchFileOptions, PreloadUnresolvedFileOptions, PreloadUnresolvedFileResult, PreloadedFileResult, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderMetadataCallback, RenderHeaderMetadataProps, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SupportedLanguages, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, VirtualFileMetrics, VirtualWindowSpecs, preloadDiffHTML, preloadFile, preloadFileDiff, preloadMultiFileDiff, preloadPatchDiff, preloadPatchFile, preloadUnresolvedFile, preloadUnresolvedFileHTML, renderHTML };
|
|
6
|
+
export { AnnotationLineMap, AnnotationSide, AnnotationSpan, BaseCodeOptions, BaseDiffOptions, BaseDiffOptionsWithDefaults, BundledLanguage, ChangeContent, ChangeTypes, CodeColumnType, CodeToHastOptions, ConflictResolverTypes, ContextContent, CustomPreProperties, DecorationItem, DiffAcceptRejectHunkConfig, DiffAcceptRejectHunkType, DiffLineAnnotation, DiffLineEventBaseProps, DiffsHighlighter, DiffsThemeNames, ExpansionDirections, ExtensionFormatMap, FileContents, FileDiffMetadata, ForceDiffPlainTextOptions, ForceFilePlainTextOptions, GapSpan, HighlighterTypes, Hunk, HunkData, HunkExpansionRegion, HunkLineType, HunkSeparators, LanguageRegistration, LineAnnotation, LineDiffTypes, LineEventBaseProps, LineInfo, LineSpans, LineTypes, MergeConflictActionPayload, MergeConflictMarkerRow, MergeConflictMarkerRowType, MergeConflictRegion, MergeConflictResolution, ObservedAnnotationNodes, ObservedGridNodes, ParsedPatch, PrePropertiesConfig, PreloadDiffOptions, PreloadFileDiffOptions, PreloadFileDiffResult, PreloadFileOptions, PreloadMultiFileDiffOptions, PreloadMultiFileDiffResult, PreloadPatchDiffOptions, PreloadPatchDiffResult, PreloadPatchFileOptions, PreloadUnresolvedFileOptions, PreloadUnresolvedFileResult, PreloadedFileResult, ProcessFileConflictData, RenderDiffFilesResult, RenderDiffOptions, RenderDiffResult, RenderFileMetadata, RenderFileOptions, RenderFileResult, RenderHeaderMetadataCallback, RenderHeaderMetadataProps, RenderHeaderPrefixCallback, RenderRange, RenderWindow, RenderedDiffASTCache, RenderedFileASTCache, SelectionPoint, SelectionSide, SharedRenderState, ShikiTransformer, SupportedLanguages, ThemeRegistrationResolved, ThemeTypes, ThemedDiffResult, ThemedFileResult, ThemedToken, ThemesType, VirtualFileMetrics, VirtualWindowSpecs, preloadDiffHTML, preloadFile, preloadFileDiff, preloadMultiFileDiff, preloadPatchDiff, preloadPatchFile, preloadUnresolvedFile, preloadUnresolvedFileHTML, renderHTML };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DiffLineAnnotation, FileContents, FileDiffMetadata } from "../types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { UnresolvedFileOptions } from "../components/UnresolvedFile.js";
|
|
3
3
|
import { FileDiffOptions } from "../components/FileDiff.js";
|
|
4
4
|
|
|
5
5
|
//#region src/ssr/preloadDiffs.d.ts
|
|
@@ -52,7 +52,7 @@ declare function preloadFileDiff<LAnnotation = undefined>({
|
|
|
52
52
|
}: PreloadFileDiffOptions<LAnnotation>): Promise<PreloadFileDiffResult<LAnnotation>>;
|
|
53
53
|
interface PreloadUnresolvedFileOptions<LAnnotation> {
|
|
54
54
|
file: FileContents;
|
|
55
|
-
options?:
|
|
55
|
+
options?: Omit<UnresolvedFileOptions<LAnnotation>, 'onMergeConflictAction' | 'onMergeConflictResolve' | 'onPostRender'>;
|
|
56
56
|
annotations?: DiffLineAnnotation<LAnnotation>[];
|
|
57
57
|
}
|
|
58
58
|
interface PreloadUnresolvedFileResult<LAnnotation> extends PreloadUnresolvedFileOptions<LAnnotation> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preloadDiffs.d.ts","names":["FileDiffOptions","
|
|
1
|
+
{"version":3,"file":"preloadDiffs.d.ts","names":["FileDiffOptions","UnresolvedFileOptions","DiffLineAnnotation","FileContents","FileDiffMetadata","PreloadDiffOptions","LAnnotation","preloadDiffHTML","fileDiff","oldFile","newFile","options","annotations","Promise","preloadUnresolvedFileHTML","file","PreloadUnresolvedFileOptions","PreloadMultiFileDiffOptions","PreloadMultiFileDiffResult","preloadMultiFileDiff","PreloadFileDiffOptions","PreloadFileDiffResult","preloadFileDiff","Omit","PreloadUnresolvedFileResult","preloadUnresolvedFile","PreloadPatchDiffOptions","PreloadPatchDiffResult","preloadPatchDiff","patch"],"sources":["../../src/ssr/preloadDiffs.d.ts"],"sourcesContent":["import type { FileDiffOptions } from '../components/FileDiff';\nimport { type UnresolvedFileOptions } from '../components/UnresolvedFile';\nimport type { DiffLineAnnotation, FileContents, FileDiffMetadata } from '../types';\nexport interface PreloadDiffOptions<LAnnotation> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents;\n newFile?: FileContents;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\nexport declare function preloadDiffHTML<LAnnotation = undefined>({ fileDiff, oldFile, newFile, options, annotations }: PreloadDiffOptions<LAnnotation>): Promise<string>;\nexport declare function preloadUnresolvedFileHTML<LAnnotation = undefined>({ file, options, annotations }: PreloadUnresolvedFileOptions<LAnnotation>): Promise<string>;\nexport interface PreloadMultiFileDiffOptions<LAnnotation> {\n oldFile: FileContents;\n newFile: FileContents;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\nexport interface PreloadMultiFileDiffResult<LAnnotation> extends PreloadMultiFileDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\nexport declare function preloadMultiFileDiff<LAnnotation = undefined>({ oldFile, newFile, options, annotations }: PreloadMultiFileDiffOptions<LAnnotation>): Promise<PreloadMultiFileDiffResult<LAnnotation>>;\nexport interface PreloadFileDiffOptions<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\nexport interface PreloadFileDiffResult<LAnnotation> extends PreloadFileDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\nexport declare function preloadFileDiff<LAnnotation = undefined>({ fileDiff, options, annotations }: PreloadFileDiffOptions<LAnnotation>): Promise<PreloadFileDiffResult<LAnnotation>>;\nexport interface PreloadUnresolvedFileOptions<LAnnotation> {\n file: FileContents;\n options?: Omit<UnresolvedFileOptions<LAnnotation>, 'onMergeConflictAction' | 'onMergeConflictResolve' | 'onPostRender'>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\nexport interface PreloadUnresolvedFileResult<LAnnotation> extends PreloadUnresolvedFileOptions<LAnnotation> {\n prerenderedHTML: string;\n}\nexport declare function preloadUnresolvedFile<LAnnotation = undefined>({ file, options, annotations }: PreloadUnresolvedFileOptions<LAnnotation>): Promise<PreloadUnresolvedFileResult<LAnnotation>>;\nexport interface PreloadPatchDiffOptions<LAnnotation> {\n patch: string;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\nexport interface PreloadPatchDiffResult<LAnnotation> extends PreloadPatchDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\nexport declare function preloadPatchDiff<LAnnotation = undefined>({ patch, options, annotations }: PreloadPatchDiffOptions<LAnnotation>): Promise<PreloadPatchDiffResult<LAnnotation>>;\n//# sourceMappingURL=preloadDiffs.d.ts.map"],"mappings":";;;;;UAGiBK;aACFD;EADEC,OAAAA,CAAAA,EAEHF,YAFqB;EACpBC,OAAAA,CAAAA,EAEDD,YAFCC;EACDD,OAAAA,CAAAA,EAEAH,eAFAG,CAEgBG,WAFhBH,CAAAA;EACAA,WAAAA,CAAAA,EAEID,kBAFJC,CAEuBG,WAFvBH,CAAAA,EAAAA;;AACAH,iBAGUO,eAHVP,CAAAA,cAAAA,SAA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BE,UAwBlFe,sBAxBkFf,CAAAA,WAAAA,CAAAA,SAwBtCc,uBAxBsCd,CAwBdN,WAxBcM,CAAAA,CAAAA;EAA2CN,eAAAA,EAAAA,MAAAA;;AAAkDA,iBA2BxKsB,gBA3BwKtB,CAAAA,cAAAA,SAAAA,CAAAA,CAAAA;EAAAA,KAAAA;EAAAA,OAAAA;EAAAA;AAAAA,CAAAA,EA2B7FoB,uBA3B6FpB,CA2BrEA,WA3BqEA,CAAAA,CAAAA,EA2BtDO,OA3BsDP,CA2B9CqB,sBA3B8CrB,CA2BvBA,WA3BuBA,CAAAA,CAAAA"}
|
package/dist/ssr/preloadDiffs.js
CHANGED
|
@@ -2,6 +2,7 @@ import { DiffHunksRenderer } from "../renderers/DiffHunksRenderer.js";
|
|
|
2
2
|
import { parseDiffFromFile } from "../utils/parseDiffFromFile.js";
|
|
3
3
|
import { parseMergeConflictDiffFromFile } from "../utils/parseMergeConflictDiffFromFile.js";
|
|
4
4
|
import { UnresolvedFileHunksRenderer } from "../renderers/UnresolvedFileHunksRenderer.js";
|
|
5
|
+
import { getUnresolvedDiffHunksRendererOptions } from "../components/UnresolvedFile.js";
|
|
5
6
|
import { createStyleElement } from "../utils/createStyleElement.js";
|
|
6
7
|
import { getSingularPatch } from "../utils/getSingularPatch.js";
|
|
7
8
|
import { renderHTML } from "./renderHTML.js";
|
|
@@ -15,10 +16,10 @@ async function preloadDiffHTML({ fileDiff, oldFile, newFile, options, annotation
|
|
|
15
16
|
return renderHTML(processHunkResult(await renderer.asyncRender(fileDiff), renderer, options?.unsafeCSS));
|
|
16
17
|
}
|
|
17
18
|
async function preloadUnresolvedFileHTML({ file, options, annotations }) {
|
|
18
|
-
const { fileDiff, actions } = parseMergeConflictDiffFromFile(file);
|
|
19
|
-
const renderer = new UnresolvedFileHunksRenderer(options);
|
|
19
|
+
const { fileDiff, actions, markerRows } = parseMergeConflictDiffFromFile(file, options?.maxContextLines);
|
|
20
|
+
const renderer = new UnresolvedFileHunksRenderer(getUnresolvedDiffHunksRendererOptions(options));
|
|
20
21
|
if (annotations != null && annotations.length > 0) renderer.setLineAnnotations(annotations);
|
|
21
|
-
renderer.
|
|
22
|
+
renderer.setConflictState(actions, markerRows, fileDiff);
|
|
22
23
|
return renderHTML(processHunkResult(await renderer.asyncRender(fileDiff), renderer, options?.unsafeCSS));
|
|
23
24
|
}
|
|
24
25
|
async function preloadMultiFileDiff({ oldFile, newFile, options, annotations }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preloadDiffs.js","names":[],"sources":["../../src/ssr/preloadDiffs.ts"],"sourcesContent":["import type { FileDiffOptions } from '../components/FileDiff';\nimport {\n
|
|
1
|
+
{"version":3,"file":"preloadDiffs.js","names":[],"sources":["../../src/ssr/preloadDiffs.ts"],"sourcesContent":["import type { FileDiffOptions } from '../components/FileDiff';\nimport {\n getUnresolvedDiffHunksRendererOptions,\n type UnresolvedFileOptions,\n} from '../components/UnresolvedFile';\nimport {\n DiffHunksRenderer,\n type HunksRenderResult,\n} from '../renderers/DiffHunksRenderer';\nimport { UnresolvedFileHunksRenderer } from '../renderers/UnresolvedFileHunksRenderer';\nimport type {\n BaseDiffOptions,\n DiffLineAnnotation,\n FileContents,\n FileDiffMetadata,\n} from '../types';\nimport { createStyleElement } from '../utils/createStyleElement';\nimport { getSingularPatch } from '../utils/getSingularPatch';\nimport { parseDiffFromFile } from '../utils/parseDiffFromFile';\nimport { parseMergeConflictDiffFromFile } from '../utils/parseMergeConflictDiffFromFile';\nimport { renderHTML } from './renderHTML';\n\nexport interface PreloadDiffOptions<LAnnotation> {\n fileDiff?: FileDiffMetadata;\n oldFile?: FileContents;\n newFile?: FileContents;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport async function preloadDiffHTML<LAnnotation = undefined>({\n fileDiff,\n oldFile,\n newFile,\n options,\n annotations,\n}: PreloadDiffOptions<LAnnotation>): Promise<string> {\n if (fileDiff == null && oldFile != null && newFile != null) {\n fileDiff = parseDiffFromFile(oldFile, newFile);\n }\n if (fileDiff == null) {\n throw new Error(\n 'preloadFileDiff: You must pass at least a fileDiff prop or oldFile/newFile props'\n );\n }\n const renderer = new DiffHunksRenderer<LAnnotation>(\n getHunksRendererOptions(options)\n );\n if (annotations != null && annotations.length > 0) {\n renderer.setLineAnnotations(annotations);\n }\n return renderHTML(\n processHunkResult(\n await renderer.asyncRender(fileDiff),\n renderer,\n options?.unsafeCSS\n )\n );\n}\n\nexport async function preloadUnresolvedFileHTML<LAnnotation = undefined>({\n file,\n options,\n annotations,\n}: PreloadUnresolvedFileOptions<LAnnotation>): Promise<string> {\n const { fileDiff, actions, markerRows } = parseMergeConflictDiffFromFile(\n file,\n options?.maxContextLines\n );\n const renderer = new UnresolvedFileHunksRenderer<LAnnotation>(\n getUnresolvedDiffHunksRendererOptions(options)\n );\n if (annotations != null && annotations.length > 0) {\n renderer.setLineAnnotations(annotations);\n }\n renderer.setConflictState(actions, markerRows, fileDiff);\n return renderHTML(\n processHunkResult(\n await renderer.asyncRender(fileDiff),\n renderer,\n options?.unsafeCSS\n )\n );\n}\n\nexport interface PreloadMultiFileDiffOptions<LAnnotation> {\n oldFile: FileContents;\n newFile: FileContents;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadMultiFileDiffResult<\n LAnnotation,\n> extends PreloadMultiFileDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadMultiFileDiff<LAnnotation = undefined>({\n oldFile,\n newFile,\n options,\n annotations,\n}: PreloadMultiFileDiffOptions<LAnnotation>): Promise<\n PreloadMultiFileDiffResult<LAnnotation>\n> {\n return {\n newFile,\n oldFile,\n options,\n annotations,\n prerenderedHTML: await preloadDiffHTML({\n oldFile,\n newFile,\n options,\n annotations,\n }),\n };\n}\n\nexport interface PreloadFileDiffOptions<LAnnotation> {\n fileDiff: FileDiffMetadata;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadFileDiffResult<\n LAnnotation,\n> extends PreloadFileDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadFileDiff<LAnnotation = undefined>({\n fileDiff,\n options,\n annotations,\n}: PreloadFileDiffOptions<LAnnotation>): Promise<\n PreloadFileDiffResult<LAnnotation>\n> {\n return {\n fileDiff,\n options,\n annotations,\n prerenderedHTML: await preloadDiffHTML({\n fileDiff,\n options,\n annotations,\n }),\n };\n}\n\nexport interface PreloadUnresolvedFileOptions<LAnnotation> {\n file: FileContents;\n options?: Omit<\n UnresolvedFileOptions<LAnnotation>,\n 'onMergeConflictAction' | 'onMergeConflictResolve' | 'onPostRender'\n >;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadUnresolvedFileResult<\n LAnnotation,\n> extends PreloadUnresolvedFileOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadUnresolvedFile<LAnnotation = undefined>({\n file,\n options,\n annotations,\n}: PreloadUnresolvedFileOptions<LAnnotation>): Promise<\n PreloadUnresolvedFileResult<LAnnotation>\n> {\n return {\n file,\n options,\n annotations,\n prerenderedHTML: await preloadUnresolvedFileHTML({\n file,\n options,\n annotations,\n }),\n };\n}\n\nexport interface PreloadPatchDiffOptions<LAnnotation> {\n patch: string;\n options?: FileDiffOptions<LAnnotation>;\n annotations?: DiffLineAnnotation<LAnnotation>[];\n}\n\nexport interface PreloadPatchDiffResult<\n LAnnotation,\n> extends PreloadPatchDiffOptions<LAnnotation> {\n prerenderedHTML: string;\n}\n\nexport async function preloadPatchDiff<LAnnotation = undefined>({\n patch,\n options,\n annotations,\n}: PreloadPatchDiffOptions<LAnnotation>): Promise<\n PreloadPatchDiffResult<LAnnotation>\n> {\n const fileDiff = getSingularPatch(patch);\n return {\n patch,\n options,\n annotations,\n prerenderedHTML: await preloadDiffHTML({\n fileDiff,\n options,\n annotations,\n }),\n };\n}\n\nfunction processHunkResult<LAnnotation>(\n hunkResult: HunksRenderResult,\n renderer:\n | DiffHunksRenderer<LAnnotation>\n | UnresolvedFileHunksRenderer<LAnnotation>,\n unsafeCSS: string | undefined\n) {\n const children = [createStyleElement(hunkResult.css, true)];\n if (unsafeCSS != null) {\n children.push(createStyleElement(unsafeCSS));\n }\n if (hunkResult.headerElement != null) {\n children.push(hunkResult.headerElement);\n }\n const code = renderer.renderFullAST(hunkResult);\n code.properties['data-dehydrated'] = '';\n children.push(code);\n return children;\n}\n\nfunction getHunksRendererOptions<LAnnotation>(\n options: FileDiffOptions<LAnnotation> | undefined\n): BaseDiffOptions {\n return {\n ...options,\n hunkSeparators:\n typeof options?.hunkSeparators === 'function'\n ? 'custom'\n : options?.hunkSeparators,\n };\n}\n"],"mappings":";;;;;;;;;;AA8BA,eAAsB,gBAAyC,EAC7D,UACA,SACA,SACA,SACA,eACmD;AACnD,KAAI,YAAY,QAAQ,WAAW,QAAQ,WAAW,KACpD,YAAW,kBAAkB,SAAS,QAAQ;AAEhD,KAAI,YAAY,KACd,OAAM,IAAI,MACR,mFACD;CAEH,MAAM,WAAW,IAAI,kBACnB,wBAAwB,QAAQ,CACjC;AACD,KAAI,eAAe,QAAQ,YAAY,SAAS,EAC9C,UAAS,mBAAmB,YAAY;AAE1C,QAAO,WACL,kBACE,MAAM,SAAS,YAAY,SAAS,EACpC,UACA,SAAS,UACV,CACF;;AAGH,eAAsB,0BAAmD,EACvE,MACA,SACA,eAC6D;CAC7D,MAAM,EAAE,UAAU,SAAS,eAAe,+BACxC,MACA,SAAS,gBACV;CACD,MAAM,WAAW,IAAI,4BACnB,sCAAsC,QAAQ,CAC/C;AACD,KAAI,eAAe,QAAQ,YAAY,SAAS,EAC9C,UAAS,mBAAmB,YAAY;AAE1C,UAAS,iBAAiB,SAAS,YAAY,SAAS;AACxD,QAAO,WACL,kBACE,MAAM,SAAS,YAAY,SAAS,EACpC,UACA,SAAS,UACV,CACF;;AAg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