Merge branch 'upgrade-emoji-mart' into 'develop'

Upgrade emoji mart

See merge request soapbox-pub/soapbox-fe!595
actually-fix-tabs-bar
Alex Gleason 2021-07-10 07:14:51 +00:00
commit 079e269812
13 zmienionych plików z 181 dodań i 62 usunięć

Wyświetl plik

@ -28,7 +28,7 @@ const messages = defineMessages({
const assetHost = process.env.CDN_HOST || ''; const assetHost = process.env.CDN_HOST || '';
let EmojiPicker, Emoji; // load asynchronously let EmojiPicker, Emoji; // load asynchronously
const backgroundImageFn = () => `${assetHost}/emoji/sheet_10.png`; const backgroundImageFn = () => `${assetHost}/emoji/sheet_13.png`;
const listenerOptions = supportsPassiveEvents ? { passive: true } : false; const listenerOptions = supportsPassiveEvents ? { passive: true } : false;
const categoriesSort = [ const categoriesSort = [

Wyświetl plik

@ -52,12 +52,12 @@ describe('emoji_index', () => {
it('(different behavior from emoji-mart) do not erases custom emoji if not passed again', () => { it('(different behavior from emoji-mart) do not erases custom emoji if not passed again', () => {
const custom = [ const custom = [
{ {
id: 'soapbox', id: 'mastodon',
name: 'soapbox', name: 'mastodon',
short_names: ['soapbox'], short_names: ['mastodon'],
text: '', text: '',
emoticons: [], emoticons: [],
keywords: ['soapbox'], keywords: ['mastodon'],
imageUrl: 'http://example.com', imageUrl: 'http://example.com',
custom: true, custom: true,
}, },
@ -67,23 +67,23 @@ describe('emoji_index', () => {
const expected = []; const expected = [];
const lightExpected = [ const lightExpected = [
{ {
id: 'soapbox', id: 'mastodon',
custom: true, custom: true,
}, },
]; ];
expect(search('soap').map(trimEmojis)).toEqual(lightExpected); expect(search('masto').map(trimEmojis)).toEqual(lightExpected);
expect(emojiIndex.search('soap').map(trimEmojis)).toEqual(expected); expect(emojiIndex.search('masto').map(trimEmojis)).toEqual(expected);
}); });
it('(different behavior from emoji-mart) erases custom emoji if another is passed', () => { it('(different behavior from emoji-mart) erases custom emoji if another is passed', () => {
const custom = [ const custom = [
{ {
id: 'soapbox', id: 'mastodon',
name: 'soapbox', name: 'mastodon',
short_names: ['soapbox'], short_names: ['mastodon'],
text: '', text: '',
emoticons: [], emoticons: [],
keywords: ['soapbox'], keywords: ['mastodon'],
imageUrl: 'http://example.com', imageUrl: 'http://example.com',
custom: true, custom: true,
}, },
@ -91,19 +91,19 @@ describe('emoji_index', () => {
search('', { custom }); search('', { custom });
emojiIndex.search('', { custom }); emojiIndex.search('', { custom });
const expected = []; const expected = [];
expect(search('soap', { custom: [] }).map(trimEmojis)).toEqual(expected); expect(search('masto', { custom: [] }).map(trimEmojis)).toEqual(expected);
expect(emojiIndex.search('soap').map(trimEmojis)).toEqual(expected); expect(emojiIndex.search('masto').map(trimEmojis)).toEqual(expected);
}); });
it('handles custom emoji', () => { it('handles custom emoji', () => {
const custom = [ const custom = [
{ {
id: 'soapbox', id: 'mastodon',
name: 'soapbox', name: 'mastodon',
short_names: ['soapbox'], short_names: ['mastodon'],
text: '', text: '',
emoticons: [], emoticons: [],
keywords: ['soapbox'], keywords: ['mastodon'],
imageUrl: 'http://example.com', imageUrl: 'http://example.com',
custom: true, custom: true,
}, },
@ -112,12 +112,12 @@ describe('emoji_index', () => {
emojiIndex.search('', { custom }); emojiIndex.search('', { custom });
const expected = [ const expected = [
{ {
id: 'soapbox', id: 'mastodon',
custom: true, custom: true,
}, },
]; ];
expect(search('soap', { custom }).map(trimEmojis)).toEqual(expected); expect(search('masto', { custom }).map(trimEmojis)).toEqual(expected);
expect(emojiIndex.search('soap', { custom }).map(trimEmojis)).toEqual(expected); expect(emojiIndex.search('masto', { custom }).map(trimEmojis)).toEqual(expected);
}); });
it('should filter only emojis we care about, exclude pineapple', () => { it('should filter only emojis we care about, exclude pineapple', () => {

Wyświetl plik

@ -7,29 +7,38 @@
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');
const emojiMap = require('./emoji_map.json'); const emojiMap = require('./emoji_map.json');
const { emojiIndex } = require('emoji-mart'); const { emojiIndex } = require('emoji-mart');
const { uncompress: emojiMartUncompress } = require('emoji-mart/dist/utils/data'); const { uncompress: emojiMartUncompress } = require('emoji-mart/dist/utils/data');
let data = require('emoji-mart/data/all.json'); let data = require('emoji-mart/data/all.json');
if(data.compressed) { if(data.compressed) {
data = emojiMartUncompress(data); data = emojiMartUncompress(data);
} }
const emojiMartData = data; const emojiMartData = data;
const excluded = ['®', '©', '™']; const excluded = ['®', '©', '™'];
const skins = ['🏻', '🏼', '🏽', '🏾', '🏿']; const skinTones = ['🏻', '🏼', '🏽', '🏾', '🏿'];
const shortcodeMap = {}; const shortcodeMap = {};
const shortCodesToEmojiData = {}; const shortCodesToEmojiData = {};
const emojisWithoutShortCodes = []; const emojisWithoutShortCodes = [];
Object.keys(emojiIndex.emojis).forEach(key => { Object.keys(emojiIndex.emojis).forEach(key => {
shortcodeMap[emojiIndex.emojis[key].native] = emojiIndex.emojis[key].id; let emoji = emojiIndex.emojis[key];
// Emojis with skin tone modifiers are stored like this
if (Object.prototype.hasOwnProperty.call(emoji, '1')) {
emoji = emoji['1'];
}
shortcodeMap[emoji.native] = emoji.id;
}); });
const stripModifiers = unicode => { const stripModifiers = unicode => {
skins.forEach(tone => { skinTones.forEach(tone => {
unicode = unicode.replace(tone, ''); unicode = unicode.replace(tone, '');
}); });
@ -64,13 +73,22 @@ Object.keys(emojiMap).forEach(key => {
if (!Array.isArray(shortCodesToEmojiData[shortcode])) { if (!Array.isArray(shortCodesToEmojiData[shortcode])) {
shortCodesToEmojiData[shortcode] = [[]]; shortCodesToEmojiData[shortcode] = [[]];
} }
shortCodesToEmojiData[shortcode][0].push(filenameData); shortCodesToEmojiData[shortcode][0].push(filenameData);
} }
}); });
Object.keys(emojiIndex.emojis).forEach(key => { Object.keys(emojiIndex.emojis).forEach(key => {
const { native } = emojiIndex.emojis[key]; let emoji = emojiIndex.emojis[key];
// Emojis with skin tone modifiers are stored like this
if (Object.prototype.hasOwnProperty.call(emoji, '1')) {
emoji = emoji['1'];
}
const { native } = emoji;
let { short_names, search, unified } = emojiMartData.emojis[key]; let { short_names, search, unified } = emojiMartData.emojis[key];
if (short_names[0] !== key) { if (short_names[0] !== key) {
throw new Error('The compresser expects the first short_code to be the ' + throw new Error('The compresser expects the first short_code to be the ' +
'key. It may need to be rewritten if the emoji change such that this ' + 'key. It may need to be rewritten if the emoji change such that this ' +
@ -80,11 +98,16 @@ Object.keys(emojiIndex.emojis).forEach(key => {
short_names = short_names.slice(1); // first short name can be inferred from the key short_names = short_names.slice(1); // first short name can be inferred from the key
const searchData = [native, short_names, search]; const searchData = [native, short_names, search];
if (unicodeToUnifiedName(native) !== unified) { if (unicodeToUnifiedName(native) !== unified) {
// unified name can't be derived from unicodeToUnifiedName // unified name can't be derived from unicodeToUnifiedName
searchData.push(unified); searchData.push(unified);
} }
if (!Array.isArray(shortCodesToEmojiData[key])) {
shortCodesToEmojiData[key] = [[]];
}
shortCodesToEmojiData[key].push(searchData); shortCodesToEmojiData[key].push(searchData);
}); });

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -2,16 +2,20 @@ function padLeft(str, num) {
while (str.length < num) { while (str.length < num) {
str = '0' + str; str = '0' + str;
} }
return str; return str;
} }
exports.unicodeToUnifiedName = (str) => { exports.unicodeToUnifiedName = (str) => {
let output = ''; let output = '';
for (let i = 0; i < str.length; i += 2) { for (let i = 0; i < str.length; i += 2) {
if (i > 0) { if (i > 0) {
output += '-'; output += '-';
} }
output += padLeft(str.codePointAt(i).toString(16).toUpperCase(), 4); output += padLeft(str.codePointAt(i).toString(16).toUpperCase(), 4);
} }
return output; return output;
}; };

Wyświetl plik

@ -63,6 +63,13 @@ class IconPickerMenu extends React.PureComponent {
setRef = c => { setRef = c => {
this.node = c; this.node = c;
if (!c) return;
// Nice and dirty hack to display the icons
c.querySelectorAll('button.emoji-mart-emoji > span').forEach(elem => {
elem.innerHTML = `<i class="fa fa-${elem.parentNode.getAttribute('title')}"></i>`;
});
} }
getI18n = () => { getI18n = () => {
@ -99,7 +106,6 @@ class IconPickerMenu extends React.PureComponent {
emoticons: [], emoticons: [],
keywords: [name], keywords: [name],
imageUrl: '', imageUrl: '',
render: <Icon id={name} />,
}); });
} }
}); });

Wyświetl plik

@ -1,12 +1,12 @@
.emoji-mart { .emoji-mart {
font-size: 13px; font-size: 13px;
display: inline-block; display: inline-block;
color: var(--primary-text-color);
&, &,
* { * {
box-sizing: border-box; box-sizing: border-box;
line-height: 1.15; line-height: 1.15;
color: var(--primary-text-color);
} }
.emoji-mart-emoji { .emoji-mart-emoji {
@ -21,6 +21,7 @@
border-bottom-width: 1px; border-bottom-width: 1px;
border-top-left-radius: 5px; border-top-left-radius: 5px;
border-top-right-radius: 5px; border-top-right-radius: 5px;
background: var(--foreground-color);
} }
&:last-child { &:last-child {
@ -47,6 +48,8 @@
overflow: hidden; overflow: hidden;
transition: color 0.1s ease-out; transition: color 0.1s ease-out;
cursor: pointer; cursor: pointer;
background: transparent;
border: 0;
&:hover { &:hover {
color: var(--primary-text-color--faint); color: var(--primary-text-color--faint);
@ -105,16 +108,18 @@
padding: 10px; padding: 10px;
padding-right: 45px; padding-right: 45px;
background: var(--foreground-color); background: var(--foreground-color);
position: relative;
input { input {
font-size: 14px; font-size: 14px;
font-weight: 400; font-weight: 400;
color: var(--primary-text-color);
padding: 7px 9px; padding: 7px 9px;
padding-right: 25px;
font-family: inherit; font-family: inherit;
display: block; display: block;
width: 100%; width: 100%;
background: var(--background-color); background: var(--background-color);
color: var(--primary-text-color);
border: 1px solid var(--brand-color--faint); border: 1px solid var(--brand-color--faint);
border-radius: 9999px; border-radius: 9999px;
@ -130,6 +135,30 @@
} }
} }
.emoji-mart-search-icon {
position: absolute;
top: 18px;
right: 45px + 5px;
z-index: 2;
padding: 2px 5px 1px;
border: 0;
background: none;
transition: all 100ms linear;
transition-property: opacity;
pointer-events: auto;
opacity: 0.7;
&:disabled {
cursor: default;
pointer-events: none;
opacity: 0.3;
}
svg {
fill: var(--primary-text-color);
}
}
.emoji-mart-category .emoji-mart-emoji { .emoji-mart-category .emoji-mart-emoji {
cursor: pointer; cursor: pointer;
@ -168,18 +197,38 @@
} }
} }
/* For screenreaders only, via https://stackoverflow.com/a/19758620 */
.emoji-mart-sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
.emoji-mart-category-list {
margin: 0;
padding: 0;
}
.emoji-mart-category-list li {
list-style: none;
margin: 0;
padding: 0;
display: inline-block;
}
.emoji-mart-emoji { .emoji-mart-emoji {
position: relative; position: relative;
display: inline-block; display: inline-block;
background: transparent;
border: 0;
padding: 0;
font-size: 0; font-size: 0;
.fa {
font-size: 18px;
width: 22px;
height: 22px;
text-align: center;
}
span { span {
width: 22px; width: 22px;
height: 22px; height: 22px;
@ -188,19 +237,17 @@
.emoji-mart-no-results { .emoji-mart-no-results {
font-size: 14px; font-size: 14px;
text-align: center;
padding-top: 70px;
color: var(--primary-text-color--faint); color: var(--primary-text-color--faint);
text-align: center;
.emoji-mart-category-label { padding: 5px 6px;
display: none; padding-top: 70px;
}
.emoji-mart-no-results-label { .emoji-mart-no-results-label {
margin-top: 0.2em; margin-top: 0.2em;
} }
.emoji-mart-emoji:hover::before { .emoji-mart-emoji:hover::before {
cursor: default;
content: none; content: none;
} }
} }
@ -266,3 +313,34 @@
background-repeat: no-repeat; background-repeat: no-repeat;
} }
} }
.font-icon-picker {
.emoji-mart-search {
// Search doesn't work. Hide it for now.
display: none;
padding: 10px !important;
}
.emoji-mart-category-label > span {
padding: 9px 6px 5px;
}
.emoji-mart-scroll {
border-radius: 4px;
}
.emoji-mart-search-icon {
right: 18px;
}
.emoji-mart-bar {
display: none;
}
.fa {
font-size: 18px;
width: 22px;
height: 22px;
text-align: center;
}
}

Wyświetl plik

@ -520,6 +520,11 @@ code {
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
outline: none; outline: none;
display: flex;
align-items: center;
justify-content: center;
height: 41px;
box-sizing: border-box;
.fa { .fa {
font-size: 18px; font-size: 18px;

Wyświetl plik

@ -65,8 +65,8 @@
"cssnano": "^4.1.10", "cssnano": "^4.1.10",
"detect-passive-events": "^2.0.0", "detect-passive-events": "^2.0.0",
"dotenv": "^8.0.0", "dotenv": "^8.0.0",
"emoji-datasource": "4.0.4", "emoji-datasource": "5.0.0",
"emoji-mart": "https://gitlab.com/soapbox-pub/emoji-mart#build", "emoji-mart": "^3.0.1",
"es6-symbol": "^3.1.1", "es6-symbol": "^3.1.1",
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
"exif-js": "^2.3.0", "exif-js": "^2.3.0",

Wyświetl plik

@ -21,7 +21,6 @@ const backendEndpoints = [
'/auth/password', '/auth/password',
'/.well-known/webfinger', '/.well-known/webfinger',
'/static', '/static',
'/emoji',
'/main/ostatus', '/main/ostatus',
'/ostatus_subscribe', '/ostatus_subscribe',
]; ];

Wyświetl plik

@ -62,7 +62,7 @@ module.exports = merge(sharedConfig, {
}, },
externals: [ externals: [
'/emoji/1f602.svg', // used for emoji picker dropdown '/emoji/1f602.svg', // used for emoji picker dropdown
'/emoji/sheet_10.png', // used in emoji-mart '/emoji/sheet_13.png', // used in emoji-mart
], ],
excludes: [ excludes: [
'**/*.gz', '**/*.gz',

Wyświetl plik

@ -99,7 +99,7 @@ module.exports = {
to: join(__dirname, '../static/emoji'), to: join(__dirname, '../static/emoji'),
}, { }, {
from: join(__dirname, '../node_modules/emoji-datasource/img/twitter/sheets/32.png'), from: join(__dirname, '../node_modules/emoji-datasource/img/twitter/sheets/32.png'),
to: join(__dirname, '../static/emoji/sheet_10.png'), to: join(__dirname, '../static/emoji/sheet_13.png'),
}], }],
options: { options: {
concurrency: 100, concurrency: 100,

Wyświetl plik

@ -1444,6 +1444,13 @@
dependencies: dependencies:
regenerator-runtime "^0.12.0" regenerator-runtime "^0.12.0"
"@babel/runtime@^7.0.0", "@babel/runtime@^7.14.6", "@babel/runtime@^7.8.4":
version "7.14.6"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.14.6.tgz#535203bc0892efc7dec60bdc27b2ecf6e409062d"
integrity sha512-/PCB2uJ7oM44tz8YhC4Z/6PeOKXp4K588f+5M3clr1M4zbqztlo0XEfJ2LEzj/FgwfgGcIdl8n7YYjTCI0BYwg==
dependencies:
regenerator-runtime "^0.13.4"
"@babel/runtime@^7.1.2": "@babel/runtime@^7.1.2":
version "7.4.5" version "7.4.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.5.tgz#582bb531f5f9dc67d2fcb682979894f75e253f12" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.5.tgz#582bb531f5f9dc67d2fcb682979894f75e253f12"
@ -1465,13 +1472,6 @@
dependencies: dependencies:
regenerator-runtime "^0.13.4" regenerator-runtime "^0.13.4"
"@babel/runtime@^7.14.6", "@babel/runtime@^7.8.4":
version "7.14.6"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.14.6.tgz#535203bc0892efc7dec60bdc27b2ecf6e409062d"
integrity sha512-/PCB2uJ7oM44tz8YhC4Z/6PeOKXp4K588f+5M3clr1M4zbqztlo0XEfJ2LEzj/FgwfgGcIdl8n7YYjTCI0BYwg==
dependencies:
regenerator-runtime "^0.13.4"
"@babel/runtime@^7.7.2": "@babel/runtime@^7.7.2":
version "7.7.2" version "7.7.2"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.7.2.tgz#111a78002a5c25fc8e3361bedc9529c696b85a6a" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.7.2.tgz#111a78002a5c25fc8e3361bedc9529c696b85a6a"
@ -4973,14 +4973,18 @@ elliptic@^6.0.0:
minimalistic-assert "^1.0.0" minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.0" minimalistic-crypto-utils "^1.0.0"
emoji-datasource@4.0.4: emoji-datasource@5.0.0:
version "4.0.4" version "5.0.0"
resolved "https://registry.yarnpkg.com/emoji-datasource/-/emoji-datasource-4.0.4.tgz#516b9ab2f34569e468e4e3753a34a47a0b2b5aa3" resolved "https://registry.yarnpkg.com/emoji-datasource/-/emoji-datasource-5.0.0.tgz#1522fdba3c52223a1cf5a1c1fc282935400eaa06"
integrity sha1-UWuasvNFaeRo5ON1OjSkegsrWqM= integrity sha512-LuvLWFnxznTH++GytEzpzOPUo1SB+6CUFqIlVETJJ3x9fpyMCKFfyqberbhMLOpT1qcNe+km+zoyBeUSC3u5Rw==
"emoji-mart@https://gitlab.com/soapbox-pub/emoji-mart#build": emoji-mart@^3.0.1:
version "2.6.3" version "3.0.1"
resolved "https://gitlab.com/soapbox-pub/emoji-mart#4bdefa3d3ee7eb58716adc8727f688facc557291" resolved "https://registry.yarnpkg.com/emoji-mart/-/emoji-mart-3.0.1.tgz#9ce86706e02aea0506345f98464814a662ca54c6"
integrity sha512-sxpmMKxqLvcscu6mFn9ITHeZNkGzIvD0BSNFE/LJESPbCA8s1jM6bCDPjWbV31xHq7JXaxgpHxLB54RCbBZSlg==
dependencies:
"@babel/runtime" "^7.0.0"
prop-types "^15.6.0"
emoji-regex@^7.0.1: emoji-regex@^7.0.1:
version "7.0.3" version "7.0.3"