2022-09-27 10:52:19 +05:30
|
|
|
<template>
|
Use a general approach to show tooltip, fix temporary tooltip bug (#23574)
## TLDR
* Improve performance: lazy creating the tippy instances.
* Transparently support all "tooltip" elements, no need to call
`initTooltip` again and again.
* Fix a temporary tooltip re-entrance bug, which causes showing temp
content forever.
* Upgrade vue3-calendar-heatmap to 2.0.2 with lazy tippy init
(initHeatmap time decreases from 100ms to 50ms)
## Details
### The performance
Creating a lot of tippy tooltip instances is expensive. This PR doesn't
create all tippy tooltip instances, instead, it only adds "mouseover"
event listener to necessary elements, and then switches to the tippy
tooltip
### The general approach for all tooltips
Before, dynamically generated tooltips need to be called with
`initTooltip`.
After, use MutationObserver to:
* Attach the event listeners to newly created tooltip elements, work for
Vue (easier than before)
* Catch changed attributes and update the tooltip content (better than
before)
It does help a lot, eg:
https://github.com/go-gitea/gitea/blob/1a4efa0ee9a49d48549be7479a46be133b9bc260/web_src/js/components/PullRequestMergeForm.vue#L33-L36
### Temporary tooltip re-entrance bug
To reproduce, on try.gitea.io, click the "copy clone url" quickly, then
the tooltip will be "Copied!" forever.
After this PR, with the help of `attachTippyTooltip`, the tooltip
content could be reset to the default correctly.
### Other changes
* `data-tooltip-content` is preferred from now on, the old
`data-content` may cause conflicts with other modules.
* `data-placement` was only used for tooltip, so it's renamed to
`data-tooltip-placement`, and removed from `createTippy`.
2023-03-23 15:26:15 +05:30
|
|
|
<div v-show="show" :title="item.name">
|
2023-02-16 11:27:25 +05:30
|
|
|
<!--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"-->
|
2023-04-07 23:57:10 +05:30
|
|
|
<div class="item" :class="[item.isFile ? 'filewrapper gt-p-1 gt-ac' : '', selectedFile === genCompleteFileHash(item.file?.NameHash) ? 'selected' : '']">
|
2022-09-27 10:52:19 +05:30
|
|
|
<!-- Files -->
|
|
|
|
<SvgIcon
|
|
|
|
v-if="item.isFile"
|
|
|
|
name="octicon-file"
|
|
|
|
class="svg-icon file"
|
|
|
|
/>
|
|
|
|
<a
|
|
|
|
v-if="item.isFile"
|
2023-03-30 17:36:10 +05:30
|
|
|
class="file gt-ellipsis"
|
2022-09-27 10:52:19 +05:30
|
|
|
:href="item.isFile ? '#diff-' + item.file.NameHash : ''"
|
|
|
|
>{{ item.name }}</a>
|
|
|
|
<SvgIcon
|
|
|
|
v-if="item.isFile"
|
|
|
|
:name="getIconForDiffType(item.file.Type)"
|
|
|
|
:class="['svg-icon', getIconForDiffType(item.file.Type), 'status']"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<!-- Directories -->
|
2023-03-30 17:36:10 +05:30
|
|
|
<div v-if="!item.isFile" class="directory gt-p-1 gt-ac" @click.stop="handleClick(item.isFile)">
|
2022-09-27 10:52:19 +05:30
|
|
|
<SvgIcon
|
|
|
|
class="svg-icon"
|
|
|
|
:name="collapsed ? 'octicon-chevron-right' : 'octicon-chevron-down'"
|
|
|
|
/>
|
|
|
|
<SvgIcon
|
|
|
|
class="svg-icon directory"
|
|
|
|
name="octicon-file-directory-fill"
|
|
|
|
/>
|
2023-02-13 23:29:59 +05:30
|
|
|
<span class="gt-ellipsis">{{ item.name }}</span>
|
2022-09-27 10:52:19 +05:30
|
|
|
</div>
|
|
|
|
<div v-show="!collapsed">
|
2023-04-07 23:57:10 +05:30
|
|
|
<DiffFileTreeItem v-for="childItem in item.children" :key="childItem.name" :item="childItem" class="list" :selected-file="selectedFile"/>
|
2022-09-27 10:52:19 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import {SvgIcon} from '../svg.js';
|
|
|
|
|
|
|
|
export default {
|
2022-12-23 21:33:11 +05:30
|
|
|
components: {SvgIcon},
|
2022-09-27 10:52:19 +05:30
|
|
|
props: {
|
|
|
|
item: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
show: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true
|
2023-04-07 23:57:10 +05:30
|
|
|
},
|
|
|
|
selectedFile: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
required: true
|
2022-09-27 10:52:19 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
data: () => ({
|
|
|
|
collapsed: false,
|
|
|
|
}),
|
|
|
|
methods: {
|
|
|
|
handleClick(itemIsFile) {
|
|
|
|
if (itemIsFile) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-12 08:04:46 +05:30
|
|
|
this.collapsed = !this.collapsed;
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
|
|
|
getIconForDiffType(pType) {
|
|
|
|
const diffTypes = {
|
|
|
|
1: 'octicon-diff-added',
|
|
|
|
2: 'octicon-diff-modified',
|
|
|
|
3: 'octicon-diff-removed',
|
|
|
|
4: 'octicon-diff-renamed',
|
|
|
|
5: 'octicon-diff-modified', // there is no octicon for copied, so modified should be ok
|
|
|
|
};
|
|
|
|
return diffTypes[pType];
|
|
|
|
},
|
2023-04-07 23:57:10 +05:30
|
|
|
genCompleteFileHash(hash) {
|
|
|
|
return `#diff-${hash}`;
|
|
|
|
}
|
2022-09-27 10:52:19 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2023-03-30 17:36:10 +05:30
|
|
|
.svg-icon.status {
|
2022-09-27 10:52:19 +05:30
|
|
|
float: right;
|
|
|
|
}
|
2023-02-12 08:04:46 +05:30
|
|
|
|
2023-03-30 17:36:10 +05:30
|
|
|
.svg-icon.file {
|
2022-09-27 10:52:19 +05:30
|
|
|
color: var(--color-secondary-dark-7);
|
|
|
|
}
|
|
|
|
|
2023-03-30 17:36:10 +05:30
|
|
|
.svg-icon.directory {
|
2022-09-27 10:52:19 +05:30
|
|
|
color: var(--color-primary);
|
|
|
|
}
|
|
|
|
|
2023-03-30 17:36:10 +05:30
|
|
|
.svg-icon.octicon-diff-modified {
|
2022-09-27 10:52:19 +05:30
|
|
|
color: var(--color-yellow);
|
|
|
|
}
|
|
|
|
|
2023-03-30 17:36:10 +05:30
|
|
|
.svg-icon.octicon-diff-added {
|
2022-09-27 10:52:19 +05:30
|
|
|
color: var(--color-green);
|
|
|
|
}
|
|
|
|
|
2023-03-30 17:36:10 +05:30
|
|
|
.svg-icon.octicon-diff-removed {
|
2022-09-27 10:52:19 +05:30
|
|
|
color: var(--color-red);
|
|
|
|
}
|
|
|
|
|
2023-03-30 17:36:10 +05:30
|
|
|
.svg-icon.octicon-diff-renamed {
|
2022-09-27 10:52:19 +05:30
|
|
|
color: var(--color-teal);
|
|
|
|
}
|
|
|
|
|
|
|
|
.item.filewrapper {
|
|
|
|
display: grid !important;
|
|
|
|
grid-template-columns: 20px 7fr 1fr;
|
|
|
|
padding-left: 18px !important;
|
|
|
|
}
|
|
|
|
|
2023-04-07 23:57:10 +05:30
|
|
|
.item.filewrapper:hover, div.directory:hover {
|
2022-09-27 10:52:19 +05:30
|
|
|
color: var(--color-text);
|
|
|
|
background: var(--color-hover);
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
|
2023-04-07 23:57:10 +05:30
|
|
|
.item.filewrapper.selected {
|
|
|
|
color: var(--color-text);
|
|
|
|
background: var(--color-active);
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
|
2022-09-27 10:52:19 +05:30
|
|
|
div.directory {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: 18px 20px auto;
|
2023-02-12 08:04:46 +05:30
|
|
|
user-select: none;
|
|
|
|
cursor: pointer;
|
2022-09-27 10:52:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
div.list {
|
|
|
|
padding-bottom: 0 !important;
|
|
|
|
padding-top: inherit !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
a {
|
|
|
|
text-decoration: none;
|
2023-03-30 17:36:10 +05:30
|
|
|
color: var(--color-text);
|
2022-09-27 10:52:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
a:hover {
|
|
|
|
text-decoration: none;
|
2023-03-30 17:36:10 +05:30
|
|
|
color: var(--color-text);
|
2022-09-27 10:52:19 +05:30
|
|
|
}
|
|
|
|
</style>
|