mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 05:18:29 +00:00
Enable TypeScript strictNullChecks (#35843)
A big step towards enabling strict mode in Typescript. There was definitely a good share of potential bugs while refactoring this. When in doubt, I opted to keep the potentially broken behaviour. Notably, the `DOMEvent` type is gone, it was broken and we're better of with type assertions on `e.target`. --------- Signed-off-by: silverwind <me@silverwind.io> Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -7,7 +7,7 @@ const hasPrefix = (str: string): boolean => str.startsWith('user-content-');
|
||||
// scroll to anchor while respecting the `user-content` prefix that exists on the target
|
||||
function scrollToAnchor(encodedId?: string): void {
|
||||
// FIXME: need to rewrite this function with new a better markup anchor generation logic, too many tricks here
|
||||
let elemId: string;
|
||||
let elemId: string | undefined;
|
||||
try {
|
||||
elemId = decodeURIComponent(encodedId ?? '');
|
||||
} catch {} // ignore the errors, since the "encodedId" is from user's input
|
||||
@@ -44,7 +44,7 @@ export function initMarkupAnchors(): void {
|
||||
// remove `user-content-` prefix from links so they don't show in url bar when clicked
|
||||
for (const a of markupEl.querySelectorAll<HTMLAnchorElement>('a[href^="#"]')) {
|
||||
const href = a.getAttribute('href');
|
||||
if (!href.startsWith('#user-content-')) continue;
|
||||
if (!href?.startsWith('#user-content-')) continue;
|
||||
a.setAttribute('href', `#${removePrefix(href.substring(1))}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,6 @@ export function initMarkupCodeCopy(elMarkup: HTMLElement): void {
|
||||
btn.setAttribute('data-clipboard-text', el.textContent.replace(/\r?\n$/, ''));
|
||||
// we only want to use `.code-block-container` if it exists, no matter `.code-block` exists or not.
|
||||
const btnContainer = el.closest('.code-block-container') ?? el.closest('.code-block');
|
||||
btnContainer.append(btn);
|
||||
btnContainer!.append(btn);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ export async function initMarkupCodeMermaid(elMarkup: HTMLElement): Promise<void
|
||||
});
|
||||
|
||||
const pre = el.closest('pre');
|
||||
if (pre.hasAttribute('data-render-done')) return;
|
||||
if (!pre || pre.hasAttribute('data-render-done')) return;
|
||||
|
||||
const source = el.textContent;
|
||||
if (mermaidMaxSourceCharacters >= 0 && source.length > mermaidMaxSourceCharacters) {
|
||||
|
||||
@@ -16,7 +16,7 @@ export function showMarkupRefIssuePopup(e: MouseEvent | FocusEvent) {
|
||||
if (getAttachedTippyInstance(refIssue)) return;
|
||||
if (refIssue.classList.contains('ref-external-issue')) return;
|
||||
|
||||
const issuePathInfo = parseIssueHref(refIssue.getAttribute('href'));
|
||||
const issuePathInfo = parseIssueHref(refIssue.getAttribute('href')!);
|
||||
if (!issuePathInfo.ownerName) return;
|
||||
|
||||
const el = document.createElement('div');
|
||||
|
||||
@@ -2,7 +2,7 @@ import {generateElemId, queryElemChildren} from '../utils/dom.ts';
|
||||
import {isDarkTheme} from '../utils.ts';
|
||||
|
||||
export async function loadRenderIframeContent(iframe: HTMLIFrameElement) {
|
||||
const iframeSrcUrl = iframe.getAttribute('data-src');
|
||||
const iframeSrcUrl = iframe.getAttribute('data-src')!;
|
||||
if (!iframe.id) iframe.id = generateElemId('gitea-iframe-');
|
||||
|
||||
window.addEventListener('message', (e) => {
|
||||
|
||||
@@ -13,7 +13,7 @@ const preventListener = (e: Event) => e.preventDefault();
|
||||
export function initMarkupTasklist(elMarkup: HTMLElement): void {
|
||||
if (!elMarkup.matches('[data-can-edit=true]')) return;
|
||||
|
||||
const container = elMarkup.parentNode;
|
||||
const container = elMarkup.parentNode!;
|
||||
const checkboxes = elMarkup.querySelectorAll<HTMLInputElement>(`.task-list-item input[type=checkbox]`);
|
||||
|
||||
for (const checkbox of checkboxes) {
|
||||
@@ -24,9 +24,9 @@ export function initMarkupTasklist(elMarkup: HTMLElement): void {
|
||||
checkbox.setAttribute('data-editable', 'true');
|
||||
checkbox.addEventListener('input', async () => {
|
||||
const checkboxCharacter = checkbox.checked ? 'x' : ' ';
|
||||
const position = parseInt(checkbox.getAttribute('data-source-position')) + 1;
|
||||
const position = parseInt(checkbox.getAttribute('data-source-position')!) + 1;
|
||||
|
||||
const rawContent = container.querySelector('.raw-content');
|
||||
const rawContent = container.querySelector('.raw-content')!;
|
||||
const oldContent = rawContent.textContent;
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
@@ -53,10 +53,10 @@ export function initMarkupTasklist(elMarkup: HTMLElement): void {
|
||||
}
|
||||
|
||||
try {
|
||||
const editContentZone = container.querySelector<HTMLDivElement>('.edit-content-zone');
|
||||
const updateUrl = editContentZone.getAttribute('data-update-url');
|
||||
const context = editContentZone.getAttribute('data-context');
|
||||
const contentVersion = editContentZone.getAttribute('data-content-version');
|
||||
const editContentZone = container.querySelector<HTMLDivElement>('.edit-content-zone')!;
|
||||
const updateUrl = editContentZone.getAttribute('data-update-url')!;
|
||||
const context = editContentZone.getAttribute('data-context')!;
|
||||
const contentVersion = editContentZone.getAttribute('data-content-version')!;
|
||||
|
||||
const requestBody = new FormData();
|
||||
requestBody.append('ignore_attachments', 'true');
|
||||
|
||||
Reference in New Issue
Block a user