2022-09-27 05:22:19 +00:00
|
|
|
<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 09:56:15 +00:00
|
|
|
<div v-show="show" :title="item.name">
|
2023-02-16 05:57:25 +00:00
|
|
|
<!--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-02-13 17:59:59 +00:00
|
|
|
<div class="item" :class="item.isFile ? 'filewrapper gt-p-1' : ''">
|
2022-09-27 05:22:19 +00:00
|
|
|
<!-- Files -->
|
|
|
|
<SvgIcon
|
|
|
|
v-if="item.isFile"
|
|
|
|
name="octicon-file"
|
|
|
|
class="svg-icon file"
|
|
|
|
/>
|
|
|
|
<a
|
|
|
|
v-if="item.isFile"
|
2023-02-13 17:59:59 +00:00
|
|
|
class="file gt-ellipsis muted"
|
2022-09-27 05:22:19 +00:00
|
|
|
: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-02-13 17:59:59 +00:00
|
|
|
<div v-if="!item.isFile" class="directory gt-p-1" @click.stop="handleClick(item.isFile)">
|
2022-09-27 05:22:19 +00:00
|
|
|
<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 17:59:59 +00:00
|
|
|
<span class="gt-ellipsis">{{ item.name }}</span>
|
2022-09-27 05:22:19 +00:00
|
|
|
</div>
|
|
|
|
<div v-show="!collapsed">
|
|
|
|
<DiffFileTreeItem v-for="childItem in item.children" :key="childItem.name" :item="childItem" class="list" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import {SvgIcon} from '../svg.js';
|
|
|
|
|
|
|
|
export default {
|
2022-12-23 16:03:11 +00:00
|
|
|
components: {SvgIcon},
|
2022-09-27 05:22:19 +00:00
|
|
|
props: {
|
|
|
|
item: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
show: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data: () => ({
|
|
|
|
collapsed: false,
|
|
|
|
}),
|
|
|
|
methods: {
|
|
|
|
handleClick(itemIsFile) {
|
|
|
|
if (itemIsFile) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-12 02:34:46 +00:00
|
|
|
this.collapsed = !this.collapsed;
|
2022-09-27 05:22:19 +00:00
|
|
|
},
|
|
|
|
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];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
span.svg-icon.status {
|
|
|
|
float: right;
|
|
|
|
}
|
2023-02-12 02:34:46 +00:00
|
|
|
|
2022-09-27 05:22:19 +00:00
|
|
|
span.svg-icon.file {
|
|
|
|
color: var(--color-secondary-dark-7);
|
|
|
|
}
|
|
|
|
|
|
|
|
span.svg-icon.directory {
|
|
|
|
color: var(--color-primary);
|
|
|
|
}
|
|
|
|
|
|
|
|
span.svg-icon.octicon-diff-modified {
|
|
|
|
color: var(--color-yellow);
|
|
|
|
}
|
|
|
|
|
|
|
|
span.svg-icon.octicon-diff-added {
|
|
|
|
color: var(--color-green);
|
|
|
|
}
|
|
|
|
|
|
|
|
span.svg-icon.octicon-diff-removed {
|
|
|
|
color: var(--color-red);
|
|
|
|
}
|
|
|
|
|
|
|
|
span.svg-icon.octicon-diff-renamed {
|
|
|
|
color: var(--color-teal);
|
|
|
|
}
|
|
|
|
|
|
|
|
.item.filewrapper {
|
|
|
|
display: grid !important;
|
|
|
|
grid-template-columns: 20px 7fr 1fr;
|
|
|
|
padding-left: 18px !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.item.filewrapper:hover {
|
|
|
|
color: var(--color-text);
|
|
|
|
background: var(--color-hover);
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
|
|
|
|
div.directory {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: 18px 20px auto;
|
2023-02-12 02:34:46 +00:00
|
|
|
user-select: none;
|
|
|
|
cursor: pointer;
|
2022-09-27 05:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
div.directory:hover {
|
|
|
|
color: var(--color-text);
|
|
|
|
background: var(--color-hover);
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
|
|
|
|
div.list {
|
|
|
|
padding-bottom: 0 !important;
|
|
|
|
padding-top: inherit !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
a {
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
a:hover {
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
|
|
|
</style>
|