2023-12-03 00:25:34 -08:00
|
|
|
/*
|
2024-02-11 18:37:45 -08:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-12-03 00:25:34 -08:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-12-20 18:36:45 -08:00
|
|
|
import { defineAsyncComponent, Ref, ref } from 'vue';
|
2023-12-03 00:25:34 -08:00
|
|
|
import { popup } from '@/os.js';
|
2023-12-13 21:11:20 -08:00
|
|
|
import { defaultStore } from '@/store.js';
|
2023-12-03 00:25:34 -08: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-13 21:11:20 -08:00
|
|
|
const emojisRef = defaultStore.reactiveState.pinnedEmojis;
|
2023-12-03 00:25:34 -08:00
|
|
|
await popup(defineAsyncComponent(() => import('@/components/MkEmojiPickerDialog.vue')), {
|
|
|
|
src: this.src,
|
2023-12-13 21:11:20 -08:00
|
|
|
pinnedEmojis: emojisRef,
|
2023-12-03 00:25:34 -08: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-13 21:11:20 -08:00
|
|
|
onChosen?: EmojiPicker['onChosen'],
|
|
|
|
onClosed?: EmojiPicker['onClosed'],
|
2023-12-03 00:25:34 -08:00
|
|
|
) {
|
|
|
|
this.src.value = src;
|
|
|
|
this.manualShowing.value = true;
|
|
|
|
this.onChosen = onChosen;
|
|
|
|
this.onClosed = onClosed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const emojiPicker = new EmojiPicker();
|