refactor(frontend): Improve typing (#14240)

* Improve typing

* Remove redundant promise

* Refactor

* Update packages/frontend/src/scripts/mfm-function-picker.ts

Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>

* Update packages/frontend/src/scripts/mfm-function-picker.ts

Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>

---------

Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
This commit is contained in:
woxtu 2024-07-18 00:31:52 +09:00 committed by GitHub
parent 68bcd91d57
commit 6942a920c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 17 deletions

View File

@ -7,29 +7,24 @@ import { Ref, nextTick } from 'vue';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { MFM_TAGS } from '@/const.js'; import { MFM_TAGS } from '@/const.js';
import type { MenuItem } from '@/types/menu.js';
/** /**
* MFMの装飾のリストを表示する * MFMの装飾のリストを表示する
*/ */
export function mfmFunctionPicker(src: any, textArea: HTMLInputElement | HTMLTextAreaElement, textRef: Ref<string>) { export function mfmFunctionPicker(src: HTMLElement | EventTarget | null, textArea: HTMLInputElement | HTMLTextAreaElement, textRef: Ref<string>) {
return new Promise((res, rej) => { os.popupMenu([{
os.popupMenu([{ text: i18n.ts.addMfmFunction,
text: i18n.ts.addMfmFunction, type: 'label',
type: 'label', }, ...getFunctionList(textArea, textRef)], src);
}, ...getFunctionList(textArea, textRef)], src);
});
} }
function getFunctionList(textArea: HTMLInputElement | HTMLTextAreaElement, textRef: Ref<string>) : object[] { function getFunctionList(textArea: HTMLInputElement | HTMLTextAreaElement, textRef: Ref<string>): MenuItem[] {
const ret: object[] = []; return MFM_TAGS.map(tag => ({
MFM_TAGS.forEach(tag => { text: tag,
ret.push({ icon: 'ti ti-icons',
text: tag, action: () => add(textArea, textRef, tag),
icon: 'ti ti-icons', }));
action: () => add(textArea, textRef, tag),
});
});
return ret;
} }
function add(textArea: HTMLInputElement | HTMLTextAreaElement, textRef: Ref<string>, type: string) { function add(textArea: HTMLInputElement | HTMLTextAreaElement, textRef: Ref<string>, type: string) {