2023-12-03 17:25:34 +09:00
|
|
|
/*
|
2024-02-14 00:59:27 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-12-03 17:25:34 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-12-21 11:36:45 +09:00
|
|
|
import { defineAsyncComponent, Ref, ref } from 'vue';
|
2023-12-03 17:25:34 +09:00
|
|
|
import { popup } from '@/os.js';
|
2023-12-14 14:11:20 +09:00
|
|
|
import { defaultStore } from '@/store.js';
|
2023-12-03 17:25:34 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 絵文字ピッカーを表示する。
|
|
|
|
* 類似の機能として{@link ReactionPicker}が存在しているが、この機能とは動きが異なる。
|
|
|
|
* 投稿フォームなどで絵文字を選択する時など、絵文字ピックアップ後でもダイアログが消えずに残り、
|
|
|
|
* 一度表示したダイアログを連続で使用できることが望ましいシーンでの利用が想定される。
|
|
|
|
*/
|
|
|
|
class EmojiPicker {
|
|
|
|
private src: Ref<HTMLElement | null> = ref(null);
|
|
|
|
private manualShowing = ref(false);
|
|
|
|
private onChosen?: (emoji: string) => void;
|
|
|
|
private onClosed?: () => void;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
// nop
|
|
|
|
}
|
|
|
|
|
|
|
|
public async init() {
|
2023-12-14 14:11:20 +09:00
|
|
|
const emojisRef = defaultStore.reactiveState.pinnedEmojis;
|
2023-12-03 17:25:34 +09:00
|
|
|
await popup(defineAsyncComponent(() => import('@/components/MkEmojiPickerDialog.vue')), {
|
|
|
|
src: this.src,
|
2023-12-14 14:11:20 +09:00
|
|
|
pinnedEmojis: emojisRef,
|
2023-12-03 17:25:34 +09:00
|
|
|
asReactionPicker: false,
|
|
|
|
manualShowing: this.manualShowing,
|
|
|
|
choseAndClose: false,
|
|
|
|
}, {
|
|
|
|
done: emoji => {
|
|
|
|
if (this.onChosen) this.onChosen(emoji);
|
|
|
|
},
|
|
|
|
close: () => {
|
|
|
|
this.manualShowing.value = false;
|
|
|
|
},
|
|
|
|
closed: () => {
|
|
|
|
this.src.value = null;
|
|
|
|
if (this.onClosed) this.onClosed();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public show(
|
|
|
|
src: HTMLElement,
|
2023-12-14 14:11:20 +09:00
|
|
|
onChosen?: EmojiPicker['onChosen'],
|
|
|
|
onClosed?: EmojiPicker['onClosed'],
|
2023-12-03 17:25:34 +09:00
|
|
|
) {
|
|
|
|
this.src.value = src;
|
|
|
|
this.manualShowing.value = true;
|
|
|
|
this.onChosen = onChosen;
|
|
|
|
this.onClosed = onClosed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const emojiPicker = new EmojiPicker();
|