From 9be90a58754061171bbd5025d85d2b891364efd3 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 23 Mar 2023 17:56:15 +0800 Subject: [PATCH] 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`. --- package-lock.json | 12 +- package.json | 2 +- .../repo/issue/view_content/sidebar.tmpl | 4 +- templates/repo/sub_menu.tmpl | 2 +- web_src/js/components/DashboardRepoList.vue | 4 - web_src/js/components/DiffFileList.vue | 12 -- web_src/js/components/DiffFileTreeItem.vue | 2 +- web_src/js/features/common-global.js | 7 -- web_src/js/features/contextpopup.js | 1 + web_src/js/features/repo-diff.js | 5 - web_src/js/features/repo-issue.js | 5 +- web_src/js/index.js | 2 +- web_src/js/modules/tippy.js | 117 +++++++++++++++--- 13 files changed, 111 insertions(+), 64 deletions(-) diff --git a/package-lock.json b/package-lock.json index 353e0ab655..2f277f180f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,7 @@ "vue": "3.2.47", "vue-bar-graph": "2.0.0", "vue-loader": "17.0.1", - "vue3-calendar-heatmap": "2.0.0", + "vue3-calendar-heatmap": "2.0.2", "webpack": "5.76.2", "webpack-cli": "5.0.1", "workbox-routing": "6.5.4", @@ -9425,17 +9425,17 @@ } }, "node_modules/vue3-calendar-heatmap": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/vue3-calendar-heatmap/-/vue3-calendar-heatmap-2.0.0.tgz", - "integrity": "sha512-BchyC33WiZryYatFINj3LWqgyE6X82Huzf7abA23tsF/IbaRZVwZzie8SmGaYvezEBiPXhJogQ3dtxIuXFjkBw==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/vue3-calendar-heatmap/-/vue3-calendar-heatmap-2.0.2.tgz", + "integrity": "sha512-ev0rNbOGhzX1YcNhFE0xSmJQUzK96wubBLdzaUKtKf0GhjYE8QAwzmWYcYrugolLgDj2vKzHQ/9gA3O9S26WOA==", "dependencies": { "tippy.js": "^6.3.7" }, "engines": { - "node": ">=12" + "node": ">=16" }, "peerDependencies": { - "vue": "^3.2.24" + "vue": "^3.2.29" } }, "node_modules/w3c-xmlserializer": { diff --git a/package.json b/package.json index db7cf1154b..e5f346f207 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "vue": "3.2.47", "vue-bar-graph": "2.0.0", "vue-loader": "17.0.1", - "vue3-calendar-heatmap": "2.0.0", + "vue3-calendar-heatmap": "2.0.2", "webpack": "5.76.2", "webpack-cli": "5.0.1", "workbox-routing": "6.5.4", diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index cef1e3a02e..fb7c77f4eb 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -661,9 +661,9 @@ {{if and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo}}
-
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index 5c1688d019..adb1e3079f 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -40,7 +40,7 @@
{{range .LanguageStats}} -
 
+
 
{{end}}
{{end}} diff --git a/web_src/js/components/DashboardRepoList.vue b/web_src/js/components/DashboardRepoList.vue index 075af65af3..a97cfb02ba 100644 --- a/web_src/js/components/DashboardRepoList.vue +++ b/web_src/js/components/DashboardRepoList.vue @@ -147,7 +147,6 @@