Update to Twemoji 12 and switch to 'simple-emoji-map' (#20)

This commit is contained in:
David Sevilla Martín 2019-08-01 17:17:25 -04:00 committed by Franz Liedke
parent 7ae9b1263b
commit 5fe1de86dc
7 changed files with 923 additions and 653 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,18 +2,15 @@
"private": true, "private": true,
"name": "@flarum/emoji", "name": "@flarum/emoji",
"dependencies": { "dependencies": {
"emojibase-data": "^3.2.0",
"flarum-webpack-config": "0.1.0-beta.10", "flarum-webpack-config": "0.1.0-beta.10",
"simple-emoji-map": "^0.3.0",
"textarea-caret": "^3.1.0", "textarea-caret": "^3.1.0",
"twemoji": "^11.2.0", "twemoji": "^12.1.2",
"webpack": "^4.26.0", "webpack": "^4.35.3",
"webpack-cli": "^3.1.2" "webpack-cli": "^3.3.5"
}, },
"scripts": { "scripts": {
"dev": "webpack --mode development --watch", "dev": "webpack --mode development --watch",
"build": "webpack --mode production", "build": "webpack --mode production"
"predev": "npm run generate-emoji-map",
"prebuild": "npm run generate-emoji-map",
"generate-emoji-map": "node ./scripts/generate-emoji-map.js"
} }
} }

View File

@ -1,45 +0,0 @@
const fs = require('fs');
const path = require('path');
const twemoji = require('twemoji/2/twemoji.npm');
const outputPath = './src/forum/generated/emojiMap.json';
const data = require('emojibase-data/en/data.json');
const twemojiFileNames = fs.readdirSync('./node_modules/twemoji/2/svg')
.map(name => path.basename(name, '.svg'));
const alternative = {
"👁️‍🗨️" : "👁‍🗨",
};
const emojis = {};
for (let e of data) {
const emoji = alternative[e.emoji] || e.emoji;
const emojiCode = getEmojiIconCode(emoji);
if (!checkExistanceInTwemoji(emojiCode)) {
console.error('Can not find', emoji, emojiCode);
continue;
}
emojis[emoji] = e.shortcodes;
}
const outputDir = path.dirname(outputPath);
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
fs.writeFileSync(outputPath, JSON.stringify(emojis));
function checkExistanceInTwemoji(code) {
return twemojiFileNames.indexOf(code) != -1;
}
function getEmojiIconCode(emoji) {
const U200D = String.fromCharCode(0x200D);
return twemoji.convert.toCodePoint(emoji.indexOf(U200D) < 0 ?
emoji.replace(/\uFE0F/g, '') :
emoji
);
}

View File

@ -1,10 +1,10 @@
import getCaretCoordinates from 'textarea-caret'; import getCaretCoordinates from 'textarea-caret';
import emojiMap from 'simple-emoji-map';
import { extend } from 'flarum/extend'; import { extend } from 'flarum/extend';
import ComposerBody from 'flarum/components/ComposerBody'; import ComposerBody from 'flarum/components/ComposerBody';
import TextEditor from 'flarum/components/TextEditor'; import TextEditor from 'flarum/components/TextEditor';
import TextEditorButton from 'flarum/components/TextEditorButton'; import TextEditorButton from 'flarum/components/TextEditorButton';
import emojiMap from './generated/emojiMap.json';
import getEmojiIconCode from './helpers/getEmojiIconCode'; import getEmojiIconCode from './helpers/getEmojiIconCode';
import KeyboardNavigatable from 'flarum/utils/KeyboardNavigatable'; import KeyboardNavigatable from 'flarum/utils/KeyboardNavigatable';

View File

@ -2,7 +2,7 @@
https://github.com/twitter/twemoji/blob/gh-pages/LICENSE https://github.com/twitter/twemoji/blob/gh-pages/LICENSE
*/ */
import twemoji from 'twemoji/2/twemoji.npm'; import twemoji from 'twemoji';
// avoid using a string literal like '\u200D' here because minifiers expand it inline // avoid using a string literal like '\u200D' here because minifiers expand it inline
const U200D = String.fromCharCode(0x200D); const U200D = String.fromCharCode(0x200D);

View File

@ -1,6 +1,4 @@
import { override } from 'flarum/extend';
import app from 'flarum/app'; import app from 'flarum/app';
import Post from 'flarum/models/Post';
import addComposerAutocomplete from './addComposerAutocomplete'; import addComposerAutocomplete from './addComposerAutocomplete';
import renderEmoji from './renderEmoji'; import renderEmoji from './renderEmoji';

View File

@ -1,6 +1,6 @@
/*global s9e*/ /*global s9e*/
import twemoji from 'twemoji/2/twemoji.npm'; import twemoji from 'twemoji';
import { override } from 'flarum/extend'; import { override } from 'flarum/extend';
import Post from 'flarum/models/Post'; import Post from 'flarum/models/Post';