emoji-picker-element
emoji-picker-element copied to clipboard
Add `getAllNativeEmojis` to database
We have a use case where we'd like to synchronously determine if a string is a single emoji.
By adding getAllNativeEmojis
, we can load all of the emoji unicode strings into a Set, solving our problem.
Thanks for the PR! I think though, that this is not quite the implementation I would propose to solve this problem.
One of my main design decisions with emoji-picker-element
was to use IndexedDB, to avoid having all emoji in memory. With getAllNativeEmojis
, we are encouraging people to read the entire database into memory, which obviates a major benefit of IndexedDB.
Lookig at your code, it seems that originally you implemented isSingleEmoji()
using (await emojiDatabase.getEmojiByUnicodeOrName(text)) !== null
. This seems to me to be the appropriate, IDB-friendly approach. You're not reading the whole DB into memory, but instead leveraging the database's built-in index.
Why did you find that you needed synchronous access instead?
We are building a chat app and we want to increase the size of messages which contain only a single emoji.
So each time we render a message we check if its text matches with an emoji from the emoji picker db.
The first implementation of this was async where we would render the message, then check if it was a single emoji, and resize it if so. But obviously that caused issues where users would end up in slightly the wrong scroll position after the resizing.
We could get around this though by performing the isSingleEmoji
check higher up within the code where the messages are fetched which is already async. I'll give that a try a bit later and see how it looks / performs.
We have a use case for this too. I'm implementing an input rule for adding emojis with colon wrapped shortcodes and I have to determine whether the typed shortcode matches any emojis; but handling this in ProseMirror requires synchronous processing which is not possible with the current API.
With getAllNativeEmojis
, I can get the emoji list before rendering the editor and that should solve my issue.
@dumptyd I still feel this is the wrong way to go about it. Or at the very least, the IndexedDB query should only query the keys (unicode/shortcode) rather than the values (full-fat emoji data).
I can maybe picture an API like getAllShortcodes()
. Then you can build a Trie data structure out of it or something (outside of the scope of this project). Note that for unicode, you can use emoji-regex, so I don't see much need to expose that.
Or open a PR on ProseMirror to support async processing. :)