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