2024-10-28 21:15:05 +01:00
|
|
|
<script lang="ts" setup>
|
2025-01-22 08:11:51 +01:00
|
|
|
import {SvgIcon, type SvgName} from '../svg.ts';
|
2024-07-07 17:32:30 +02:00
|
|
|
import {diffTreeStore} from '../modules/stores.ts';
|
2024-10-28 21:15:05 +01:00
|
|
|
import {ref} from 'vue';
|
2025-02-27 16:58:25 -08:00
|
|
|
import type {Item, File, FileStatus} from '../utils/filetree.ts';
|
2024-10-28 21:15:05 +01:00
|
|
|
|
|
|
|
defineProps<{
|
|
|
|
item: Item,
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const store = diffTreeStore();
|
|
|
|
const collapsed = ref(false);
|
|
|
|
|
2025-02-27 16:58:25 -08:00
|
|
|
function getIconForDiffStatus(pType: FileStatus) {
|
|
|
|
const diffTypes: Record<FileStatus, { name: SvgName, classes: Array<string> }> = {
|
|
|
|
'added': {name: 'octicon-diff-added', classes: ['text', 'green']},
|
|
|
|
'modified': {name: 'octicon-diff-modified', classes: ['text', 'yellow']},
|
|
|
|
'deleted': {name: 'octicon-diff-removed', classes: ['text', 'red']},
|
|
|
|
'renamed': {name: 'octicon-diff-renamed', classes: ['text', 'teal']},
|
|
|
|
'copied': {name: 'octicon-diff-renamed', classes: ['text', 'green']},
|
|
|
|
'typechange': {name: 'octicon-diff-modified', classes: ['text', 'green']}, // there is no octicon for copied, so renamed should be ok
|
2024-10-28 21:15:05 +01:00
|
|
|
};
|
2025-02-27 16:58:25 -08:00
|
|
|
return diffTypes[pType];
|
2024-10-28 21:15:05 +01:00
|
|
|
}
|
2025-01-07 19:38:30 -06:00
|
|
|
|
2025-01-15 21:26:17 +01:00
|
|
|
function fileIcon(file: File) {
|
2025-01-07 19:38:30 -06:00
|
|
|
if (file.IsSubmodule) {
|
|
|
|
return 'octicon-file-submodule';
|
|
|
|
}
|
|
|
|
return 'octicon-file';
|
|
|
|
}
|
2022-09-27 07:22:19 +02:00
|
|
|
</script>
|
2024-10-28 21:15:05 +01:00
|
|
|
|
2023-09-02 16:59:07 +02:00
|
|
|
<template>
|
|
|
|
<!--title instead of tooltip above as the tooltip needs too much work with the current methods, i.e. not being loaded or staying open for "too long"-->
|
|
|
|
<a
|
|
|
|
v-if="item.isFile" class="item-file"
|
2025-02-27 16:58:25 -08:00
|
|
|
:class="{ 'selected': store.selectedItem === '#diff-' + item.file.NameHash, 'viewed': item.file.IsViewed }"
|
2023-09-02 16:59:07 +02:00
|
|
|
:title="item.name" :href="'#diff-' + item.file.NameHash"
|
|
|
|
>
|
|
|
|
<!-- file -->
|
2025-01-07 19:38:30 -06:00
|
|
|
<SvgIcon :name="fileIcon(item.file)"/>
|
2024-03-22 14:45:10 +01:00
|
|
|
<span class="gt-ellipsis tw-flex-1">{{ item.name }}</span>
|
2025-02-27 16:58:25 -08:00
|
|
|
<SvgIcon
|
|
|
|
:name="getIconForDiffStatus(item.file.Status).name"
|
|
|
|
:class="getIconForDiffStatus(item.file.Status).classes"
|
|
|
|
/>
|
2023-09-02 16:59:07 +02:00
|
|
|
</a>
|
2022-09-27 07:22:19 +02:00
|
|
|
|
2025-02-27 16:58:25 -08:00
|
|
|
<template v-else-if="item.isFile === false">
|
|
|
|
<div class="item-directory" :title="item.name" @click.stop="collapsed = !collapsed">
|
|
|
|
<!-- directory -->
|
|
|
|
<SvgIcon :name="collapsed ? 'octicon-chevron-right' : 'octicon-chevron-down'"/>
|
|
|
|
<SvgIcon
|
|
|
|
class="text primary"
|
|
|
|
:name="collapsed ? 'octicon-file-directory-fill' : 'octicon-file-directory-open-fill'"
|
|
|
|
/>
|
|
|
|
<span class="gt-ellipsis">{{ item.name }}</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-show="!collapsed" class="sub-items">
|
|
|
|
<DiffFileTreeItem v-for="childItem in item.children" :key="childItem.name" :item="childItem"/>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-09-02 16:59:07 +02:00
|
|
|
</template>
|
2022-09-27 07:22:19 +02:00
|
|
|
<style scoped>
|
2025-02-27 16:58:25 -08:00
|
|
|
a,
|
|
|
|
a:hover {
|
2023-08-19 03:55:56 +08:00
|
|
|
text-decoration: none;
|
|
|
|
color: var(--color-text);
|
2022-09-27 07:22:19 +02:00
|
|
|
}
|
|
|
|
|
2023-08-19 03:55:56 +08:00
|
|
|
.sub-items {
|
2023-10-21 12:38:19 +02:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: 1px;
|
2023-10-25 18:00:53 +08:00
|
|
|
margin-left: 13px;
|
|
|
|
border-left: 1px solid var(--color-secondary);
|
2022-09-27 07:22:19 +02:00
|
|
|
}
|
|
|
|
|
2023-10-21 12:38:19 +02:00
|
|
|
.sub-items .item-file {
|
2023-10-25 18:00:53 +08:00
|
|
|
padding-left: 18px;
|
2022-09-27 07:22:19 +02:00
|
|
|
}
|
|
|
|
|
2023-08-19 03:55:56 +08:00
|
|
|
.item-file.selected {
|
2023-04-08 02:27:10 +08:00
|
|
|
color: var(--color-text);
|
|
|
|
background: var(--color-active);
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
|
2023-08-19 03:55:56 +08:00
|
|
|
.item-file.viewed {
|
|
|
|
color: var(--color-text-light-3);
|
2022-09-27 07:22:19 +02:00
|
|
|
}
|
|
|
|
|
2024-11-28 13:25:21 +01:00
|
|
|
.item-directory {
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
|
2023-08-19 03:55:56 +08:00
|
|
|
.item-file,
|
|
|
|
.item-directory {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 0.25em;
|
2024-11-28 13:25:21 +01:00
|
|
|
padding: 6px;
|
2022-09-27 07:22:19 +02:00
|
|
|
}
|
|
|
|
|
2023-08-19 03:55:56 +08:00
|
|
|
.item-file:hover,
|
|
|
|
.item-directory:hover {
|
2023-03-30 14:06:10 +02:00
|
|
|
color: var(--color-text);
|
2023-08-19 03:55:56 +08:00
|
|
|
background: var(--color-hover);
|
|
|
|
border-radius: 4px;
|
|
|
|
cursor: pointer;
|
2023-06-25 02:46:30 +02:00
|
|
|
}
|
2022-09-27 07:22:19 +02:00
|
|
|
</style>
|