This commit is contained in:
tamaina
2023-01-16 09:39:58 +00:00
parent 9d64ac6d6f
commit 21e4c3dfe9
8 changed files with 74 additions and 61 deletions

View File

@ -33,7 +33,7 @@
</template>
<script lang="ts">
import { markRaw, ref, shallowRef, onUpdated, onMounted, onBeforeUnmount, nextTick, watch } from 'vue';
import { markRaw, ref, shallowRef, computed, onUpdated, onMounted, onBeforeUnmount, nextTick, watch } from 'vue';
import sanitizeHtml from 'sanitize-html';
import contains from '@/scripts/contains';
import { char2twemojiFilePath, char2fluentEmojiFilePath } from '@/scripts/emoji-base';
@ -61,59 +61,59 @@ type EmojiDef = {
const lib = emojilist.filter(x => x.category !== 'flags');
const char2path = defaultStore.state.emojiStyle === 'twemoji' ? char2twemojiFilePath : char2fluentEmojiFilePath;
const emojiDb = computed(() => {
const char2path = defaultStore.reactiveState.emojiStyle.value === 'twemoji' ? char2twemojiFilePath : char2fluentEmojiFilePath;
const emjdb: EmojiDef[] = lib.map(x => ({
emoji: x.char,
name: x.name,
url: char2path(x.char),
}));
for (const x of lib) {
if (x.keywords) {
for (const k of x.keywords) {
emjdb.push({
emoji: x.char,
name: k,
aliasOf: x.name,
url: char2path(x.char),
});
}
}
}
emjdb.sort((a, b) => a.name.length - b.name.length);
//#region Construct Emoji DB
const emojiDefinitions: EmojiDef[] = [];
for (const x of customEmojis) {
emojiDefinitions.push({
const unicodeEmojiDB: EmojiDef[] = lib.map(x => ({
emoji: x.char,
name: x.name,
emoji: `:${x.name}:`,
isCustomEmoji: true,
});
url: char2path(x.char),
}));
if (x.aliases) {
for (const alias of x.aliases) {
emojiDefinitions.push({
name: alias,
aliasOf: x.name,
emoji: `:${x.name}:`,
isCustomEmoji: true,
});
for (const x of lib) {
if (x.keywords) {
for (const k of x.keywords) {
unicodeEmojiDB.push({
emoji: x.char,
name: k,
aliasOf: x.name,
url: char2path(x.char),
});
}
}
}
}
emojiDefinitions.sort((a, b) => a.name.length - b.name.length);
unicodeEmojiDB.sort((a, b) => a.name.length - b.name.length);
const emojiDb = markRaw(emojiDefinitions.concat(emjdb));
//#endregion
//#region Construct Emoji DB
const customEmojiDB: EmojiDef[] = [];
for (const x of customEmojis.value) {
customEmojiDB.push({
name: x.name,
emoji: `:${x.name}:`,
isCustomEmoji: true,
});
if (x.aliases) {
for (const alias of x.aliases) {
customEmojiDB.push({
name: alias,
aliasOf: x.name,
emoji: `:${x.name}:`,
isCustomEmoji: true,
});
}
}
}
customEmojiDB.sort((a, b) => a.name.length - b.name.length);
return markRaw([ ...customEmojiDB, ...unicodeEmojiDB ]);
});
export default {
emojiDb,
emojiDefinitions,
emojilist,
};
</script>
@ -230,7 +230,7 @@ function exec() {
} else if (props.type === 'emoji') {
if (!props.q || props.q === '') {
// 最近使った絵文字をサジェスト
emojis.value = defaultStore.state.recentlyUsedEmojis.map(emoji => emojiDb.find(dbEmoji => dbEmoji.emoji === emoji)).filter(x => x) as EmojiDef[];
emojis.value = defaultStore.state.recentlyUsedEmojis.map(emoji => emojiDb.value.find(dbEmoji => dbEmoji.emoji === emoji)).filter(x => x) as EmojiDef[];
return;
}

View File

@ -138,7 +138,7 @@ watch(q, () => {
const searchCustom = () => {
const max = 8;
const emojis = customEmojis;
const emojis = customEmojis.value;
const matches = new Set<Misskey.entities.CustomEmoji>();
const exactMatch = emojis.find(emoji => emoji.name === newQ);
@ -323,7 +323,7 @@ function done(query?: string): boolean | void {
if (query == null || typeof query !== 'string') return;
const q2 = query.replace(/:/g, '');
const exactMatchCustom = customEmojis.find(emoji => emoji.name === q2);
const exactMatchCustom = customEmojis.value.find(emoji => emoji.name === q2);
if (exactMatchCustom) {
chosen(exactMatchCustom);
return true;