From 8a53a39c426e95164e87a3b0857eb420711bfd85 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 11 Dec 2024 09:29:04 +0100 Subject: [PATCH] Fix a number of typescript errors (#32773) Fixes 96 typescript errors. Behaviour changes are commented below. --------- Co-authored-by: wxiaoguang --- web_src/js/features/repo-branch.ts | 4 +-- web_src/js/features/repo-code.ts | 18 +++++-------- web_src/js/features/repo-common.ts | 4 +-- web_src/js/features/repo-diff-commit.ts | 8 +++--- web_src/js/features/repo-graph.ts | 12 ++++----- web_src/js/features/repo-home.ts | 4 +-- web_src/js/features/repo-issue-pr-status.ts | 2 +- web_src/js/features/repo-issue.ts | 22 ++++++++-------- web_src/js/features/repo-migration.ts | 28 ++++++++++----------- web_src/js/features/repo-new.ts | 2 +- web_src/js/features/repo-projects.ts | 16 ++++++------ web_src/js/features/repo-release.ts | 10 ++++---- web_src/js/features/repo-search.ts | 4 +-- web_src/js/features/repo-settings.ts | 8 +++--- web_src/js/features/sshkey-helper.ts | 2 +- web_src/js/features/tablesort.ts | 2 +- web_src/js/features/tribute.ts | 2 +- web_src/js/globals.d.ts | 2 ++ web_src/js/modules/toast.ts | 11 +++++--- 19 files changed, 81 insertions(+), 80 deletions(-) diff --git a/web_src/js/features/repo-branch.ts b/web_src/js/features/repo-branch.ts index edf2f69638..0c1077748b 100644 --- a/web_src/js/features/repo-branch.ts +++ b/web_src/js/features/repo-branch.ts @@ -11,7 +11,7 @@ function initRepoCreateBranchButton() { for (const el of document.querySelectorAll('.show-create-branch-modal')) { el.addEventListener('click', () => { const modalFormName = el.getAttribute('data-modal-form') || '#create-branch-form'; - const modalForm = document.querySelector(modalFormName); + const modalForm = document.querySelector(modalFormName); if (!modalForm) return; modalForm.action = `${modalForm.getAttribute('data-base-action')}${el.getAttribute('data-branch-from-urlcomponent')}`; @@ -29,7 +29,7 @@ function initRepoRenameBranchButton() { const target = el.getAttribute('data-modal'); const modal = document.querySelector(target); const oldBranchName = el.getAttribute('data-old-branch-name'); - modal.querySelector('input[name=from]').value = oldBranchName; + modal.querySelector('input[name=from]').value = oldBranchName; // display the warning that the branch which is chosen is the default branch const warn = modal.querySelector('.default-branch-warning'); diff --git a/web_src/js/features/repo-code.ts b/web_src/js/features/repo-code.ts index 0068d6c0b5..a8d6e8f97d 100644 --- a/web_src/js/features/repo-code.ts +++ b/web_src/js/features/repo-code.ts @@ -8,7 +8,7 @@ import {toAbsoluteUrl} from '../utils.ts'; export const singleAnchorRegex = /^#(L|n)([1-9][0-9]*)$/; export const rangeAnchorRegex = /^#(L[1-9][0-9]*)-(L[1-9][0-9]*)$/; -function changeHash(hash) { +function changeHash(hash: string) { if (window.history.pushState) { window.history.pushState(null, null, hash); } else { @@ -24,7 +24,7 @@ function getLineEls() { return document.querySelectorAll(`.code-view td.lines-code${isBlame() ? '.blame-code' : ''}`); } -function selectRange($linesEls, $selectionEndEl, $selectionStartEls) { +function selectRange($linesEls, $selectionEndEl, $selectionStartEls?) { for (const el of $linesEls) { el.closest('tr').classList.remove('active'); } @@ -34,7 +34,7 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls) { const copyPermalink = document.querySelector('a.copy-line-permalink'); const viewGitBlame = document.querySelector('a.view_git_blame'); - const updateIssueHref = function (anchor) { + const updateIssueHref = function (anchor: string) { if (!refInNewIssue) return; const urlIssueNew = refInNewIssue.getAttribute('data-url-issue-new'); const urlParamBodyLink = refInNewIssue.getAttribute('data-url-param-body-link'); @@ -42,7 +42,7 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls) { refInNewIssue.setAttribute('href', `${urlIssueNew}?body=${encodeURIComponent(issueContent)}`); }; - const updateViewGitBlameFragment = function (anchor) { + const updateViewGitBlameFragment = function (anchor: string) { if (!viewGitBlame) return; let href = viewGitBlame.getAttribute('href'); href = `${href.replace(/#L\d+$|#L\d+-L\d+$/, '')}`; @@ -52,7 +52,7 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls) { viewGitBlame.setAttribute('href', href); }; - const updateCopyPermalinkUrl = function (anchor) { + const updateCopyPermalinkUrl = function (anchor: string) { if (!copyPermalink) return; let link = copyPermalink.getAttribute('data-url'); link = `${link.replace(/#L\d+$|#L\d+-L\d+$/, '')}#${anchor}`; @@ -142,13 +142,7 @@ export function initRepoCodeView() { }); } selectRange($(linesEls), $(selectedEls), from ? $(from) : null); - - if (window.getSelection) { - window.getSelection().removeAllRanges(); - } else { - document.selection.empty(); - } - + window.getSelection().removeAllRanges(); showLineButton(); }); diff --git a/web_src/js/features/repo-common.ts b/web_src/js/features/repo-common.ts index c246d5b4b0..5185a7ca43 100644 --- a/web_src/js/features/repo-common.ts +++ b/web_src/js/features/repo-common.ts @@ -64,7 +64,7 @@ export function initRepoCloneLink() { }); } -export function initRepoCommonBranchOrTagDropdown(selector) { +export function initRepoCommonBranchOrTagDropdown(selector: string) { $(selector).each(function () { const $dropdown = $(this); $dropdown.find('.reference.column').on('click', function () { @@ -75,7 +75,7 @@ export function initRepoCommonBranchOrTagDropdown(selector) { }); } -export function initRepoCommonFilterSearchDropdown(selector) { +export function initRepoCommonFilterSearchDropdown(selector: string) { const $dropdown = $(selector); if (!$dropdown.length) return; diff --git a/web_src/js/features/repo-diff-commit.ts b/web_src/js/features/repo-diff-commit.ts index c115e6300a..b270fb8568 100644 --- a/web_src/js/features/repo-diff-commit.ts +++ b/web_src/js/features/repo-diff-commit.ts @@ -1,7 +1,7 @@ import {hideElem, showElem, toggleElem} from '../utils/dom.ts'; import {GET} from '../modules/fetch.ts'; -async function loadBranchesAndTags(area, loadingButton) { +async function loadBranchesAndTags(area: Element, loadingButton: Element) { loadingButton.classList.add('disabled'); try { const res = await GET(loadingButton.getAttribute('data-fetch-url')); @@ -15,7 +15,7 @@ async function loadBranchesAndTags(area, loadingButton) { } } -function addTags(area, tags) { +function addTags(area: Element, tags: Array>) { const tagArea = area.querySelector('.tag-area'); toggleElem(tagArea.parentElement, tags.length > 0); for (const tag of tags) { @@ -23,7 +23,7 @@ function addTags(area, tags) { } } -function addBranches(area, branches, defaultBranch) { +function addBranches(area: Element, branches: Array>, defaultBranch: string) { const defaultBranchTooltip = area.getAttribute('data-text-default-branch-tooltip'); const branchArea = area.querySelector('.branch-area'); toggleElem(branchArea.parentElement, branches.length > 0); @@ -33,7 +33,7 @@ function addBranches(area, branches, defaultBranch) { } } -function addLink(parent, href, text, tooltip) { +function addLink(parent: Element, href: string, text: string, tooltip?: string) { const link = document.createElement('a'); link.classList.add('muted', 'tw-px-1'); link.href = href; diff --git a/web_src/js/features/repo-graph.ts b/web_src/js/features/repo-graph.ts index 231a726653..c9740dbedf 100644 --- a/web_src/js/features/repo-graph.ts +++ b/web_src/js/features/repo-graph.ts @@ -22,7 +22,7 @@ export function initRepoGraphGit() { for (const link of document.querySelectorAll('.pagination a')) { const href = link.getAttribute('href'); if (!href) continue; - const url = new URL(href, window.location); + const url = new URL(href, window.location.href); const params = url.searchParams; params.set('mode', 'monochrome'); url.search = `?${params.toString()}`; @@ -38,7 +38,7 @@ export function initRepoGraphGit() { for (const link of document.querySelectorAll('.pagination a')) { const href = link.getAttribute('href'); if (!href) continue; - const url = new URL(href, window.location); + const url = new URL(href, window.location.href); const params = url.searchParams; params.delete('mode'); url.search = `?${params.toString()}`; @@ -53,7 +53,7 @@ export function initRepoGraphGit() { window.history.replaceState({}, '', window.location.pathname); } }); - const url = new URL(window.location); + const url = new URL(window.location.href); const params = url.searchParams; const updateGraph = () => { const queryString = params.toString(); @@ -103,7 +103,7 @@ export function initRepoGraphGit() { }, onAdd(toAdd) { if (toAdd === '...flow-hide-pr-refs') { - params.set('hide-pr-refs', true); + params.set('hide-pr-refs', 'true'); } else { params.append('branch', toAdd); } @@ -111,7 +111,7 @@ export function initRepoGraphGit() { }, }); - graphContainer.addEventListener('mouseenter', (e) => { + graphContainer.addEventListener('mouseenter', (e: MouseEvent & {target: HTMLElement}) => { if (e.target.matches('#rev-list li')) { const flow = e.target.getAttribute('data-flow'); if (flow === '0') return; @@ -132,7 +132,7 @@ export function initRepoGraphGit() { } }); - graphContainer.addEventListener('mouseleave', (e) => { + graphContainer.addEventListener('mouseleave', (e: MouseEvent & {target: HTMLElement}) => { if (e.target.matches('#rev-list li')) { const flow = e.target.getAttribute('data-flow'); if (flow === '0') return; diff --git a/web_src/js/features/repo-home.ts b/web_src/js/features/repo-home.ts index df52b87f5a..4c69a00434 100644 --- a/web_src/js/features/repo-home.ts +++ b/web_src/js/features/repo-home.ts @@ -1,7 +1,7 @@ import {stripTags} from '../utils.ts'; import {hideElem, queryElemChildren, showElem} from '../utils/dom.ts'; import {POST} from '../modules/fetch.ts'; -import {showErrorToast} from '../modules/toast.ts'; +import {showErrorToast, type Toast} from '../modules/toast.ts'; import {fomanticQuery} from '../modules/fomantic/base.ts'; const {appSubUrl} = window.config; @@ -13,7 +13,7 @@ export function initRepoTopicBar() { const editDiv = document.querySelector('#topic_edit'); const viewDiv = document.querySelector('#repo-topics'); const topicDropdown = editDiv.querySelector('.ui.dropdown'); - let lastErrorToast; + let lastErrorToast: Toast; mgrBtn.addEventListener('click', () => { hideElem(viewDiv); diff --git a/web_src/js/features/repo-issue-pr-status.ts b/web_src/js/features/repo-issue-pr-status.ts index 7890b9c48d..8426b389f0 100644 --- a/web_src/js/features/repo-issue-pr-status.ts +++ b/web_src/js/features/repo-issue-pr-status.ts @@ -1,7 +1,7 @@ export function initRepoPullRequestCommitStatus() { for (const btn of document.querySelectorAll('.commit-status-hide-checks')) { const panel = btn.closest('.commit-status-panel'); - const list = panel.querySelector('.commit-status-list'); + const list = panel.querySelector('.commit-status-list'); btn.addEventListener('click', () => { list.style.maxHeight = list.style.maxHeight ? '' : '0px'; // toggle btn.textContent = btn.getAttribute(list.style.maxHeight ? 'data-show-all' : 'data-hide-all'); diff --git a/web_src/js/features/repo-issue.ts b/web_src/js/features/repo-issue.ts index e4f9ce4cde..7541039786 100644 --- a/web_src/js/features/repo-issue.ts +++ b/web_src/js/features/repo-issue.ts @@ -124,7 +124,7 @@ export function initRepoIssueFilterItemLabel() { export function initRepoIssueCommentDelete() { // Delete comment - document.addEventListener('click', async (e) => { + document.addEventListener('click', async (e: MouseEvent & {target: HTMLElement}) => { if (!e.target.matches('.delete-comment')) return; e.preventDefault(); @@ -143,7 +143,7 @@ export function initRepoIssueCommentDelete() { const counter = document.querySelector('#review-box .review-comments-counter'); let num = parseInt(counter?.getAttribute('data-pending-comment-number')) - 1 || 0; num = Math.max(num, 0); - counter.setAttribute('data-pending-comment-number', num); + counter.setAttribute('data-pending-comment-number', String(num)); counter.textContent = String(num); } @@ -199,7 +199,7 @@ export function initRepoIssueDependencyDelete() { export function initRepoIssueCodeCommentCancel() { // Cancel inline code comment - document.addEventListener('click', (e) => { + document.addEventListener('click', (e: MouseEvent & {target: HTMLElement}) => { if (!e.target.matches('.cancel-code-comment')) return; const form = e.target.closest('form'); @@ -268,12 +268,14 @@ export function initRepoPullRequestMergeInstruction() { export function initRepoPullRequestAllowMaintainerEdit() { const wrapper = document.querySelector('#allow-edits-from-maintainers'); if (!wrapper) return; - const checkbox = wrapper.querySelector('input[type="checkbox"]'); + const checkbox = wrapper.querySelector('input[type="checkbox"]'); checkbox.addEventListener('input', async () => { const url = `${wrapper.getAttribute('data-url')}/set_allow_maintainer_edit`; wrapper.classList.add('is-loading'); try { - const resp = await POST(url, {data: new URLSearchParams({allow_maintainer_edit: checkbox.checked})}); + const resp = await POST(url, {data: new URLSearchParams({ + allow_maintainer_edit: String(checkbox.checked), + })}); if (!resp.ok) { throw new Error('Failed to update maintainer edit permission'); } @@ -322,7 +324,7 @@ export function initRepoIssueWipTitle() { const $issueTitle = $('#issue_title'); $issueTitle.trigger('focus'); - const value = $issueTitle.val().trim().toUpperCase(); + const value = ($issueTitle.val() as string).trim().toUpperCase(); const wipPrefixes = $('.title_wip_desc').data('wip-prefixes'); for (const prefix of wipPrefixes) { @@ -338,7 +340,7 @@ export function initRepoIssueWipTitle() { export function initRepoIssueComments() { if (!$('.repository.view.issue .timeline').length) return; - document.addEventListener('click', (e) => { + document.addEventListener('click', (e: MouseEvent & {target: HTMLElement}) => { const urlTarget = document.querySelector(':target'); if (!urlTarget) return; @@ -490,7 +492,7 @@ export function initRepoPullRequestReview() { export function initRepoIssueReferenceIssue() { // Reference issue - $(document).on('click', '.reference-issue', function (event) { + $(document).on('click', '.reference-issue', function (e) { const target = this.getAttribute('data-target'); const content = document.querySelector(`#${target}`)?.textContent ?? ''; const poster = this.getAttribute('data-poster-username'); @@ -500,7 +502,7 @@ export function initRepoIssueReferenceIssue() { const textarea = modal.querySelector('textarea[name="content"]'); textarea.value = `${content}\n\n_Originally posted by @${poster} in ${reference}_`; $(modal).modal('show'); - event.preventDefault(); + e.preventDefault(); }); } @@ -584,7 +586,7 @@ export function initRepoIssueTitleEdit() { } export function initRepoIssueBranchSelect() { - document.querySelector('#branch-select')?.addEventListener('click', (e) => { + document.querySelector('#branch-select')?.addEventListener('click', (e: MouseEvent & {target: HTMLElement}) => { const el = e.target.closest('.item[data-branch]'); if (!el) return; const pullTargetBranch = document.querySelector('#pull-target-branch'); diff --git a/web_src/js/features/repo-migration.ts b/web_src/js/features/repo-migration.ts index 8f79ee1423..fb9c822f98 100644 --- a/web_src/js/features/repo-migration.ts +++ b/web_src/js/features/repo-migration.ts @@ -1,14 +1,14 @@ import {hideElem, showElem, toggleElem} from '../utils/dom.ts'; -const service = document.querySelector('#service_type'); -const user = document.querySelector('#auth_username'); -const pass = document.querySelector('#auth_password'); -const token = document.querySelector('#auth_token'); -const mirror = document.querySelector('#mirror'); -const lfs = document.querySelector('#lfs'); -const lfsSettings = document.querySelector('#lfs_settings'); -const lfsEndpoint = document.querySelector('#lfs_endpoint'); -const items = document.querySelectorAll('#migrate_items input[type=checkbox]'); +const service = document.querySelector('#service_type'); +const user = document.querySelector('#auth_username'); +const pass = document.querySelector('#auth_password'); +const token = document.querySelector('#auth_token'); +const mirror = document.querySelector('#mirror'); +const lfs = document.querySelector('#lfs'); +const lfsSettings = document.querySelector('#lfs_settings'); +const lfsEndpoint = document.querySelector('#lfs_endpoint'); +const items = document.querySelectorAll('#migrate_items input[type=checkbox]'); export function initRepoMigration() { checkAuth(); @@ -25,11 +25,11 @@ export function initRepoMigration() { }); lfs?.addEventListener('change', setLFSSettingsVisibility); - const cloneAddr = document.querySelector('#clone_addr'); + const cloneAddr = document.querySelector('#clone_addr'); cloneAddr?.addEventListener('change', () => { - const repoName = document.querySelector('#repo_name'); + const repoName = document.querySelector('#repo_name'); if (cloneAddr.value && !repoName?.value) { // Only modify if repo_name input is blank - repoName.value = cloneAddr.value.match(/^(.*\/)?((.+?)(\.git)?)$/)[3]; + repoName.value = /^(.*\/)?((.+?)(\.git)?)$/.exec(cloneAddr.value)[3]; } }); } @@ -41,8 +41,8 @@ function checkAuth() { checkItems(serviceType !== 1); } -function checkItems(tokenAuth) { - let enableItems; +function checkItems(tokenAuth: boolean) { + let enableItems = false; if (tokenAuth) { enableItems = token?.value !== ''; } else { diff --git a/web_src/js/features/repo-new.ts b/web_src/js/features/repo-new.ts index 22d8c8a47b..436288325a 100644 --- a/web_src/js/features/repo-new.ts +++ b/web_src/js/features/repo-new.ts @@ -7,7 +7,7 @@ export function initRepoNew() { const gitignores = $('input[name="gitignores"]').val(); const license = $('input[name="license"]').val(); if (gitignores || license) { - document.querySelector('input[name="auto_init"]').checked = true; + document.querySelector('input[name="auto_init"]').checked = true; } }); } diff --git a/web_src/js/features/repo-projects.ts b/web_src/js/features/repo-projects.ts index bc2bb69a33..d1f0d17c44 100644 --- a/web_src/js/features/repo-projects.ts +++ b/web_src/js/features/repo-projects.ts @@ -25,7 +25,7 @@ async function createNewColumn(url, columnTitle, projectColorInput) { } } -async function moveIssue({item, from, to, oldIndex}) { +async function moveIssue({item, from, to, oldIndex}: {item: HTMLElement, from: HTMLElement, to: HTMLElement, oldIndex: number}) { const columnCards = to.querySelectorAll('.issue-card'); updateIssueCount(from); updateIssueCount(to); @@ -97,14 +97,14 @@ export function initRepoProject() { return; } - const _promise = initRepoProjectSortable(); + initRepoProjectSortable(); // no await for (const modal of document.querySelectorAll('.edit-project-column-modal')) { - const projectHeader = modal.closest('.project-column-header'); - const projectTitleLabel = projectHeader?.querySelector('.project-column-title-label'); - const projectTitleInput = modal.querySelector('.project-column-title-input'); - const projectColorInput = modal.querySelector('#new_project_column_color'); - const boardColumn = modal.closest('.project-column'); + const projectHeader = modal.closest('.project-column-header'); + const projectTitleLabel = projectHeader?.querySelector('.project-column-title-label'); + const projectTitleInput = modal.querySelector('.project-column-title-input'); + const projectColorInput = modal.querySelector('#new_project_column_color'); + const boardColumn = modal.closest('.project-column'); modal.querySelector('.edit-project-column-button')?.addEventListener('click', async function (e) { e.preventDefault(); try { @@ -119,7 +119,7 @@ export function initRepoProject() { } finally { projectTitleLabel.textContent = projectTitleInput?.value; projectTitleInput.closest('form')?.classList.remove('dirty'); - const dividers = boardColumn.querySelectorAll(':scope > .divider'); + const dividers = boardColumn.querySelectorAll(':scope > .divider'); if (projectColorInput.value) { const color = contrastColor(projectColorInput.value); boardColumn.style.setProperty('background', projectColorInput.value, 'important'); diff --git a/web_src/js/features/repo-release.ts b/web_src/js/features/repo-release.ts index c59ab1f323..683c57dad1 100644 --- a/web_src/js/features/repo-release.ts +++ b/web_src/js/features/repo-release.ts @@ -1,11 +1,11 @@ import {hideElem, showElem} from '../utils/dom.ts'; export function initRepoRelease() { - document.addEventListener('click', (e) => { + document.addEventListener('click', (e: MouseEvent & {target: HTMLElement}) => { if (e.target.matches('.remove-rel-attach')) { const uuid = e.target.getAttribute('data-uuid'); const id = e.target.getAttribute('data-id'); - document.querySelector(`input[name='attachment-del-${uuid}']`).value = 'true'; + document.querySelector(`input[name='attachment-del-${uuid}']`).value = 'true'; hideElem(`#attachment-${id}`); } }); @@ -28,8 +28,8 @@ function initTagNameEditor() { const newTagHelperText = el.getAttribute('data-tag-helper-new'); const existingTagHelperText = el.getAttribute('data-tag-helper-existing'); - const tagNameInput = document.querySelector('#tag-name'); - const hideTargetInput = function(tagNameInput) { + const tagNameInput = document.querySelector('#tag-name'); + const hideTargetInput = function(tagNameInput: HTMLInputElement) { const value = tagNameInput.value; const tagHelper = document.querySelector('#tag-helper'); if (existingTags.includes(value)) { @@ -42,7 +42,7 @@ function initTagNameEditor() { } }; hideTargetInput(tagNameInput); // update on page load because the input may have a value - tagNameInput.addEventListener('input', (e) => { + tagNameInput.addEventListener('input', (e: InputEvent & {target: HTMLInputElement}) => { hideTargetInput(e.target); }); } diff --git a/web_src/js/features/repo-search.ts b/web_src/js/features/repo-search.ts index 185f6119d9..9cc2dd4223 100644 --- a/web_src/js/features/repo-search.ts +++ b/web_src/js/features/repo-search.ts @@ -1,8 +1,8 @@ export function initRepositorySearch() { - const repositorySearchForm = document.querySelector('#repo-search-form'); + const repositorySearchForm = document.querySelector('#repo-search-form'); if (!repositorySearchForm) return; - repositorySearchForm.addEventListener('change', (e) => { + repositorySearchForm.addEventListener('change', (e: Event & {target: HTMLFormElement}) => { e.preventDefault(); const formData = new FormData(repositorySearchForm); diff --git a/web_src/js/features/repo-settings.ts b/web_src/js/features/repo-settings.ts index 9ea546f76d..5e7edb0402 100644 --- a/web_src/js/features/repo-settings.ts +++ b/web_src/js/features/repo-settings.ts @@ -73,7 +73,7 @@ function initRepoSettingsSearchTeamBox() { function initRepoSettingsGitHook() { if (!$('.edit.githook').length) return; const filename = document.querySelector('.hook-filename').textContent; - createMonaco($('#content')[0], filename, {language: 'shell'}); + createMonaco($('#content')[0] as HTMLTextAreaElement, filename, {language: 'shell'}); } function initRepoSettingsBranches() { @@ -99,7 +99,7 @@ function initRepoSettingsBranches() { // show the `Matched` mark for the status checks that match the pattern const markMatchedStatusChecks = () => { - const patterns = (document.querySelector('#status_check_contexts').value || '').split(/[\r\n]+/); + const patterns = (document.querySelector('#status_check_contexts').value || '').split(/[\r\n]+/); const validPatterns = patterns.map((item) => item.trim()).filter(Boolean); const marks = document.querySelectorAll('.status-check-matched-mark'); @@ -122,7 +122,7 @@ function initRepoSettingsBranches() { function initRepoSettingsOptions() { if ($('.repository.settings.options').length > 0) { // Enable or select internal/external wiki system and issue tracker. - $('.enable-system').on('change', function () { + $('.enable-system').on('change', function (this: HTMLInputElement) { if (this.checked) { $($(this).data('target')).removeClass('disabled'); if (!$(this).data('context')) $($(this).data('context')).addClass('disabled'); @@ -131,7 +131,7 @@ function initRepoSettingsOptions() { if (!$(this).data('context')) $($(this).data('context')).removeClass('disabled'); } }); - $('.enable-system-radio').on('change', function () { + $('.enable-system-radio').on('change', function (this: HTMLInputElement) { if (this.value === 'false') { $($(this).data('target')).addClass('disabled'); if ($(this).data('context') !== undefined) $($(this).data('context')).removeClass('disabled'); diff --git a/web_src/js/features/sshkey-helper.ts b/web_src/js/features/sshkey-helper.ts index 5531c18451..9234e3ec44 100644 --- a/web_src/js/features/sshkey-helper.ts +++ b/web_src/js/features/sshkey-helper.ts @@ -2,7 +2,7 @@ export function initSshKeyFormParser() { // Parse SSH Key document.querySelector('#ssh-key-content')?.addEventListener('input', function () { const arrays = this.value.split(' '); - const title = document.querySelector('#ssh-key-title'); + const title = document.querySelector('#ssh-key-title'); if (!title.value && arrays.length === 3 && arrays[2] !== '') { title.value = arrays[2]; } diff --git a/web_src/js/features/tablesort.ts b/web_src/js/features/tablesort.ts index 436fe0a594..15ea358fa3 100644 --- a/web_src/js/features/tablesort.ts +++ b/web_src/js/features/tablesort.ts @@ -13,7 +13,7 @@ function tableSort(normSort, revSort, isDefault) { if (!normSort) return false; if (!revSort) revSort = ''; - const url = new URL(window.location); + const url = new URL(window.location.href); let urlSort = url.searchParams.get('sort'); if (!urlSort && isDefault) urlSort = normSort; diff --git a/web_src/js/features/tribute.ts b/web_src/js/features/tribute.ts index 193c65076f..44588c0064 100644 --- a/web_src/js/features/tribute.ts +++ b/web_src/js/features/tribute.ts @@ -48,7 +48,7 @@ function makeCollections({mentions, emoji}) { return collections; } -export async function attachTribute(element, {mentions, emoji} = {}) { +export async function attachTribute(element, {mentions, emoji}) { const {default: Tribute} = await import(/* webpackChunkName: "tribute" */'tributejs'); const collections = makeCollections({mentions, emoji}); const tribute = new Tribute({collection: collections, noMatchTemplate: ''}); diff --git a/web_src/js/globals.d.ts b/web_src/js/globals.d.ts index 9964293727..9780a1cf3c 100644 --- a/web_src/js/globals.d.ts +++ b/web_src/js/globals.d.ts @@ -33,6 +33,7 @@ interface JQuery { modal: any; // fomantic tab: any; // fomantic transition: any, // fomantic + search: any, // fomantic } interface JQueryStatic { @@ -62,4 +63,5 @@ interface Window { turnstile: any, hcaptcha: any, codeEditors: any[], + updateCloneStates: () => void, } diff --git a/web_src/js/modules/toast.ts b/web_src/js/modules/toast.ts index 264ccbbdce..36e2321743 100644 --- a/web_src/js/modules/toast.ts +++ b/web_src/js/modules/toast.ts @@ -5,6 +5,9 @@ import Toastify from 'toastify-js'; // don't use "async import", because when ne import type {Intent} from '../types.ts'; import type {SvgName} from '../svg.ts'; import type {Options} from 'toastify-js'; +import type StartToastifyInstance from 'toastify-js'; + +export type Toast = ReturnType; type ToastLevels = { [intent in Intent]: { @@ -38,7 +41,7 @@ type ToastOpts = { } & Options; // See https://github.com/apvarun/toastify-js#api for options -function showToast(message: string, level: Intent, {gravity, position, duration, useHtmlBody, preventDuplicates = true, ...other}: ToastOpts = {}) { +function showToast(message: string, level: Intent, {gravity, position, duration, useHtmlBody, preventDuplicates = true, ...other}: ToastOpts = {}): Toast { const body = useHtmlBody ? String(message) : htmlEscape(message); const key = `${level}-${body}`; @@ -75,14 +78,14 @@ function showToast(message: string, level: Intent, {gravity, position, duration, return toast; } -export function showInfoToast(message: string, opts?: ToastOpts) { +export function showInfoToast(message: string, opts?: ToastOpts): Toast { return showToast(message, 'info', opts); } -export function showWarningToast(message: string, opts?: ToastOpts) { +export function showWarningToast(message: string, opts?: ToastOpts): Toast { return showToast(message, 'warning', opts); } -export function showErrorToast(message: string, opts?: ToastOpts) { +export function showErrorToast(message: string, opts?: ToastOpts): Toast { return showToast(message, 'error', opts); }