-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
974da75
commit 48d3ebb
Showing
11 changed files
with
689 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { computed, defineComponent, ref } from "vue"; | ||
|
||
import { SplitSide } from ".."; | ||
import { useExtendData, useSlots } from "../context"; | ||
import { useDomWidth } from "../hooks/useDomWidth"; | ||
import { useSubscribeDiffFile } from "../hooks/useSubscribeDiffFile"; | ||
|
||
import type { DiffFileExtends } from "../utils"; | ||
|
||
export const DiffUnifiedExtendLine = defineComponent( | ||
(props: { index: number; diffFile: DiffFileExtends; lineNumber: number }) => { | ||
const extendData = useExtendData(); | ||
|
||
const slots = useSlots(); | ||
|
||
const unifiedItem = ref(props.diffFile.getUnifiedLine(props.index)); | ||
|
||
const oldExtend = ref(extendData.value?.oldFile?.[unifiedItem.value.oldLineNumber]); | ||
|
||
const newExtend = ref(extendData.value?.newFile?.[unifiedItem.value.newLineNumber]); | ||
|
||
useSubscribeDiffFile(props, (diffFile) => { | ||
unifiedItem.value = diffFile.getUnifiedLine(props.index); | ||
}); | ||
|
||
useSubscribeDiffFile(props, () => (oldExtend.value = extendData.value?.oldFile?.[unifiedItem.value.oldLineNumber])); | ||
|
||
useSubscribeDiffFile(props, () => (newExtend.value = extendData.value?.newFile?.[unifiedItem.value.newLineNumber])); | ||
|
||
const currentIsShow = computed(() => | ||
Boolean((oldExtend.value || newExtend.value) && unifiedItem.value && !unifiedItem.value.isHidden && unifiedItem.value.diff) | ||
); | ||
|
||
const width = useDomWidth({ | ||
selector: ref(".unified-diff-table-wrapper"), | ||
enable: currentIsShow, | ||
}); | ||
|
||
return () => { | ||
if (!currentIsShow.value) return null; | ||
|
||
return ( | ||
<tr data-line={`${props.lineNumber}-extend`} data-state="extend" class="diff-line diff-line-extend"> | ||
<td class="diff-line-extend-content align-top p-0" colspan={4}> | ||
<div class="diff-line-extend-wrapper sticky left-0" style={{ width: width.value + "px" }}> | ||
{width.value > 0 && | ||
oldExtend.value && | ||
slots.extend({ | ||
diffFile: props.diffFile, | ||
side: SplitSide.old, | ||
lineNumber: unifiedItem.value.oldLineNumber, | ||
data: oldExtend.value.data, | ||
onUpdate: props.diffFile.notifyAll, | ||
})} | ||
{width.value > 0 && | ||
newExtend.value && | ||
slots.extend({ | ||
diffFile: props.diffFile, | ||
side: SplitSide.new, | ||
lineNumber: unifiedItem.value.newLineNumber, | ||
data: newExtend.value.data, | ||
onUpdate: props.diffFile.notifyAll, | ||
})} | ||
</div> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
}, | ||
{ name: "DiffUnifiedExtendLine", props: ["diffFile", "index", "lineNumber"] } | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { composeLen } from "@git-diff-view/core"; | ||
import { defineComponent, ref } from "vue"; | ||
|
||
import { useEnableWrap } from "../context"; | ||
import { useSubscribeDiffFile } from "../hooks/useSubscribeDiffFile"; | ||
|
||
import { hunkContentBGName, hunkLineNumberBGName, plainLineNumberColorName } from "./color"; | ||
import { ExpandAll, ExpandDown, ExpandUp } from "./DiffExpand"; | ||
|
||
import type { DiffFile } from "@git-diff-view/core"; | ||
|
||
export const DiffUnifiedHunkLine = defineComponent( | ||
(props: { index: number; diffFile: DiffFile; lineNumber: number }) => { | ||
const currentHunk = ref(props.diffFile.getUnifiedHunkLine(props.index)); | ||
|
||
const enableWrap = useEnableWrap(); | ||
|
||
const currentIsShow = ref(currentHunk.value && currentHunk.value.unifiedInfo.startHiddenIndex < currentHunk.value.unifiedInfo.endHiddenIndex); | ||
|
||
const currentIsEnableAll = ref( | ||
currentHunk.value && currentHunk.value.unifiedInfo.endHiddenIndex - currentHunk.value.unifiedInfo.startHiddenIndex < composeLen | ||
); | ||
|
||
useSubscribeDiffFile(props, (diffFile) => (currentHunk.value = diffFile.getUnifiedHunkLine(props.index))); | ||
|
||
useSubscribeDiffFile( | ||
props, | ||
() => (currentIsShow.value = currentHunk.value && currentHunk.value.unifiedInfo.startHiddenIndex < currentHunk.value.unifiedInfo.endHiddenIndex) | ||
); | ||
|
||
useSubscribeDiffFile( | ||
props, | ||
() => | ||
(currentIsEnableAll.value = | ||
currentHunk.value && currentHunk.value.unifiedInfo.endHiddenIndex - currentHunk.value.unifiedInfo.startHiddenIndex < composeLen) | ||
); | ||
|
||
return () => { | ||
if (!currentIsShow.value) return null; | ||
|
||
return ( | ||
<tr | ||
data-line={`${props.lineNumber}-hunk`} | ||
data-state="hunk" | ||
class="diff-line diff-line-hunk select-none" | ||
style={{ backgroundColor: `var(${hunkContentBGName})` }} | ||
> | ||
<td | ||
class="diff-line-num diff-line-num-hunk left-0 text-left select-none w-[1%] min-w-[60px] whitespace-nowrap z-[1]" | ||
style={{ | ||
position: enableWrap.value ? "relative" : "sticky", | ||
backgroundColor: `var(${hunkLineNumberBGName})`, | ||
color: `var(${plainLineNumberColorName})`, | ||
}} | ||
> | ||
{currentIsEnableAll.value ? ( | ||
<button | ||
class="w-full hover:bg-blue-300 flex justify-center items-center py-[6px] cursor-pointer rounded-[2px]" | ||
title="Expand All" | ||
onClick={() => props.diffFile.onUnifiedHunkExpand("all", props.index)} | ||
> | ||
<ExpandAll className="fill-current" /> | ||
</button> | ||
) : ( | ||
<> | ||
<button | ||
class="w-full hover:bg-blue-300 flex justify-center items-center py-[2px] cursor-pointer rounded-[2px]" | ||
title="Expand Down" | ||
onClick={() => props.diffFile.onUnifiedHunkExpand("down", props.index)} | ||
> | ||
<ExpandDown className="fill-current" /> | ||
</button> | ||
<button | ||
class="w-full hover:bg-blue-300 flex justify-center items-center py-[2px] cursor-pointer rounded-[2px]" | ||
title="Expand Up" | ||
onClick={() => props.diffFile.onUnifiedHunkExpand("up", props.index)} | ||
> | ||
<ExpandUp className="fill-current" /> | ||
</button> | ||
</> | ||
)} | ||
</td> | ||
<td class="diff-line-content diff-line-content-hunk pr-[10px] align-middle"> | ||
<div | ||
class="opacity-[0.5] pl-[1.5em]" | ||
style={{ | ||
whiteSpace: enableWrap.value ? "pre-wrap" : "pre", | ||
wordBreak: enableWrap.value ? "break-all" : "initial", | ||
}} | ||
> | ||
{currentHunk.value.unifiedInfo.plainText} | ||
</div> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
}, | ||
{ name: "DiffUnifiedHunkLine", props: ["index", "diffFile", "lineNumber"] } | ||
); | ||
|
||
export const DiffUnifiedExpandLastLine = defineComponent( | ||
(props: { diffFile: DiffFile }) => { | ||
const currentIsShow = ref(props.diffFile.getNeedShowExpandAll("unified")); | ||
|
||
const enableWrap = useEnableWrap(); | ||
|
||
useSubscribeDiffFile(props, (diffFile) => (currentIsShow.value = diffFile.getNeedShowExpandAll("unified"))); | ||
|
||
return () => { | ||
if (!currentIsShow.value) return null; | ||
|
||
return ( | ||
<tr data-line="last-hunk" data-state="hunk" class="diff-line diff-line-hunk select-none" style={{ backgroundColor: `var(${hunkContentBGName})` }}> | ||
<td | ||
class="diff-line-num diff-line-num-hunk left-0 text-left select-none w-[1%] min-w-[60px] whitespace-nowrap" | ||
style={{ | ||
position: enableWrap.value ? "relative" : "sticky", | ||
backgroundColor: `var(${hunkLineNumberBGName})`, | ||
color: `var(${plainLineNumberColorName})`, | ||
}} | ||
> | ||
<button | ||
class="w-full hover:bg-blue-300 flex justify-center items-center py-[2px] cursor-pointer rounded-[2px]" | ||
title="Expand Down" | ||
onClick={() => props.diffFile.onUnifiedLastExpand()} | ||
> | ||
<ExpandDown className="fill-current" /> | ||
</button> | ||
</td> | ||
<td class="diff-line-content diff-line-content-hunk pr-[10px] align-middle" /> | ||
</tr> | ||
); | ||
}; | ||
}, | ||
{ name: "DiffUnifiedExpandLastLine", props: ["diffFile"] } | ||
); |
Oops, something went wrong.