From 2cf0cf0de1fc298f1b44a0452c8dbb2c2f9dd71c Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 23 Dec 2022 17:03:11 +0100 Subject: [PATCH 1/4] JS refactors (#22227) - Replace all default exports with named exports, except for Vue SFCs - Remove names from Vue SFCs, they are automatically inferred from the filename - Misc whitespace-related tweaks --- web_src/js/components/ActivityHeatmap.vue | 1 - web_src/js/components/ContextPopup.vue | 10 +-------- web_src/js/components/DiffFileList.vue | 6 ----- web_src/js/components/DiffFileTree.vue | 6 +---- web_src/js/components/DiffFileTreeItem.vue | 7 +----- .../js/components/PullRequestMergeForm.vue | 12 +--------- web_src/js/features/clipboard.js | 2 +- web_src/js/features/colorpicker.js | 2 +- web_src/js/features/common-global.js | 2 +- web_src/js/features/comp/ColorPicker.js | 2 +- web_src/js/features/comp/EasyMDE.js | 2 +- web_src/js/features/comp/SearchUserBox.js | 1 - web_src/js/features/comp/WebHookEditor.js | 1 + web_src/js/features/contextpopup.js | 2 +- web_src/js/features/copycontent.js | 1 + web_src/js/features/dropzone.js | 2 +- web_src/js/features/emoji.js | 3 +-- web_src/js/features/file-fold.js | 1 - web_src/js/features/formatting.js | 1 - web_src/js/features/heatmap.js | 3 ++- web_src/js/features/imagediff.js | 2 +- web_src/js/features/repo-diff-filetree.js | 2 +- web_src/js/features/repo-findfile.js | 2 +- web_src/js/features/repo-graph.js | 2 +- web_src/js/features/repo-issue-pr-form.js | 2 +- web_src/js/features/repo-issue.js | 2 +- web_src/js/features/repo-legacy.js | 21 +++++++----------- web_src/js/features/repo-migration.js | 2 +- web_src/js/features/repo-projects.js | 2 +- web_src/js/features/repo-release.js | 2 +- web_src/js/features/serviceworker.js | 2 +- web_src/js/features/tablesort.js | 2 +- web_src/js/features/tribute.js | 2 +- web_src/js/index.js | 22 +++++++++---------- web_src/js/svg.js | 2 -- 35 files changed, 47 insertions(+), 89 deletions(-) diff --git a/web_src/js/components/ActivityHeatmap.vue b/web_src/js/components/ActivityHeatmap.vue index 6cd72a8bf7..d0f81c586c 100644 --- a/web_src/js/components/ActivityHeatmap.vue +++ b/web_src/js/components/ActivityHeatmap.vue @@ -18,7 +18,6 @@ import {CalendarHeatmap} from 'vue3-calendar-heatmap'; export default { - name: 'ActivityHeatmap', components: {CalendarHeatmap}, props: { values: { diff --git a/web_src/js/components/ContextPopup.vue b/web_src/js/components/ContextPopup.vue index 0b086690a9..07c73ff5cf 100644 --- a/web_src/js/components/ContextPopup.vue +++ b/web_src/js/components/ContextPopup.vue @@ -46,19 +46,13 @@ const luminance = (colorString) => { const luminanceThreshold = 0.179; export default { - name: 'ContextPopup', - - components: { - SvgIcon, - }, - + components: {SvgIcon}, data: () => ({ loading: false, issue: null, i18nErrorOccurred: i18n.error_occurred, i18nErrorMessage: null, }), - computed: { createdAt() { return new Date(this.issue.created_at).toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'}); @@ -107,7 +101,6 @@ export default { }); } }, - mounted() { this.$refs.root.addEventListener('us-load-context-popup', (e) => { const data = e.detail; @@ -116,7 +109,6 @@ export default { } }); }, - methods: { load(data) { this.loading = true; diff --git a/web_src/js/components/DiffFileList.vue b/web_src/js/components/DiffFileList.vue index da53be3b46..f95f28528d 100644 --- a/web_src/js/components/DiffFileList.vue +++ b/web_src/js/components/DiffFileList.vue @@ -27,12 +27,9 @@ import {doLoadMoreFiles} from '../features/repo-diff.js'; const {pageData} = window.config; export default { - name: 'DiffFileList', - data: () => { return pageData.diffFileInfo; }, - watch: { fileListIsVisible(newValue) { if (newValue === true) { @@ -44,15 +41,12 @@ export default { } } }, - 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; diff --git a/web_src/js/components/DiffFileTree.vue b/web_src/js/components/DiffFileTree.vue index 717ba70f7f..e592574ac1 100644 --- a/web_src/js/components/DiffFileTree.vue +++ b/web_src/js/components/DiffFileTree.vue @@ -21,15 +21,12 @@ const {pageData} = window.config; const LOCAL_STORAGE_KEY = 'diff_file_tree_visible'; export default { - name: 'DiffFileTree', components: {DiffFileTreeItem}, - data: () => { const fileTreeIsVisible = localStorage.getItem(LOCAL_STORAGE_KEY) === 'true'; pageData.diffFileInfo.fileTreeIsVisible = fileTreeIsVisible; return pageData.diffFileInfo; }, - computed: { fileTree() { const result = []; @@ -94,7 +91,6 @@ export default { return result; } }, - mounted() { // ensure correct buttons when we are mounted to the dom this.adjustToggleButton(this.fileTreeIsVisible); @@ -125,7 +121,7 @@ export default { doLoadMoreFiles(this.link, this.diffEnd, () => { this.isLoadingNewData = false; }); - } + }, }, }; diff --git a/web_src/js/components/DiffFileTreeItem.vue b/web_src/js/components/DiffFileTreeItem.vue index 4f20f1e66a..4089e51410 100644 --- a/web_src/js/components/DiffFileTreeItem.vue +++ b/web_src/js/components/DiffFileTreeItem.vue @@ -43,11 +43,7 @@ import {SvgIcon} from '../svg.js'; export default { - name: 'DiffFileTreeItem', - components: { - SvgIcon, - }, - + components: {SvgIcon}, props: { item: { type: Object, @@ -59,7 +55,6 @@ export default { default: true } }, - data: () => ({ collapsed: false, }), diff --git a/web_src/js/components/PullRequestMergeForm.vue b/web_src/js/components/PullRequestMergeForm.vue index 1fec12dd5a..1e0ebc5a47 100644 --- a/web_src/js/components/PullRequestMergeForm.vue +++ b/web_src/js/components/PullRequestMergeForm.vue @@ -111,11 +111,7 @@ import {SvgIcon} from '../svg.js'; const {csrfToken, pageData} = window.config; export default { - name: 'PullRequestMergeForm', - components: { - SvgIcon, - }, - + components: {SvgIcon}, data: () => ({ csrfToken, mergeForm: pageData.pullRequestMergeForm, @@ -137,20 +133,17 @@ export default { showMergeStyleMenu: false, showActionForm: false, }), - computed: { mergeButtonStyleClass() { if (this.mergeForm.allOverridableChecksOk) return 'green'; return this.autoMergeWhenSucceed ? 'blue' : 'red'; } }, - watch: { mergeStyle(val) { this.mergeStyleDetail = this.mergeForm.mergeStyles.find((e) => e.name === val); } }, - created() { this.mergeStyleAllowedCount = this.mergeForm.mergeStyles.reduce((v, msd) => v + (msd.allowed ? 1 : 0), 0); @@ -158,15 +151,12 @@ export default { if (!mergeStyle) mergeStyle = this.mergeForm.mergeStyles.find((e) => e.allowed)?.name; this.switchMergeStyle(mergeStyle, !this.mergeForm.canMergeNow); }, - mounted() { document.addEventListener('mouseup', this.hideMergeStyleMenu); }, - unmounted() { document.removeEventListener('mouseup', this.hideMergeStyleMenu); }, - methods: { hideMergeStyleMenu() { this.showMergeStyleMenu = false; diff --git a/web_src/js/features/clipboard.js b/web_src/js/features/clipboard.js index 75b96cb781..f8486cdc6c 100644 --- a/web_src/js/features/clipboard.js +++ b/web_src/js/features/clipboard.js @@ -44,7 +44,7 @@ function fallbackCopyToClipboard(text) { // For all DOM elements with [data-clipboard-target] or [data-clipboard-text], // this copy-to-clipboard will work for them -export default function initGlobalCopyToClipboardListener() { +export function initGlobalCopyToClipboardListener() { document.addEventListener('click', (e) => { let target = e.target; // in case , so we just search diff --git a/web_src/js/features/colorpicker.js b/web_src/js/features/colorpicker.js index 11c5f26fa4..a5fdb3f5a6 100644 --- a/web_src/js/features/colorpicker.js +++ b/web_src/js/features/colorpicker.js @@ -1,4 +1,4 @@ -export default async function createColorPicker($els) { +export async function createColorPicker($els) { if (!$els || !$els.length) return; await Promise.all([ diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 7efefd7084..2504f3be0a 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -1,7 +1,7 @@ import $ from 'jquery'; import 'jquery.are-you-sure'; import {mqBinarySearch} from '../utils.js'; -import createDropzone from './dropzone.js'; +import {createDropzone} from './dropzone.js'; import {initCompColorPicker} from './comp/ColorPicker.js'; import {showGlobalErrorMessage} from '../bootstrap.js'; import {attachDropdownAria} from './aria.js'; diff --git a/web_src/js/features/comp/ColorPicker.js b/web_src/js/features/comp/ColorPicker.js index 053fc6c059..5665b7a24a 100644 --- a/web_src/js/features/comp/ColorPicker.js +++ b/web_src/js/features/comp/ColorPicker.js @@ -1,5 +1,5 @@ import $ from 'jquery'; -import createColorPicker from '../colorpicker.js'; +import {createColorPicker} from '../colorpicker.js'; export function initCompColorPicker() { createColorPicker($('.color-picker')); diff --git a/web_src/js/features/comp/EasyMDE.js b/web_src/js/features/comp/EasyMDE.js index 1f7fe45153..182e6b429d 100644 --- a/web_src/js/features/comp/EasyMDE.js +++ b/web_src/js/features/comp/EasyMDE.js @@ -1,5 +1,5 @@ import $ from 'jquery'; -import attachTribute from '../tribute.js'; +import {attachTribute} from '../tribute.js'; import {handleGlobalEnterQuickSubmit} from './QuickSubmit.js'; /** diff --git a/web_src/js/features/comp/SearchUserBox.js b/web_src/js/features/comp/SearchUserBox.js index 46ecb8ebf4..0e9a005acf 100644 --- a/web_src/js/features/comp/SearchUserBox.js +++ b/web_src/js/features/comp/SearchUserBox.js @@ -2,7 +2,6 @@ import $ from 'jquery'; import {htmlEscape} from 'escape-goat'; const {appSubUrl} = window.config; - const looksLikeEmailAddressCheck = /^\S+@\S+$/; export function initCompSearchUserBox() { diff --git a/web_src/js/features/comp/WebHookEditor.js b/web_src/js/features/comp/WebHookEditor.js index 85a4f92809..cda0fa3910 100644 --- a/web_src/js/features/comp/WebHookEditor.js +++ b/web_src/js/features/comp/WebHookEditor.js @@ -1,4 +1,5 @@ import $ from 'jquery'; + const {csrfToken} = window.config; export function initCompWebHookEditor() { diff --git a/web_src/js/features/contextpopup.js b/web_src/js/features/contextpopup.js index d29da6d951..61f7120908 100644 --- a/web_src/js/features/contextpopup.js +++ b/web_src/js/features/contextpopup.js @@ -4,7 +4,7 @@ import ContextPopup from '../components/ContextPopup.vue'; import {parseIssueHref} from '../utils.js'; import {createTippy} from '../modules/tippy.js'; -export default function initContextPopups() { +export function initContextPopups() { const refIssues = $('.ref-issue'); if (!refIssues.length) return; diff --git a/web_src/js/features/copycontent.js b/web_src/js/features/copycontent.js index 9b791bedba..5a4b99ae9b 100644 --- a/web_src/js/features/copycontent.js +++ b/web_src/js/features/copycontent.js @@ -1,6 +1,7 @@ import {copyToClipboard} from './clipboard.js'; import {showTemporaryTooltip} from '../modules/tippy.js'; import {convertImage} from '../utils.js'; + const {i18n} = window.config; async function doCopy(content, btn) { diff --git a/web_src/js/features/dropzone.js b/web_src/js/features/dropzone.js index 1c80fb778c..e7b8a9dde9 100644 --- a/web_src/js/features/dropzone.js +++ b/web_src/js/features/dropzone.js @@ -1,4 +1,4 @@ -export default async function createDropzone(el, opts) { +export async function createDropzone(el, opts) { const [{Dropzone}] = await Promise.all([ import(/* webpackChunkName: "dropzone" */'dropzone'), import(/* webpackChunkName: "dropzone" */'dropzone/dist/dropzone.css'), diff --git a/web_src/js/features/emoji.js b/web_src/js/features/emoji.js index 304c564f3d..d00ff65456 100644 --- a/web_src/js/features/emoji.js +++ b/web_src/js/features/emoji.js @@ -1,7 +1,6 @@ import emojis from '../../../assets/emoji.json'; -const {assetUrlPrefix} = window.config; -const {customEmojis} = window.config; +const {assetUrlPrefix, customEmojis} = window.config; const tempMap = {...customEmojis}; for (const {emoji, aliases} of emojis) { diff --git a/web_src/js/features/file-fold.js b/web_src/js/features/file-fold.js index 5e714a1de8..0d5be7cf60 100644 --- a/web_src/js/features/file-fold.js +++ b/web_src/js/features/file-fold.js @@ -1,6 +1,5 @@ import {svg} from '../svg.js'; - // Hides the file if newFold is true, and shows it otherwise. The actual hiding is performed using CSS. // // The fold arrow is the icon displayed on the upper left of the file box, especially intended for components having the 'fold-file' class. diff --git a/web_src/js/features/formatting.js b/web_src/js/features/formatting.js index c8f5db9e14..837e323376 100644 --- a/web_src/js/features/formatting.js +++ b/web_src/js/features/formatting.js @@ -1,7 +1,6 @@ import {prettyNumber} from '../utils.js'; const {lang} = document.documentElement; - const dateFormatter = new Intl.DateTimeFormat(lang, {year: 'numeric', month: 'long', day: 'numeric'}); const shortDateFormatter = new Intl.DateTimeFormat(lang, {year: 'numeric', month: 'short', day: 'numeric'}); const dateTimeFormatter = new Intl.DateTimeFormat(lang, {year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric'}); diff --git a/web_src/js/features/heatmap.js b/web_src/js/features/heatmap.js index 368ddd0d77..f80089ee43 100644 --- a/web_src/js/features/heatmap.js +++ b/web_src/js/features/heatmap.js @@ -1,7 +1,8 @@ import {createApp} from 'vue'; import ActivityHeatmap from '../components/ActivityHeatmap.vue'; import {translateMonth, translateDay} from '../utils.js'; -export default function initHeatmap() { + +export function initHeatmap() { const el = document.getElementById('user-heatmap'); if (!el) return; diff --git a/web_src/js/features/imagediff.js b/web_src/js/features/imagediff.js index 0b021d070f..03ae3b047b 100644 --- a/web_src/js/features/imagediff.js +++ b/web_src/js/features/imagediff.js @@ -34,7 +34,7 @@ function getDefaultSvgBoundsIfUndefined(svgXml, src) { return null; } -export default function initImageDiff() { +export function initImageDiff() { function createContext(image1, image2) { const size1 = { width: image1 && image1.width || 0, diff --git a/web_src/js/features/repo-diff-filetree.js b/web_src/js/features/repo-diff-filetree.js index 6059dd82e7..5dd2c42e74 100644 --- a/web_src/js/features/repo-diff-filetree.js +++ b/web_src/js/features/repo-diff-filetree.js @@ -2,7 +2,7 @@ import {createApp} from 'vue'; import DiffFileTree from '../components/DiffFileTree.vue'; import DiffFileList from '../components/DiffFileList.vue'; -export default function initDiffFileTree() { +export function initDiffFileTree() { const el = document.getElementById('diff-file-tree'); if (!el) return; diff --git a/web_src/js/features/repo-findfile.js b/web_src/js/features/repo-findfile.js index 750b906cef..7b8833e793 100644 --- a/web_src/js/features/repo-findfile.js +++ b/web_src/js/features/repo-findfile.js @@ -1,6 +1,6 @@ import $ from 'jquery'; - import {svg} from '../svg.js'; + const {csrf} = window.config; const threshold = 50; diff --git a/web_src/js/features/repo-graph.js b/web_src/js/features/repo-graph.js index f27a986621..16d35e66f2 100644 --- a/web_src/js/features/repo-graph.js +++ b/web_src/js/features/repo-graph.js @@ -1,6 +1,6 @@ import $ from 'jquery'; -export default function initRepoGraphGit() { +export function initRepoGraphGit() { const graphContainer = document.getElementById('git-graph-container'); if (!graphContainer) return; diff --git a/web_src/js/features/repo-issue-pr-form.js b/web_src/js/features/repo-issue-pr-form.js index 59d4c7a3b4..7b26e643c0 100644 --- a/web_src/js/features/repo-issue-pr-form.js +++ b/web_src/js/features/repo-issue-pr-form.js @@ -1,7 +1,7 @@ import {createApp} from 'vue'; import PullRequestMergeForm from '../components/PullRequestMergeForm.vue'; -export default function initPullRequestMergeForm() { +export function initRepoPullRequestMergeForm() { const el = document.getElementById('pull-request-merge-form'); if (!el) return; diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index ca5d69c5a6..56d294e81a 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -1,6 +1,6 @@ import $ from 'jquery'; import {htmlEscape} from 'escape-goat'; -import attachTribute from './tribute.js'; +import {attachTribute} from './tribute.js'; import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js'; import {initEasyMDEImagePaste} from './comp/ImagePaste.js'; import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js'; diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 910d4bb56c..37366578e2 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -3,33 +3,28 @@ import {createCommentEasyMDE, getAttachedEasyMDE} from './comp/EasyMDE.js'; import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js'; import {initEasyMDEImagePaste} from './comp/ImagePaste.js'; import { - initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel, - initRepoIssueCommentDelete, - initRepoIssueComments, initRepoIssueDependencyDelete, - initRepoIssueReferenceIssue, initRepoIssueStatusButton, - initRepoIssueTitleEdit, - initRepoIssueWipToggle, initRepoPullRequestUpdate, - updateIssuesMeta, + initRepoIssueBranchSelect, initRepoIssueCodeCommentCancel, initRepoIssueCommentDelete, + initRepoIssueComments, initRepoIssueDependencyDelete, initRepoIssueReferenceIssue, + initRepoIssueStatusButton, initRepoIssueTitleEdit, initRepoIssueWipToggle, + initRepoPullRequestUpdate, updateIssuesMeta, } from './repo-issue.js'; import {initUnicodeEscapeButton} from './repo-unicode-escape.js'; import {svg} from '../svg.js'; import {htmlEscape} from 'escape-goat'; import {initRepoBranchTagDropdown} from '../components/RepoBranchTagDropdown.js'; import { - initRepoCloneLink, - initRepoCommonBranchOrTagDropdown, - initRepoCommonFilterSearchDropdown, + initRepoCloneLink, initRepoCommonBranchOrTagDropdown, initRepoCommonFilterSearchDropdown, initRepoCommonLanguageStats, } from './repo-common.js'; import {initCitationFileCopyContent} from './citation.js'; import {initCompLabelEdit} from './comp/LabelEdit.js'; import {initRepoDiffConversationNav} from './repo-diff.js'; -import attachTribute from './tribute.js'; -import createDropzone from './dropzone.js'; +import {attachTribute} from './tribute.js'; +import {createDropzone} from './dropzone.js'; import {initCommentContent, initMarkupContent} from '../markup/content.js'; import {initCompReactionSelector} from './comp/ReactionSelector.js'; import {initRepoSettingBranches} from './repo-settings.js'; -import initRepoPullRequestMergeForm from './repo-issue-pr-form.js'; +import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.js'; const {csrfToken} = window.config; diff --git a/web_src/js/features/repo-migration.js b/web_src/js/features/repo-migration.js index ece01e53bd..c317c7245c 100644 --- a/web_src/js/features/repo-migration.js +++ b/web_src/js/features/repo-migration.js @@ -10,7 +10,7 @@ const $lfsSettings = $('#lfs_settings'); const $lfsEndpoint = $('#lfs_endpoint'); const $items = $('#migrate_items').find('input[type=checkbox]'); -export default function initRepoMigration() { +export function initRepoMigration() { checkAuth(); setLFSSettingsVisibility(); diff --git a/web_src/js/features/repo-projects.js b/web_src/js/features/repo-projects.js index b5a720c9d7..f6d6c89816 100644 --- a/web_src/js/features/repo-projects.js +++ b/web_src/js/features/repo-projects.js @@ -84,7 +84,7 @@ async function initRepoProjectSortable() { } } -export default function initRepoProject() { +export function initRepoProject() { if (!$('.repository.projects').length) { return; } diff --git a/web_src/js/features/repo-release.js b/web_src/js/features/repo-release.js index b68a7a6cd5..e84cc53d17 100644 --- a/web_src/js/features/repo-release.js +++ b/web_src/js/features/repo-release.js @@ -1,5 +1,5 @@ import $ from 'jquery'; -import attachTribute from './tribute.js'; +import {attachTribute} from './tribute.js'; import {initCompMarkupContentPreviewTab} from './comp/MarkupContentPreview.js'; import {initEasyMDEImagePaste} from './comp/ImagePaste.js'; import {createCommentEasyMDE} from './comp/EasyMDE.js'; diff --git a/web_src/js/features/serviceworker.js b/web_src/js/features/serviceworker.js index a072811b04..32d2e04cd6 100644 --- a/web_src/js/features/serviceworker.js +++ b/web_src/js/features/serviceworker.js @@ -35,7 +35,7 @@ async function checkCacheValidity() { } } -export default async function initServiceWorker() { +export async function initServiceWorker() { if (!('serviceWorker' in navigator)) return; if (useServiceWorker) { diff --git a/web_src/js/features/tablesort.js b/web_src/js/features/tablesort.js index 1fc2a4bd56..436fe0a594 100644 --- a/web_src/js/features/tablesort.js +++ b/web_src/js/features/tablesort.js @@ -1,4 +1,4 @@ -export default function initTableSort() { +export function initTableSort() { for (const header of document.querySelectorAll('th[data-sortt-asc]') || []) { const sorttAsc = header.getAttribute('data-sortt-asc'); const sorttDesc = header.getAttribute('data-sortt-desc'); diff --git a/web_src/js/features/tribute.js b/web_src/js/features/tribute.js index dcee7aa4a3..94f3512a2e 100644 --- a/web_src/js/features/tribute.js +++ b/web_src/js/features/tribute.js @@ -49,7 +49,7 @@ function makeCollections({mentions, emoji}) { return collections; } -export default async function attachTribute(elementOrNodeList, {mentions, emoji} = {}) { +export async function attachTribute(elementOrNodeList, {mentions, emoji} = {}) { if (!window.config.requireTribute || !elementOrNodeList) return; const nodes = Array.from('length' in elementOrNodeList ? elementOrNodeList : [elementOrNodeList]); if (!nodes.length) return; diff --git a/web_src/js/index.js b/web_src/js/index.js index f4638a60e0..a866184203 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -6,16 +6,16 @@ import {initVueEnv} from './components/VueComponentLoader.js'; import {initRepoActivityTopAuthorsChart} from './components/RepoActivityTopAuthors.vue'; import {initDashboardRepoList} from './components/DashboardRepoList.js'; -import attachTribute from './features/tribute.js'; -import initGlobalCopyToClipboardListener from './features/clipboard.js'; -import initContextPopups from './features/contextpopup.js'; -import initRepoGraphGit from './features/repo-graph.js'; -import initHeatmap from './features/heatmap.js'; -import initImageDiff from './features/imagediff.js'; -import initRepoMigration from './features/repo-migration.js'; -import initRepoProject from './features/repo-projects.js'; -import initServiceWorker from './features/serviceworker.js'; -import initTableSort from './features/tablesort.js'; +import {attachTribute} from './features/tribute.js'; +import {initGlobalCopyToClipboardListener} from './features/clipboard.js'; +import {initContextPopups} from './features/contextpopup.js'; +import {initRepoGraphGit} from './features/repo-graph.js'; +import {initHeatmap} from './features/heatmap.js'; +import {initImageDiff} from './features/imagediff.js'; +import {initRepoMigration} from './features/repo-migration.js'; +import {initRepoProject} from './features/repo-projects.js'; +import {initServiceWorker} from './features/serviceworker.js'; +import {initTableSort} from './features/tablesort.js'; import {initAdminUserListSearchForm} from './features/admin/users.js'; import {initAdminConfigs} from './features/admin/config.js'; import {initMarkupAnchors} from './markup/anchors.js'; @@ -24,7 +24,7 @@ import {initRepoIssueContentHistory} from './features/repo-issue-content.js'; import {initStopwatch} from './features/stopwatch.js'; import {initFindFileInRepo} from './features/repo-findfile.js'; import {initCommentContent, initMarkupContent} from './markup/content.js'; -import initDiffFileTree from './features/repo-diff-filetree.js'; +import {initDiffFileTree} from './features/repo-diff-filetree.js'; import {initUserAuthLinkAccountView, initUserAuthOauth2} from './features/user-auth.js'; import { diff --git a/web_src/js/svg.js b/web_src/js/svg.js index 60dd49f8bf..0f08f64e80 100644 --- a/web_src/js/svg.js +++ b/web_src/js/svg.js @@ -26,7 +26,6 @@ import octiconSidebarExpand from '../../public/img/svg/octicon-sidebar-expand.sv import octiconTriangleDown from '../../public/img/svg/octicon-triangle-down.svg'; import octiconX from '../../public/img/svg/octicon-x.svg'; - export const svgs = { 'octicon-chevron-down': octiconChevronDown, 'octicon-chevron-right': octiconChevronRight, @@ -57,7 +56,6 @@ export const svgs = { 'octicon-x': octiconX, }; - const parser = new DOMParser(); const serializer = new XMLSerializer(); From 2b0b56319e94b7173b566af4d082f03664853789 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 24 Dec 2022 02:34:51 +0800 Subject: [PATCH 2/4] Improve testing for pgsql empty repository (#22223) --- tests/integration/empty_repo_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integration/empty_repo_test.go b/tests/integration/empty_repo_test.go index 4bc1d811bf..1a83de1292 100644 --- a/tests/integration/empty_repo_test.go +++ b/tests/integration/empty_repo_test.go @@ -11,6 +11,8 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/tests" + + "github.com/stretchr/testify/assert" ) func TestEmptyRepo(t *testing.T) { @@ -21,7 +23,8 @@ func TestEmptyRepo(t *testing.T) { "commit/1ae57b34ccf7e18373", "graph", } - emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{}, unittest.Cond("is_empty = ?", true)) + emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 5}) + assert.True(t, emptyRepo.IsEmpty) owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: emptyRepo.OwnerID}) for _, subpath := range subpaths { req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, emptyRepo.Name, subpath) From 3bd49f780157494a3ff923a3bcdbb8696a688173 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 25 Dec 2022 00:19:36 +0000 Subject: [PATCH 3/4] [skip ci] Updated licenses and gitignores --- options/gitignore/Godot | 4 ++++ options/license/Bitstream-Charter | 9 ++++++++ options/license/Graphics-Gems | 5 +++++ options/license/IJG-short | 35 +++++++++++++++++++++++++++++++ options/license/MIT-Wu | 28 +++++++++++++++++++++++++ options/license/TPDL | 2 ++ options/license/TTWL | 8 +++++++ 7 files changed, 91 insertions(+) create mode 100644 options/license/Bitstream-Charter create mode 100644 options/license/Graphics-Gems create mode 100644 options/license/IJG-short create mode 100644 options/license/MIT-Wu create mode 100644 options/license/TPDL create mode 100644 options/license/TTWL diff --git a/options/gitignore/Godot b/options/gitignore/Godot index 4f48ad79f8..d9aac213e7 100644 --- a/options/gitignore/Godot +++ b/options/gitignore/Godot @@ -1,3 +1,6 @@ +# Godot 4+ specific ignores +.godot/ + # Godot-specific ignores .import/ export.cfg @@ -9,3 +12,4 @@ export_presets.cfg # Mono-specific ignores .mono/ data_*/ +mono_crash.*.json diff --git a/options/license/Bitstream-Charter b/options/license/Bitstream-Charter new file mode 100644 index 0000000000..7a0cf97a0c --- /dev/null +++ b/options/license/Bitstream-Charter @@ -0,0 +1,9 @@ +(c) Copyright 1989-1992, Bitstream Inc., Cambridge, MA. + +You are hereby granted permission under all Bitstream propriety rights +to use, copy, modify, sublicense, sell, and redistribute the 4 Bitstream +Charter (r) Type 1 outline fonts and the 4 Courier Type 1 outline fonts for +any purpose and without restriction; provided, that this notice is left +intact on all copies of such fonts and that Bitstream's trademark is acknowledged +as shown below on all unmodified copies of the 4 Charter Type 1 fonts. +BITSTREAM CHARTER is a registered trademark of Bitstream Inc. diff --git a/options/license/Graphics-Gems b/options/license/Graphics-Gems new file mode 100644 index 0000000000..ec28c46563 --- /dev/null +++ b/options/license/Graphics-Gems @@ -0,0 +1,5 @@ +LICENSE + +This code repository predates the concept of Open Source, and predates most licenses along such lines. As such, the official license truly is: + +EULA: The Graphics Gems code is copyright-protected. In other words, you cannot claim the text of the code as your own and resell it. Using the code is permitted in any program, product, or library, non-commercial or commercial. Giving credit is not required, though is a nice gesture. The code comes as-is, and if there are any flaws or problems with any Gems code, nobody involved with Gems - authors, editors, publishers, or webmasters - are to be held responsible. Basically, don't be a jerk, and remember that anything free comes with no guarantee. diff --git a/options/license/IJG-short b/options/license/IJG-short new file mode 100644 index 0000000000..bbb0859d80 --- /dev/null +++ b/options/license/IJG-short @@ -0,0 +1,35 @@ +The authors make NO WARRANTY or representation, either express or +implied, with respect to this software, its quality, accuracy, +merchantability, or fitness for a particular purpose. This software is +provided "AS IS", and you, its user, assume the entire risk as to its +quality and accuracy. + +This software is copyright (C) 1991, 1992, Thomas G. Lane. All Rights +Reserved except as specified below. + +Permission is hereby granted to use, copy, modify, and distribute this +software (or portions thereof) for any purpose, without fee, subject to +these conditions: + +(1) If any part of the source code for this software +is distributed, then this README file must be included, with this +copyright and no-warranty notice unaltered; and any additions, +deletions, or changes to the original files must be clearly indicated +in accompanying documentation. + +(2) If only executable code is +distributed, then the accompanying documentation must state that "this +software is based in part on the work of the Independent JPEG Group". + +(3) Permission for use of this software is granted only if the user +accepts full responsibility for any undesirable consequences; the +authors accept NO LIABILITY for damages of any kind. + +Permission is NOT granted for the use of any IJG author's name or +company name in advertising or publicity relating to this software or +products derived from it. This software may be referred to only as +"the Independent JPEG Group's software". + +We specifically permit and encourage the use of this software as the +basis of commercial products, provided that all warranty or liability +claims are assumed by the product vendor. diff --git a/options/license/MIT-Wu b/options/license/MIT-Wu new file mode 100644 index 0000000000..86eec3c517 --- /dev/null +++ b/options/license/MIT-Wu @@ -0,0 +1,28 @@ +Copyright (c) 2003-2005 Tom Wu +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, +EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY +WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + +IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL, +INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF +THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +In addition, the following condition applies: + +All redistributions must retain an intact copy of this copyright notice +and disclaimer. diff --git a/options/license/TPDL b/options/license/TPDL new file mode 100644 index 0000000000..d950f8f19e --- /dev/null +++ b/options/license/TPDL @@ -0,0 +1,2 @@ +Copyright (C) 1996-2010 David Muir Sharnoff. Copyright (C) 2011 Google, Inc. +License hereby granted for anyone to use, modify or redistribute this module at their own risk. Please feed useful changes back to cpan@dave.sharnoff.org. diff --git a/options/license/TTWL b/options/license/TTWL new file mode 100644 index 0000000000..c13d3fbe04 --- /dev/null +++ b/options/license/TTWL @@ -0,0 +1,8 @@ +Copyright (C) 1996-2002,2005,2006 David Muir Sharnoff. +Copyright (C) 2005 Aristotle Pagaltzis +Copyright (C) 2012-2013 Google, Inc. + +This module may be modified, used, copied, and redistributed at your own risk. +Although allowed by the preceding license, please do not publicly +redistribute modified versions of this code with the name "Text::Tabs" +unless it passes the unmodified Text::Tabs test suite. From f5cd0d93192fc4d04966ba971c7aaaae7475926d Mon Sep 17 00:00:00 2001 From: silverwind Date: Sun, 25 Dec 2022 18:17:48 +0100 Subject: [PATCH 4/4] Add Mermaid copy button, avoid unnecessary tooltip hide (#22225) - Add Copy button to mermaid diagrams which copies their source. - Set tippy to not hide on click and avoid tooltip re-creation for temporary tooltips. This avoids hide and show when copying repo url. Popovers still hide the tooltip as usual. Screenshot 2022-12-23 at 14 02 32 Co-authored-by: Lauris BH Co-authored-by: KN4CK3R --- web_src/js/markup/codecopy.js | 13 ++++++++----- web_src/js/markup/mermaid.js | 10 +++++++++- web_src/js/modules/tippy.js | 3 ++- web_src/less/markup/codecopy.less | 6 ++++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/web_src/js/markup/codecopy.js b/web_src/js/markup/codecopy.js index 2aa7070c72..a12802ef73 100644 --- a/web_src/js/markup/codecopy.js +++ b/web_src/js/markup/codecopy.js @@ -1,15 +1,18 @@ import {svg} from '../svg.js'; +export function makeCodeCopyButton() { + const button = document.createElement('button'); + button.classList.add('code-copy', 'ui', 'button'); + button.innerHTML = svg('octicon-copy'); + return button; +} + export function renderCodeCopy() { const els = document.querySelectorAll('.markup .code-block code'); if (!els.length) return; - const button = document.createElement('button'); - button.classList.add('code-copy', 'ui', 'button'); - button.innerHTML = svg('octicon-copy'); - for (const el of els) { - const btn = button.cloneNode(true); + const btn = makeCodeCopyButton(); btn.setAttribute('data-clipboard-text', el.textContent); el.after(btn); } diff --git a/web_src/js/markup/mermaid.js b/web_src/js/markup/mermaid.js index efd9abbb56..29fa92552d 100644 --- a/web_src/js/markup/mermaid.js +++ b/web_src/js/markup/mermaid.js @@ -1,4 +1,6 @@ import {isDarkTheme} from '../utils.js'; +import {makeCodeCopyButton} from './codecopy.js'; + const {mermaidMaxSourceCharacters} = window.config; const iframeCss = ` @@ -58,7 +60,13 @@ export async function renderMermaid() { iframe.sandbox = 'allow-scripts'; iframe.style.height = `${Math.ceil(parseFloat(heightStr))}px`; iframe.srcdoc = `${svgStr}`; - el.closest('pre').replaceWith(iframe); + const mermaidBlock = document.createElement('div'); + mermaidBlock.classList.add('mermaid-block'); + mermaidBlock.append(iframe); + const btn = makeCodeCopyButton(); + btn.setAttribute('data-clipboard-text', source); + mermaidBlock.append(btn); + el.closest('pre').replaceWith(mermaidBlock); }); } catch (err) { displayError(el, err); diff --git a/web_src/js/modules/tippy.js b/web_src/js/modules/tippy.js index 6a89151691..ce8f0369f1 100644 --- a/web_src/js/modules/tippy.js +++ b/web_src/js/modules/tippy.js @@ -6,6 +6,7 @@ export function createTippy(target, opts = {}) { placement: target.getAttribute('data-placement') || 'top-start', animation: false, allowHTML: false, + hideOnClick: false, interactiveBorder: 30, ignoreAttributes: true, maxWidth: 500, // increase over default 350px @@ -46,7 +47,7 @@ export function showTemporaryTooltip(target, content) { } tippy.setContent(content); - tippy.show(); + if (!tippy.state.isShown) tippy.show(); tippy.setProps({ onHidden: (tippy) => { if (oldContent) { diff --git a/web_src/less/markup/codecopy.less b/web_src/less/markup/codecopy.less index b2ce77aaa1..f6f9894fc1 100644 --- a/web_src/less/markup/codecopy.less +++ b/web_src/less/markup/codecopy.less @@ -1,4 +1,5 @@ -.markup .code-block { +.markup .code-block, +.markup .mermaid-block { position: relative; } @@ -26,7 +27,8 @@ background: var(--color-secondary-dark-1) !important; } -.markup .code-block:hover .code-copy { +.markup .code-block:hover .code-copy, +.markup .mermaid-block:hover .code-copy { visibility: visible; animation: fadein .2s both; }