mirror of
https://github.com/go-gitea/gitea.git
synced 2026-02-10 05:48:51 +00:00
Misc typescript tweaks (#36523)
Some minor refactors, disable one obsolete lint rule, fix another. The tribute type issue is not fully fixed and I'm pretty sure it must be an error in their types.
This commit is contained in:
@@ -342,7 +342,7 @@ export default defineConfig([
|
||||
'import-x/first': [2],
|
||||
'import-x/group-exports': [0],
|
||||
'import-x/max-dependencies': [0],
|
||||
'import-x/named': [2],
|
||||
'import-x/named': [0],
|
||||
'import-x/namespace': [0],
|
||||
'import-x/newline-after-import': [0],
|
||||
'import-x/no-absolute-path': [0],
|
||||
@@ -987,7 +987,7 @@ export default defineConfig([
|
||||
'vitest/require-to-throw-message': [0],
|
||||
'vitest/require-top-level-describe': [0],
|
||||
'vitest/valid-describe-callback': [2],
|
||||
'vitest/valid-expect': [2],
|
||||
'vitest/valid-expect': [2, {maxArgs: 2}],
|
||||
'vitest/valid-title': [2],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {emojiKeys, emojiHTML, emojiString} from './emoji.ts';
|
||||
import {html, htmlRaw} from '../utils/html.ts';
|
||||
import type {TributeCollection} from 'tributejs';
|
||||
import type {MentionValue} from '../types.ts';
|
||||
|
||||
export async function attachTribute(element: HTMLElement) {
|
||||
const {default: Tribute} = await import(/* webpackChunkName: "tribute" */'tributejs');
|
||||
@@ -28,7 +29,7 @@ export async function attachTribute(element: HTMLElement) {
|
||||
},
|
||||
};
|
||||
|
||||
const mentionCollection: TributeCollection<Record<string, any>> = {
|
||||
const mentionCollection: TributeCollection<MentionValue> = {
|
||||
values: window.config.mentionValues,
|
||||
requireLeadingSpace: true,
|
||||
menuItemTemplate: (item) => {
|
||||
@@ -44,7 +45,10 @@ export async function attachTribute(element: HTMLElement) {
|
||||
};
|
||||
|
||||
const tribute = new Tribute({
|
||||
collection: [emojiCollection as TributeCollection<any>, mentionCollection],
|
||||
collection: [
|
||||
emojiCollection as TributeCollection<any>,
|
||||
mentionCollection as TributeCollection<any>,
|
||||
],
|
||||
noMatchTemplate: () => '',
|
||||
});
|
||||
tribute.attach(element);
|
||||
|
||||
8
web_src/js/globals.d.ts
vendored
8
web_src/js/globals.d.ts
vendored
@@ -29,13 +29,7 @@ interface Window {
|
||||
pageData: Record<string, any>,
|
||||
notificationSettings: Record<string, any>,
|
||||
enableTimeTracking: boolean,
|
||||
mentionValues: Array<{
|
||||
key: string,
|
||||
value: string,
|
||||
name: string,
|
||||
fullname: string,
|
||||
avatar: string,
|
||||
}>,
|
||||
mentionValues: Array<import('./types.ts').MentionValue>,
|
||||
mermaidMaxSourceCharacters: number,
|
||||
i18n: Record<string, string>,
|
||||
},
|
||||
|
||||
@@ -31,7 +31,7 @@ export function renderAnsi(line: string): string {
|
||||
|
||||
// handle "\rReading...1%\rReading...5%\rReading...100%",
|
||||
// convert it into a multiple-line string: "Reading...1%\nReading...5%\nReading...100%"
|
||||
const lines = [];
|
||||
const lines: Array<string> = [];
|
||||
for (const part of line.split('\r')) {
|
||||
if (part === '') continue;
|
||||
const partHtml = ansi_up.ansi_to_html(part);
|
||||
|
||||
@@ -2,6 +2,14 @@ export type IntervalId = ReturnType<typeof setInterval>;
|
||||
|
||||
export type Intent = 'error' | 'warning' | 'info';
|
||||
|
||||
export type MentionValue = {
|
||||
key: string,
|
||||
value: string,
|
||||
name: string,
|
||||
fullname: string,
|
||||
avatar: string,
|
||||
};
|
||||
|
||||
export type RequestData = string | FormData | URLSearchParams | Record<string, any>;
|
||||
|
||||
export type RequestOpts = {
|
||||
|
||||
@@ -117,7 +117,6 @@ test('GlobCompiler', async () => {
|
||||
for (const c of golangCases) {
|
||||
const compiled = globCompile(c.pattern, c.separators);
|
||||
const msg = `pattern: ${c.pattern}, input: ${c.input}, separators: ${c.separators || '(none)'}, compiled: ${compiled.regexpPattern}`;
|
||||
// eslint-disable-next-line vitest/valid-expect -- Unlike Jest, Vitest supports a message as the second argument
|
||||
expect(compiled.regexp.test(c.input), msg).toBe(c.matched);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user