mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-30 00:29:46 +08:00
feat(core): use emoji as folder icon (#7842)

This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { expect, test } from 'vitest';
|
||||
|
||||
import { extractEmojiIcon } from '../extract-emoji-icon';
|
||||
|
||||
test('extract-emoji-icon', () => {
|
||||
expect(extractEmojiIcon('👨🏻❤️💋👨🏻123')).toEqual({
|
||||
emoji: '👨🏻❤️💋👨🏻',
|
||||
rest: '123',
|
||||
});
|
||||
|
||||
expect(extractEmojiIcon('❤️123')).toEqual({
|
||||
emoji: null,
|
||||
rest: '❤️123',
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import Graphemer from 'graphemer';
|
||||
|
||||
export function extractEmojiIcon(text: string) {
|
||||
const isStartsWithEmoji = /^(\p{Emoji_Presentation})/u.test(text);
|
||||
if (isStartsWithEmoji) {
|
||||
// emoji like "👨🏻❤️💋👨🏻" are combined. Graphemer can handle these.
|
||||
const emojiEnd = Graphemer.nextBreak(text, 0);
|
||||
return {
|
||||
emoji: text.substring(0, emojiEnd),
|
||||
rest: text.substring(emojiEnd),
|
||||
};
|
||||
}
|
||||
return {
|
||||
emoji: null,
|
||||
rest: text,
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './create-emotion-cache';
|
||||
export * from './event';
|
||||
export * from './extract-emoji-icon';
|
||||
export * from './fractional-indexing';
|
||||
export * from './popup';
|
||||
export * from './string2color';
|
||||
|
||||
Reference in New Issue
Block a user