mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-03 20:36:07 +01: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:
		@@ -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<HTMLFormElement>(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<HTMLInputElement>('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');
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Record<string, any>>) {
 | 
			
		||||
  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<Record<string, any>>, 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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<HTMLElement>('.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');
 | 
			
		||||
 
 | 
			
		||||
@@ -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<HTMLInputElement>('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');
 | 
			
		||||
 
 | 
			
		||||
@@ -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<HTMLInputElement>('#service_type');
 | 
			
		||||
const user = document.querySelector<HTMLInputElement>('#auth_username');
 | 
			
		||||
const pass = document.querySelector<HTMLInputElement>('#auth_password');
 | 
			
		||||
const token = document.querySelector<HTMLInputElement>('#auth_token');
 | 
			
		||||
const mirror = document.querySelector<HTMLInputElement>('#mirror');
 | 
			
		||||
const lfs = document.querySelector<HTMLInputElement>('#lfs');
 | 
			
		||||
const lfsSettings = document.querySelector<HTMLElement>('#lfs_settings');
 | 
			
		||||
const lfsEndpoint = document.querySelector<HTMLElement>('#lfs_endpoint');
 | 
			
		||||
const items = document.querySelectorAll<HTMLInputElement>('#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<HTMLInputElement>('#clone_addr');
 | 
			
		||||
  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
 | 
			
		||||
      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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -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<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');
 | 
			
		||||
  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<HTMLElement>('.project-column-header');
 | 
			
		||||
    const projectTitleLabel = projectHeader?.querySelector<HTMLElement>('.project-column-title-label');
 | 
			
		||||
    const projectTitleInput = modal.querySelector<HTMLInputElement>('.project-column-title-input');
 | 
			
		||||
    const projectColorInput = modal.querySelector<HTMLInputElement>('#new_project_column_color');
 | 
			
		||||
    const boardColumn = modal.closest<HTMLElement>('.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<HTMLElement>(':scope > .divider');
 | 
			
		||||
        if (projectColorInput.value) {
 | 
			
		||||
          const color = contrastColor(projectColorInput.value);
 | 
			
		||||
          boardColumn.style.setProperty('background', projectColorInput.value, 'important');
 | 
			
		||||
 
 | 
			
		||||
@@ -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<HTMLInputElement>(`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<HTMLInputElement>('#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);
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
export function initRepositorySearch() {
 | 
			
		||||
  const repositorySearchForm = document.querySelector('#repo-search-form');
 | 
			
		||||
  const repositorySearchForm = document.querySelector<HTMLFormElement>('#repo-search-form');
 | 
			
		||||
  if (!repositorySearchForm) return;
 | 
			
		||||
 | 
			
		||||
  repositorySearchForm.addEventListener('change', (e) => {
 | 
			
		||||
  repositorySearchForm.addEventListener('change', (e: Event & {target: HTMLFormElement}) => {
 | 
			
		||||
    e.preventDefault();
 | 
			
		||||
 | 
			
		||||
    const formData = new FormData(repositorySearchForm);
 | 
			
		||||
 
 | 
			
		||||
@@ -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<HTMLTextAreaElement>('#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');
 | 
			
		||||
 
 | 
			
		||||
@@ -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<HTMLInputElement>('#ssh-key-title');
 | 
			
		||||
    if (!title.value && arrays.length === 3 && arrays[2] !== '') {
 | 
			
		||||
      title.value = arrays[2];
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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: ''});
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										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
 | 
			
		||||
  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,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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<typeof StartToastifyInstance>;
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user