mirror of
https://github.com/glitch-soc/mastodon
synced 2025-04-25 00:44:51 +00:00
[Glitch] Add emoji from Twemoji 15.0 to the emoji picker/completion
Port debe6c0545
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
4bea9a0a66
commit
e2e129457f
6 changed files with 117 additions and 40 deletions
|
@ -87,6 +87,7 @@ AUTHORS.md
|
||||||
|
|
||||||
# Ignore glitch-soc emoji map file
|
# Ignore glitch-soc emoji map file
|
||||||
/app/javascript/flavours/glitch/features/emoji/emoji_map.json
|
/app/javascript/flavours/glitch/features/emoji/emoji_map.json
|
||||||
|
/app/javascript/flavours/glitch/features/emoji/emoji_sheet.json
|
||||||
|
|
||||||
# Ignore glitch-soc locale files
|
# Ignore glitch-soc locale files
|
||||||
/app/javascript/flavours/glitch/locales
|
/app/javascript/flavours/glitch/locales
|
||||||
|
|
|
@ -12,12 +12,15 @@ import Overlay from 'react-overlays/Overlay';
|
||||||
|
|
||||||
import MoodIcon from '@/material-icons/400-20px/mood.svg?react';
|
import MoodIcon from '@/material-icons/400-20px/mood.svg?react';
|
||||||
import { IconButton } from 'flavours/glitch/components/icon_button';
|
import { IconButton } from 'flavours/glitch/components/icon_button';
|
||||||
|
import emojiCompressed from 'flavours/glitch/features/emoji/emoji_compressed';
|
||||||
import { useSystemEmojiFont } from 'flavours/glitch/initial_state';
|
import { useSystemEmojiFont } from 'flavours/glitch/initial_state';
|
||||||
import { assetHost } from 'flavours/glitch/utils/config';
|
import { assetHost } from 'flavours/glitch/utils/config';
|
||||||
|
|
||||||
import { buildCustomEmojis, categoriesFromEmojis } from '../../emoji/emoji';
|
import { buildCustomEmojis, categoriesFromEmojis } from '../../emoji/emoji';
|
||||||
import { EmojiPicker as EmojiPickerAsync } from '../../ui/util/async-components';
|
import { EmojiPicker as EmojiPickerAsync } from '../../ui/util/async-components';
|
||||||
|
|
||||||
|
const nimblePickerData = emojiCompressed[5];
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
emoji: { id: 'emoji_button.label', defaultMessage: 'Insert emoji' },
|
emoji: { id: 'emoji_button.label', defaultMessage: 'Insert emoji' },
|
||||||
emoji_search: { id: 'emoji_button.search', defaultMessage: 'Search...' },
|
emoji_search: { id: 'emoji_button.search', defaultMessage: 'Search...' },
|
||||||
|
@ -38,15 +41,18 @@ let EmojiPicker, Emoji; // load asynchronously
|
||||||
|
|
||||||
const listenerOptions = supportsPassiveEvents ? { passive: true, capture: true } : true;
|
const listenerOptions = supportsPassiveEvents ? { passive: true, capture: true } : true;
|
||||||
|
|
||||||
const backgroundImageFn = () => `${assetHost}/emoji/sheet_13.png`;
|
const backgroundImageFn = () => `${assetHost}/emoji/sheet_15.png`;
|
||||||
|
|
||||||
const notFoundFn = () => (
|
const notFoundFn = () => (
|
||||||
<div className='emoji-mart-no-results'>
|
<div className='emoji-mart-no-results'>
|
||||||
<Emoji
|
<Emoji
|
||||||
|
data={nimblePickerData}
|
||||||
emoji='sleuth_or_spy'
|
emoji='sleuth_or_spy'
|
||||||
set='twitter'
|
set='twitter'
|
||||||
size={32}
|
size={32}
|
||||||
sheetSize={32}
|
sheetSize={32}
|
||||||
|
sheetColumns={62}
|
||||||
|
sheetRows={62}
|
||||||
backgroundImageFn={backgroundImageFn}
|
backgroundImageFn={backgroundImageFn}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -105,12 +111,12 @@ class ModifierPickerMenu extends PureComponent {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='emoji-picker-dropdown__modifiers__menu' style={{ display: active ? 'block' : 'none' }} ref={this.setRef}>
|
<div className='emoji-picker-dropdown__modifiers__menu' style={{ display: active ? 'block' : 'none' }} ref={this.setRef}>
|
||||||
<button type='button' onClick={this.handleClick} data-index={1}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={1} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
<button type='button' onClick={this.handleClick} data-index={1}><Emoji data={nimblePickerData} sheetColumns={62} sheetRows={62} emoji='fist' set='twitter' size={22} sheetSize={32} skin={1} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
||||||
<button type='button' onClick={this.handleClick} data-index={2}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={2} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
<button type='button' onClick={this.handleClick} data-index={2}><Emoji data={nimblePickerData} sheetColumns={62} sheetRows={62} emoji='fist' set='twitter' size={22} sheetSize={32} skin={2} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
||||||
<button type='button' onClick={this.handleClick} data-index={3}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={3} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
<button type='button' onClick={this.handleClick} data-index={3}><Emoji data={nimblePickerData} sheetColumns={62} sheetRows={62} emoji='fist' set='twitter' size={22} sheetSize={32} skin={3} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
||||||
<button type='button' onClick={this.handleClick} data-index={4}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={4} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
<button type='button' onClick={this.handleClick} data-index={4}><Emoji data={nimblePickerData} sheetColumns={62} sheetRows={62} emoji='fist' set='twitter' size={22} sheetSize={32} skin={4} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
||||||
<button type='button' onClick={this.handleClick} data-index={5}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={5} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
<button type='button' onClick={this.handleClick} data-index={5}><Emoji data={nimblePickerData} sheetColumns={62} sheetRows={62} emoji='fist' set='twitter' size={22} sheetSize={32} skin={5} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
||||||
<button type='button' onClick={this.handleClick} data-index={6}><Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={6} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
<button type='button' onClick={this.handleClick} data-index={6}><Emoji data={nimblePickerData} sheetColumns={62} sheetRows={62} emoji='fist' set='twitter' size={22} sheetSize={32} skin={6} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} /></button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -145,7 +151,7 @@ class ModifierPicker extends PureComponent {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='emoji-picker-dropdown__modifiers'>
|
<div className='emoji-picker-dropdown__modifiers'>
|
||||||
<Emoji emoji='fist' set='twitter' size={22} sheetSize={32} skin={modifier} onClick={this.handleClick} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} />
|
<Emoji data={nimblePickerData} sheetColumns={62} sheetRows={62} emoji='fist' set='twitter' size={22} sheetSize={32} skin={modifier} onClick={this.handleClick} backgroundImageFn={backgroundImageFn} native={useSystemEmojiFont} />
|
||||||
<ModifierPickerMenu active={active} onSelect={this.handleSelect} onClose={this.props.onClose} />
|
<ModifierPickerMenu active={active} onSelect={this.handleSelect} onClose={this.props.onClose} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -281,6 +287,9 @@ class EmojiPickerMenuImpl extends PureComponent {
|
||||||
return (
|
return (
|
||||||
<div className={classNames('emoji-picker-dropdown__menu', { selecting: modifierOpen })} style={style} ref={this.setRef}>
|
<div className={classNames('emoji-picker-dropdown__menu', { selecting: modifierOpen })} style={style} ref={this.setRef}>
|
||||||
<EmojiPicker
|
<EmojiPicker
|
||||||
|
data={nimblePickerData}
|
||||||
|
sheetColumns={62}
|
||||||
|
sheetRows={62}
|
||||||
perLine={8}
|
perLine={8}
|
||||||
emojiSize={22}
|
emojiSize={22}
|
||||||
sheetSize={32}
|
sheetSize={32}
|
||||||
|
|
|
@ -45,6 +45,7 @@ type EmojiCompressed = [
|
||||||
Category[],
|
Category[],
|
||||||
Data['aliases'],
|
Data['aliases'],
|
||||||
EmojisWithoutShortCodes,
|
EmojisWithoutShortCodes,
|
||||||
|
Data,
|
||||||
];
|
];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -9,18 +9,91 @@
|
||||||
|
|
||||||
// This version comment should be bumped each time the emoji data is changed
|
// This version comment should be bumped each time the emoji data is changed
|
||||||
// to ensure that the prevaled file is regenerated by Babel
|
// to ensure that the prevaled file is regenerated by Babel
|
||||||
// version: 2
|
// version: 3
|
||||||
|
|
||||||
const { emojiIndex } = require('emoji-mart');
|
// This json file contains the names of the categories.
|
||||||
let data = require('emoji-mart/data/all.json');
|
const emojiMart5LocalesData = require('@emoji-mart/data/i18n/en.json');
|
||||||
|
const emojiMart5Data = require('@emoji-mart/data/sets/15/all.json');
|
||||||
const { uncompress: emojiMartUncompress } = require('emoji-mart/dist/utils/data');
|
const { uncompress: emojiMartUncompress } = require('emoji-mart/dist/utils/data');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
|
|
||||||
const emojiMap = require('./emoji_map.json');
|
const emojiMap = require('./emoji_map.json');
|
||||||
|
// This json file is downloaded from https://github.com/iamcal/emoji-data/
|
||||||
|
// and is used to correct the sheet coordinates since we're using that repo's sheet
|
||||||
|
const emojiSheetData = require('./emoji_sheet.json');
|
||||||
const { unicodeToFilename } = require('./unicode_to_filename');
|
const { unicodeToFilename } = require('./unicode_to_filename');
|
||||||
const { unicodeToUnifiedName } = require('./unicode_to_unified_name');
|
const { unicodeToUnifiedName } = require('./unicode_to_unified_name');
|
||||||
|
|
||||||
|
// Grabbed from `emoji_utils` to avoid circular dependency
|
||||||
|
function unifiedToNative(unified) {
|
||||||
|
let unicodes = unified.split('-'),
|
||||||
|
codePoints = unicodes.map((u) => `0x${u}`);
|
||||||
|
|
||||||
|
return String.fromCodePoint(...codePoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = {
|
||||||
|
compressed: true,
|
||||||
|
categories: emojiMart5Data.categories.map(cat => {
|
||||||
|
return {
|
||||||
|
...cat,
|
||||||
|
name: emojiMart5LocalesData.categories[cat.id]
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
aliases: emojiMart5Data.aliases,
|
||||||
|
emojis: _(emojiMart5Data.emojis).values().map(emoji => {
|
||||||
|
let skin_variations = {};
|
||||||
|
const unified = emoji.skins[0].unified.toUpperCase();
|
||||||
|
const emojiFromRawData = emojiSheetData.find(e => e.unified === unified);
|
||||||
|
|
||||||
|
if (!emojiFromRawData) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emoji.skins.length > 1) {
|
||||||
|
const [, ...nonDefaultSkins] = emoji.skins;
|
||||||
|
nonDefaultSkins.forEach(skin => {
|
||||||
|
const [matchingRawCodePoints,matchingRawEmoji] = Object.entries(emojiFromRawData.skin_variations).find((pair) => {
|
||||||
|
const [, value] = pair;
|
||||||
|
return value.unified.toLowerCase() === skin.unified;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (matchingRawEmoji && matchingRawCodePoints) {
|
||||||
|
// At the time of writing, the json from `@emoji-mart/data` doesn't have data
|
||||||
|
// for emoji like `woman-heart-woman` with two different skin tones.
|
||||||
|
const skinToneCode = matchingRawCodePoints.split('-')[0];
|
||||||
|
skin_variations[skinToneCode] = {
|
||||||
|
unified: matchingRawEmoji.unified.toUpperCase(),
|
||||||
|
non_qualified: null,
|
||||||
|
sheet_x: matchingRawEmoji.sheet_x,
|
||||||
|
sheet_y: matchingRawEmoji.sheet_y,
|
||||||
|
has_img_twitter: true,
|
||||||
|
native: unifiedToNative(matchingRawEmoji.unified.toUpperCase())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
a: emoji.name,
|
||||||
|
b: unified,
|
||||||
|
c: undefined,
|
||||||
|
f: true,
|
||||||
|
j: [emoji.id, ...emoji.keywords],
|
||||||
|
k: [emojiFromRawData.sheet_x, emojiFromRawData.sheet_y],
|
||||||
|
m: emoji.emoticons?.[0],
|
||||||
|
l: emoji.emoticons,
|
||||||
|
o: emoji.version,
|
||||||
|
id: emoji.id,
|
||||||
|
skin_variations,
|
||||||
|
native: unifiedToNative(unified.toUpperCase())
|
||||||
|
};
|
||||||
|
}).compact().keyBy(e => e.id).mapValues(e => _.omit(e, 'id')).value()
|
||||||
|
};
|
||||||
|
|
||||||
if (data.compressed) {
|
if (data.compressed) {
|
||||||
data = emojiMartUncompress(data);
|
emojiMartUncompress(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const emojiMartData = data;
|
const emojiMartData = data;
|
||||||
|
@ -32,15 +105,10 @@ const shortcodeMap = {};
|
||||||
const shortCodesToEmojiData = {};
|
const shortCodesToEmojiData = {};
|
||||||
const emojisWithoutShortCodes = [];
|
const emojisWithoutShortCodes = [];
|
||||||
|
|
||||||
Object.keys(emojiIndex.emojis).forEach(key => {
|
Object.keys(emojiMart5Data.emojis).forEach(key => {
|
||||||
let emoji = emojiIndex.emojis[key];
|
let emoji = emojiMart5Data.emojis[key];
|
||||||
|
|
||||||
// Emojis with skin tone modifiers are stored like this
|
shortcodeMap[emoji.skins[0].native] = emoji.id;
|
||||||
if (Object.hasOwn(emoji, '1')) {
|
|
||||||
emoji = emoji['1'];
|
|
||||||
}
|
|
||||||
|
|
||||||
shortcodeMap[emoji.native] = emoji.id;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const stripModifiers = unicode => {
|
const stripModifiers = unicode => {
|
||||||
|
@ -84,13 +152,9 @@ Object.keys(emojiMap).forEach(key => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.keys(emojiIndex.emojis).forEach(key => {
|
Object.keys(emojiMartData.emojis).forEach(key => {
|
||||||
let emoji = emojiIndex.emojis[key];
|
let emoji = emojiMartData.emojis[key];
|
||||||
|
|
||||||
// Emojis with skin tone modifiers are stored like this
|
|
||||||
if (Object.hasOwn(emoji, '1')) {
|
|
||||||
emoji = emoji['1'];
|
|
||||||
}
|
|
||||||
|
|
||||||
const { native } = emoji;
|
const { native } = emoji;
|
||||||
let { short_names, search, unified } = emojiMartData.emojis[key];
|
let { short_names, search, unified } = emojiMartData.emojis[key];
|
||||||
|
@ -135,4 +199,5 @@ module.exports = JSON.parse(JSON.stringify([
|
||||||
emojiMartData.categories,
|
emojiMartData.categories,
|
||||||
emojiMartData.aliases,
|
emojiMartData.aliases,
|
||||||
emojisWithoutShortCodes,
|
emojisWithoutShortCodes,
|
||||||
|
emojiMartData
|
||||||
]));
|
]));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Emoji from 'emoji-mart/dist-es/components/emoji/emoji';
|
import Emoji from 'emoji-mart/dist-es/components/emoji/nimble-emoji';
|
||||||
import Picker from 'emoji-mart/dist-es/components/picker/picker';
|
import Picker from 'emoji-mart/dist-es/components/picker/nimble-picker';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Picker,
|
Picker,
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue