diff --git a/CHANGELOG.md b/CHANGELOG.md index 5db3783e1..e452eb384 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ ### Client - Fix: 一部のモデログ(logYellowでの表示対象)について、表示の色が変わらない問題を修正 +- Feat: AiScript専用のMFM構文`$[clickable.ev=EVENTNAME ...]`を追加。`Mk:C:mfm`のオプション`onClickEv`に関数を渡すと、クリック時に`EVENTNAME`を引数にして呼び出す ### Server - Enhance: センシティブワードの設定がハッシュタグトレンドにも適用されるようになりました diff --git a/packages/frontend/src/components/MkAsUi.vue b/packages/frontend/src/components/MkAsUi.vue index 60978eb0b..8475233df 100644 --- a/packages/frontend/src/components/MkAsUi.vue +++ b/packages/frontend/src/components/MkAsUi.vue @@ -11,7 +11,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{ c.text }} - + {{ c.text }}
{{ button.text }} diff --git a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts index 4c6034c90..33d5786fb 100644 --- a/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts +++ b/packages/frontend/src/components/global/MkMisskeyFlavoredMarkdown.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { VNode, h, defineAsyncComponent } from 'vue'; +import { VNode, h, defineAsyncComponent, SetupContext } from 'vue'; import * as mfm from '@sharkey/sfm-js'; import * as Misskey from 'misskey-js'; import MkUrl from '@/components/global/MkUrl.vue'; @@ -44,8 +44,12 @@ type MfmProps = { isAnim?: boolean; }; +type MfmEvents = { + clickEv(id: string): void; +}; + // eslint-disable-next-line import/no-default-export -export default function(props: MfmProps) { +export default function(props: MfmProps, context: SetupContext) { const isNote = props.isNote ?? true; const shouldNyaize = props.nyaize ? props.nyaize === 'respect' ? props.author?.isCat ? props.author?.speakAsCat : false : false : false; @@ -290,6 +294,13 @@ export default function(props: MfmProps) { }), ]); } + case 'clickable': { + return h('span', { onClick(ev: MouseEvent): void { + ev.stopPropagation(); + ev.preventDefault(); + context.emit('clickEv', token.props.args.ev ?? ''); + } }, genEl(token.children, scale)); + } } if (style === undefined) { return h('span', {}, ['$[', token.props.name, ' ', ...genEl(token.children, scale), ']']); diff --git a/packages/frontend/src/scripts/aiscript/ui.ts b/packages/frontend/src/scripts/aiscript/ui.ts index 75b924843..08ba1e6d9 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 { + if (onClickEv) call(onClickEv, values.STR(evId)); + }, }; }