diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-12-27 21:28:38 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-27 21:28:38 +0900 |
| commit | 53898c50066366b23c507775c655599587a91673 (patch) | |
| tree | 537c9ef74f189bf9984ef3f0c3da4eded1a4aec9 /packages/frontend/src/scripts | |
| parent | Merge pull request #12564 from misskey-dev/develop (diff) | |
| parent | 2023.12.1 (diff) | |
| download | misskey-53898c50066366b23c507775c655599587a91673.tar.gz misskey-53898c50066366b23c507775c655599587a91673.tar.bz2 misskey-53898c50066366b23c507775c655599587a91673.zip | |
Merge pull request #12771 from misskey-dev/develop
Release: 2023.12.1
Diffstat (limited to 'packages/frontend/src/scripts')
5 files changed, 75 insertions, 4 deletions
diff --git a/packages/frontend/src/scripts/aiscript/ui.ts b/packages/frontend/src/scripts/aiscript/ui.ts index 75b9248432..08ba1e6d9b 100644 --- a/packages/frontend/src/scripts/aiscript/ui.ts +++ b/packages/frontend/src/scripts/aiscript/ui.ts @@ -47,6 +47,7 @@ export type AsUiMfm = AsUiComponentBase & { bold?: boolean; color?: string; font?: 'serif' | 'sans-serif' | 'monospace'; + onClickEv?: (evId: string) => void }; export type AsUiButton = AsUiComponentBase & { @@ -230,6 +231,8 @@ function getMfmOptions(def: values.Value | undefined): Omit<AsUiMfm, 'id' | 'typ if (color) utils.assertString(color); const font = def.value.get('font'); if (font) utils.assertString(font); + const onClickEv = def.value.get('onClickEv'); + if (onClickEv) utils.assertFunction(onClickEv); return { text: text?.value, @@ -237,6 +240,9 @@ function getMfmOptions(def: values.Value | undefined): Omit<AsUiMfm, 'id' | 'typ bold: bold?.value, color: color?.value, font: font?.value, + onClickEv: (evId: string) => { + if (onClickEv) call(onClickEv, values.STR(evId)); + }, }; } diff --git a/packages/frontend/src/scripts/get-note-menu.ts b/packages/frontend/src/scripts/get-note-menu.ts index 50d76167fe..7130e69279 100644 --- a/packages/frontend/src/scripts/get-note-menu.ts +++ b/packages/frontend/src/scripts/get-note-menu.ts @@ -122,7 +122,7 @@ export function getCopyNoteLinkMenu(note: Misskey.entities.Note, text: string): export function getNoteMenu(props: { note: Misskey.entities.Note; menuButton: Ref<HTMLElement>; - translation: Ref<any>; + translation: Ref<Misskey.entities.NotesTranslateResponse | null>; translating: Ref<boolean>; isDeleted: Ref<boolean>; currentClip?: Misskey.entities.Clip; diff --git a/packages/frontend/src/scripts/mfm-function-picker.ts b/packages/frontend/src/scripts/mfm-function-picker.ts new file mode 100644 index 0000000000..465926fe04 --- /dev/null +++ b/packages/frontend/src/scripts/mfm-function-picker.ts @@ -0,0 +1,61 @@ +/* + * SPDX-FileCopyrightText: syuilo and other misskey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Ref, nextTick } from 'vue'; +import * as os from '@/os.js'; +import { i18n } from '@/i18n.js'; +import { MFM_TAGS } from '@/const.js'; + +/** + * MFMの装飾のリストを表示する + */ +export function mfmFunctionPicker(src: any, textArea: HTMLInputElement | HTMLTextAreaElement, textRef: Ref<string>) { + return new Promise((res, rej) => { + os.popupMenu([{ + text: i18n.ts.addMfmFunction, + type: 'label', + }, ...getFunctionList(textArea, textRef)], src); + }); +} + +function getFunctionList(textArea: HTMLInputElement | HTMLTextAreaElement, textRef: Ref<string>) : object[] { + const ret: object[] = []; + MFM_TAGS.forEach(tag => { + ret.push({ + text: tag, + icon: 'ti ti-icons', + action: () => add(textArea, textRef, tag), + }); + }); + return ret; +} + +function add(textArea: HTMLInputElement | HTMLTextAreaElement, textRef: Ref<string>, type: string) { + const caretStart: number = textArea.selectionStart as number; + const caretEnd: number = textArea.selectionEnd as number; + + MFM_TAGS.forEach(tag => { + if (type === tag) { + if (caretStart === caretEnd) { + // 単純にFunctionを追加 + const trimmedText = `${textRef.value.substring(0, caretStart)}$[${type} ]${textRef.value.substring(caretEnd)}`; + textRef.value = trimmedText; + } else { + // 選択範囲を囲むようにFunctionを追加 + const trimmedText = `${textRef.value.substring(0, caretStart)}$[${type} ${textRef.value.substring(caretStart, caretEnd)}]${textRef.value.substring(caretEnd)}`; + textRef.value = trimmedText; + } + } + }); + + const nextCaretStart: number = caretStart + 3 + type.length; + const nextCaretEnd: number = caretEnd + 3 + type.length; + + // キャレットを戻す + nextTick(() => { + textArea.focus(); + textArea.setSelectionRange(nextCaretStart, nextCaretEnd); + }); +} diff --git a/packages/frontend/src/scripts/upload/compress-config.ts b/packages/frontend/src/scripts/upload/compress-config.ts index 8fe64c8b76..2deb9cbb81 100644 --- a/packages/frontend/src/scripts/upload/compress-config.ts +++ b/packages/frontend/src/scripts/upload/compress-config.ts @@ -4,7 +4,7 @@ */ import isAnimated from 'is-file-animated'; -import { isWebpSupported } from './isWebpSupported'; +import { isWebpSupported } from './isWebpSupported.js'; import type { BrowserImageResizerConfig } from 'browser-image-resizer'; const compressTypeMap = { diff --git a/packages/frontend/src/scripts/use-chart-tooltip.ts b/packages/frontend/src/scripts/use-chart-tooltip.ts index daf915c7e3..3d6489c3b8 100644 --- a/packages/frontend/src/scripts/use-chart-tooltip.ts +++ b/packages/frontend/src/scripts/use-chart-tooltip.ts @@ -11,8 +11,12 @@ export function useChartTooltip(opts: { position: 'top' | 'middle' } = { positio const tooltipShowing = ref(false); const tooltipX = ref(0); const tooltipY = ref(0); - const tooltipTitle = ref(null); - const tooltipSeries = ref(null); + const tooltipTitle = ref<string | null>(null); + const tooltipSeries = ref<{ + backgroundColor: string; + borderColor: string; + text: string; + }[] | null>(null); let disposeTooltipComponent; os.popup(MkChartTooltip, { |