2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2021-09-17 15:39:15 +02:00
|
|
|
<template>
|
2023-05-19 09:20:53 +02:00
|
|
|
<div class="_gaps">
|
2023-01-15 21:35:01 +01:00
|
|
|
<MkButton v-if="$i && ($i.isModerator || $i.policies.canManageCustomEmojis)" primary link to="/custom-emojis-manager">{{ i18n.ts.manageCustomEmojis }}</MkButton>
|
|
|
|
|
2021-09-17 15:39:15 +02:00
|
|
|
<div class="query">
|
2023-10-25 14:20:36 +02:00
|
|
|
<MkInput v-model="q" class="" :placeholder="i18n.ts.search" autocapitalize="off">
|
2024-06-21 19:03:27 +02:00
|
|
|
<template #prefix><i class="ti ti-search"></i></template>
|
2021-09-17 15:39:15 +02:00
|
|
|
</MkInput>
|
|
|
|
|
2021-09-25 20:17:16 +02:00
|
|
|
<!-- たくさんあると邪魔
|
2021-09-17 15:39:15 +02:00
|
|
|
<div class="tags">
|
2023-01-09 07:50:25 +01:00
|
|
|
<span class="tag _button" v-for="tag in customEmojiTags" :class="{ active: selectedTags.has(tag) }" @click="toggleTag(tag)">{{ tag }}</span>
|
2021-09-17 15:39:15 +02:00
|
|
|
</div>
|
2021-09-25 20:16:30 +02:00
|
|
|
-->
|
2021-09-17 15:39:15 +02:00
|
|
|
</div>
|
|
|
|
|
2023-05-19 09:20:53 +02:00
|
|
|
<MkFoldableSection v-if="searchEmojis">
|
2023-04-01 07:01:57 +02:00
|
|
|
<template #header>{{ i18n.ts.searchResult }}</template>
|
2023-05-19 09:20:53 +02:00
|
|
|
<div :class="$style.emojis">
|
|
|
|
<XEmoji v-for="emoji in searchEmojis" :key="emoji.name" :emoji="emoji"/>
|
2021-09-17 15:39:15 +02:00
|
|
|
</div>
|
2023-01-09 01:41:25 +01:00
|
|
|
</MkFoldableSection>
|
2023-07-08 00:08:16 +02:00
|
|
|
|
2023-05-19 09:20:53 +02:00
|
|
|
<MkFoldableSection v-for="category in customEmojiCategories" v-once :key="category">
|
2023-04-01 07:01:57 +02:00
|
|
|
<template #header>{{ category || i18n.ts.other }}</template>
|
2023-05-19 09:20:53 +02:00
|
|
|
<div :class="$style.emojis">
|
|
|
|
<XEmoji v-for="emoji in customEmojis.filter(e => e.category === category)" :key="emoji.name" :emoji="emoji"/>
|
2021-09-17 15:39:15 +02:00
|
|
|
</div>
|
2023-01-09 01:41:25 +01:00
|
|
|
</MkFoldableSection>
|
2021-09-17 15:39:15 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2023-01-09 07:50:25 +01:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { watch, ref } from 'vue';
|
2023-04-01 06:52:07 +02:00
|
|
|
import * as Misskey from 'misskey-js';
|
2022-09-06 11:21:49 +02:00
|
|
|
import XEmoji from './emojis.emoji.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-01-07 07:09:46 +01:00
|
|
|
import MkInput from '@/components/MkInput.vue';
|
2023-01-09 01:41:25 +01:00
|
|
|
import MkFoldableSection from '@/components/MkFoldableSection.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { customEmojis, customEmojiCategories, getCustomEmojiTags } from '@/custom-emojis.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { $i } from '@/account.js';
|
2021-09-17 15:39:15 +02:00
|
|
|
|
2023-01-09 08:45:05 +01:00
|
|
|
const customEmojiTags = getCustomEmojiTags();
|
2023-12-07 06:42:09 +01:00
|
|
|
const q = ref('');
|
|
|
|
const searchEmojis = ref<Misskey.entities.EmojiSimple[]>(null);
|
|
|
|
const selectedTags = ref(new Set());
|
2021-09-17 15:39:15 +02:00
|
|
|
|
2023-01-09 07:50:25 +01:00
|
|
|
function search() {
|
2023-12-07 06:42:09 +01:00
|
|
|
if ((q.value === '' || q.value == null) && selectedTags.value.size === 0) {
|
|
|
|
searchEmojis.value = null;
|
2023-01-09 07:50:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-09-17 15:39:15 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
if (selectedTags.value.size === 0) {
|
|
|
|
const queryarry = q.value.match(/\:([a-z0-9_]*)\:/g);
|
2023-04-14 07:49:41 +02:00
|
|
|
|
|
|
|
if (queryarry) {
|
2023-12-07 06:42:09 +01:00
|
|
|
searchEmojis.value = customEmojis.value.filter(emoji =>
|
2023-05-19 09:20:53 +02:00
|
|
|
queryarry.includes(`:${emoji.name}:`),
|
2023-04-14 07:49:41 +02:00
|
|
|
);
|
|
|
|
} else {
|
2023-12-07 06:42:09 +01:00
|
|
|
searchEmojis.value = customEmojis.value.filter(emoji => emoji.name.includes(q.value) || emoji.aliases.includes(q.value));
|
2023-04-14 07:49:41 +02:00
|
|
|
}
|
2023-01-09 07:50:25 +01:00
|
|
|
} else {
|
2023-12-07 06:42:09 +01:00
|
|
|
searchEmojis.value = customEmojis.value.filter(emoji => (emoji.name.includes(q.value) || emoji.aliases.includes(q.value)) && [...selectedTags.value].every(t => emoji.aliases.includes(t)));
|
2023-01-09 07:50:25 +01:00
|
|
|
}
|
|
|
|
}
|
2021-09-17 15:39:15 +02:00
|
|
|
|
2023-01-09 07:50:25 +01:00
|
|
|
function toggleTag(tag) {
|
2023-12-07 06:42:09 +01:00
|
|
|
if (selectedTags.value.has(tag)) {
|
|
|
|
selectedTags.value.delete(tag);
|
2023-01-09 07:50:25 +01:00
|
|
|
} else {
|
2023-12-07 06:42:09 +01:00
|
|
|
selectedTags.value.add(tag);
|
2023-01-09 07:50:25 +01:00
|
|
|
}
|
|
|
|
}
|
2021-09-17 15:39:15 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
watch(q, () => {
|
2023-01-09 07:50:25 +01:00
|
|
|
search();
|
2021-09-17 15:39:15 +02:00
|
|
|
});
|
2023-01-09 07:50:25 +01:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
watch(selectedTags, () => {
|
2023-01-09 07:50:25 +01:00
|
|
|
search();
|
|
|
|
}, { deep: true });
|
2021-09-17 15:39:15 +02:00
|
|
|
</script>
|
|
|
|
|
2023-05-19 09:20:53 +02:00
|
|
|
<style lang="scss" module>
|
|
|
|
.emojis {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
|
|
|
|
grid-gap: 12px;
|
2021-09-17 15:39:15 +02:00
|
|
|
}
|
|
|
|
</style>
|