mirror of
https://github.com/docmost/docmost.git
synced 2026-05-19 07:54:05 +08:00
e62bc6c250
* feat: emoji picker * fix: lazy load emoji data * loading animation (for slow connection) * parsing :shortcode: and replace with emoji + add extension to title-editor * fix * Remove title editor support * Remove shortcuts support * Cleanup --------- Co-authored-by: Philipinho <16838612+Philipinho@users.noreply.github.com>
39 lines
986 B
TypeScript
39 lines
986 B
TypeScript
import { CommandProps, EmojiMenuItemType } from "./types";
|
|
import { SearchIndex } from "emoji-mart";
|
|
import { getFrequentlyUsedEmoji, sortFrequentlyUsedEmoji } from "./utils";
|
|
|
|
const searchEmoji = async (value: string): Promise<EmojiMenuItemType[]> => {
|
|
if (value === "") {
|
|
const frequentlyUsedEmoji = getFrequentlyUsedEmoji();
|
|
return sortFrequentlyUsedEmoji(frequentlyUsedEmoji);
|
|
}
|
|
|
|
const emojis = await SearchIndex.search(value);
|
|
const results = emojis.map((emoji: any) => {
|
|
return {
|
|
id: emoji.id,
|
|
emoji: emoji.skins[0].native,
|
|
command: ({ editor, range }: CommandProps) => {
|
|
editor
|
|
.chain()
|
|
.focus()
|
|
.deleteRange(range)
|
|
.insertContent(emoji.skins[0].native + " ")
|
|
.run();
|
|
},
|
|
};
|
|
});
|
|
|
|
return results;
|
|
};
|
|
|
|
export const getEmojiItems = async ({
|
|
query,
|
|
}: {
|
|
query: string;
|
|
}): Promise<EmojiMenuItemType[]> => {
|
|
return searchEmoji(query);
|
|
};
|
|
|
|
export default getEmojiItems;
|