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