mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-27 19:27:53 +01:00
9be90a5875
## 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:
1a4efa0ee9/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`.
64 lines
2.3 KiB
Vue
64 lines
2.3 KiB
Vue
<template>
|
|
<ol class="diff-detail-box diff-stats gt-m-0" ref="root" v-if="fileListIsVisible">
|
|
<li v-for="file in files" :key="file.NameHash">
|
|
<div class="gt-bold gt-df gt-ac pull-right">
|
|
<span v-if="file.IsBin" class="gt-ml-1 gt-mr-3">{{ binaryFileMessage }}</span>
|
|
{{ file.IsBin ? '' : file.Addition + file.Deletion }}
|
|
<span v-if="!file.IsBin" class="diff-stats-bar tooltip gt-mx-3" :data-content="statisticsMessage.replace('%d', (file.Addition + file.Deletion)).replace('%d', file.Addition).replace('%d', file.Deletion)">
|
|
<div class="diff-stats-add-bar" :style="{ 'width': diffStatsWidth(file.Addition, file.Deletion) }" />
|
|
</span>
|
|
</div>
|
|
<!-- todo finish all file status, now modify, add, delete and rename -->
|
|
<span :class="['status', diffTypeToString(file.Type), 'tooltip']" :data-content="diffTypeToString(file.Type)" data-position="right center"> </span>
|
|
<a class="file gt-mono" :href="'#diff-' + file.NameHash">{{ file.Name }}</a>
|
|
</li>
|
|
<li v-if="isIncomplete" id="diff-too-many-files-stats" class="gt-pt-2">
|
|
<span class="file gt-df gt-ac gt-sb">{{ tooManyFilesMessage }}
|
|
<a :class="['ui', 'basic', 'tiny', 'button', isLoadingNewData === true ? 'disabled' : '']" id="diff-show-more-files-stats" @click.stop="loadMoreData">{{ showMoreMessage }}</a>
|
|
</span>
|
|
</li>
|
|
</ol>
|
|
</template>
|
|
|
|
<script>
|
|
import {doLoadMoreFiles} from '../features/repo-diff.js';
|
|
|
|
const {pageData} = window.config;
|
|
|
|
export default {
|
|
data: () => {
|
|
return pageData.diffFileInfo;
|
|
},
|
|
mounted() {
|
|
document.getElementById('show-file-list-btn').addEventListener('click', this.toggleFileList);
|
|
},
|
|
unmounted() {
|
|
document.getElementById('show-file-list-btn').removeEventListener('click', this.toggleFileList);
|
|
},
|
|
methods: {
|
|
toggleFileList() {
|
|
this.fileListIsVisible = !this.fileListIsVisible;
|
|
},
|
|
diffTypeToString(pType) {
|
|
const diffTypes = {
|
|
1: 'add',
|
|
2: 'modify',
|
|
3: 'del',
|
|
4: 'rename',
|
|
5: 'copy',
|
|
};
|
|
return diffTypes[pType];
|
|
},
|
|
diffStatsWidth(adds, dels) {
|
|
return `${adds / (adds + dels) * 100}%`;
|
|
},
|
|
loadMoreData() {
|
|
this.isLoadingNewData = true;
|
|
doLoadMoreFiles(this.link, this.diffEnd, () => {
|
|
this.isLoadingNewData = false;
|
|
});
|
|
}
|
|
},
|
|
};
|
|
</script>
|