入力フォームでもリアクション選択時に使用するピッカーを使うようにしたい

This commit is contained in:
osamu 2023-11-15 12:30:00 +09:00
parent cec02966ad
commit 370099dfea
3 changed files with 32 additions and 10 deletions

View File

@ -31,20 +31,21 @@ SPDX-License-Identifier: AGPL-3.0-only
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { shallowRef } from 'vue';
import MkModal from '@/components/MkModal.vue'; import MkModal from '@/components/MkModal.vue';
import MkEmojiPicker from '@/components/MkEmojiPicker.vue'; import MkEmojiPicker from '@/components/MkEmojiPicker.vue';
import { defaultStore } from '@/store.js'; import { defaultStore } from '@/store.js';
withDefaults(defineProps<{ const props = withDefaults(defineProps<{
manualShowing?: boolean | null; manualShowing?: boolean | null;
src?: HTMLElement; src?: HTMLElement;
showPinned?: boolean; showPinned?: boolean;
asReactionPicker?: boolean; asReactionPicker?: boolean;
choseAndClose?: boolean;
}>(), { }>(), {
manualShowing: null, manualShowing: null,
showPinned: true, showPinned: true,
asReactionPicker: false, asReactionPicker: false,
choseAndClose: true,
}); });
const emit = defineEmits<{ const emit = defineEmits<{
@ -53,21 +54,24 @@ const emit = defineEmits<{
(ev: 'closed'): void; (ev: 'closed'): void;
}>(); }>();
const modal = shallowRef<InstanceType<typeof MkModal>>(); const modal = $shallowRef<InstanceType<typeof MkModal>>();
const picker = shallowRef<InstanceType<typeof MkEmojiPicker>>(); const picker = $shallowRef<InstanceType<typeof MkEmojiPicker>>();
function chosen(emoji: any) { function chosen(emoji: any) {
console.log(`chosen : ${props.choseAndClose}`);
emit('done', emoji); emit('done', emoji);
modal.value?.close(); if (props.choseAndClose) {
modal?.close();
}
} }
function opening() { function opening() {
picker.value?.reset(); picker?.reset();
picker.value?.focus(); picker?.focus();
// //
setTimeout(() => { setTimeout(() => {
picker.value?.focus(); picker?.focus();
}, 10); }, 10);
} }
</script> </script>

View File

@ -124,6 +124,7 @@ import { deepClone } from '@/scripts/clone.js';
import MkRippleEffect from '@/components/MkRippleEffect.vue'; import MkRippleEffect from '@/components/MkRippleEffect.vue';
import { miLocalStorage } from '@/local-storage.js'; import { miLocalStorage } from '@/local-storage.js';
import { claimAchievement } from '@/scripts/achievements.js'; import { claimAchievement } from '@/scripts/achievements.js';
import { reactionPicker } from '@/scripts/reaction-picker.js';
const modal = inject('modal'); const modal = inject('modal');
@ -845,7 +846,16 @@ function insertMention() {
} }
async function insertEmoji(ev: MouseEvent) { async function insertEmoji(ev: MouseEvent) {
os.openEmojiPicker(ev.currentTarget ?? ev.target, {}, textareaEl); reactionPicker.show(
ev.currentTarget ?? ev.target,
reaction => {
insertTextAtCursor(textareaEl, reaction);
},
() => {
focus();
},
false,
);
} }
function showActions(ev) { function showActions(ev) {

View File

@ -9,6 +9,7 @@ import { popup } from '@/os.js';
class ReactionPicker { class ReactionPicker {
private src: Ref<HTMLElement | null> = ref(null); private src: Ref<HTMLElement | null> = ref(null);
private manualShowing = ref(false); private manualShowing = ref(false);
private choseAndClose = ref(true);
private onChosen?: (reaction: string) => void; private onChosen?: (reaction: string) => void;
private onClosed?: () => void; private onClosed?: () => void;
@ -21,6 +22,7 @@ class ReactionPicker {
src: this.src, src: this.src,
asReactionPicker: true, asReactionPicker: true,
manualShowing: this.manualShowing, manualShowing: this.manualShowing,
choseAndClose: this.choseAndClose,
}, { }, {
done: reaction => { done: reaction => {
this.onChosen!(reaction); this.onChosen!(reaction);
@ -35,9 +37,15 @@ class ReactionPicker {
}); });
} }
public show(src: HTMLElement, onChosen: ReactionPicker['onChosen'], onClosed: ReactionPicker['onClosed']) { public show(
src: HTMLElement,
onChosen: ReactionPicker['onChosen'],
onClosed: ReactionPicker['onClosed'],
choseAndClose = true,
) {
this.src.value = src; this.src.value = src;
this.manualShowing.value = true; this.manualShowing.value = true;
this.choseAndClose.value = choseAndClose;
this.onChosen = onChosen; this.onChosen = onChosen;
this.onClosed = onClosed; this.onClosed = onClosed;
} }