Adding emoji-short-name package.

- Fixes #266
This commit is contained in:
Dessalines 2019-09-04 15:22:31 -07:00
parent 6cd93ef990
commit d16df598fa
5 changed files with 18 additions and 1725 deletions

1
ui/package.json vendored
View file

@ -23,6 +23,7 @@
"autosize": "^4.0.2", "autosize": "^4.0.2",
"classcat": "^1.1.3", "classcat": "^1.1.3",
"dotenv": "^6.1.0", "dotenv": "^6.1.0",
"emoji-short-name": "^0.1.0",
"i18next": "^17.0.9", "i18next": "^17.0.9",
"inferno": "^7.0.1", "inferno": "^7.0.1",
"inferno-i18next": "nimbusec-oss/inferno-i18next", "inferno-i18next": "nimbusec-oss/inferno-i18next",

View file

@ -2,12 +2,12 @@ import { Component, linkEvent } from 'inferno';
import { CommentNode as CommentNodeI, CommentForm as CommentFormI, SearchForm, SearchType, SortType, UserOperation, SearchResponse } from '../interfaces'; import { CommentNode as CommentNodeI, CommentForm as CommentFormI, SearchForm, SearchType, SortType, UserOperation, SearchResponse } from '../interfaces';
import { Subscription } from "rxjs"; import { Subscription } from "rxjs";
import { capitalizeFirstLetter, mentionDropdownFetchLimit, msgOp, mdToHtml, randomStr, imageUploadUrl, markdownHelpUrl } from '../utils'; import { capitalizeFirstLetter, mentionDropdownFetchLimit, msgOp, mdToHtml, randomStr, imageUploadUrl, markdownHelpUrl } from '../utils';
import { twemojis } from '../twemojis';
import { WebSocketService, UserService } from '../services'; import { WebSocketService, UserService } from '../services';
import * as autosize from 'autosize'; import * as autosize from 'autosize';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
import { T } from 'inferno-i18next'; import { T } from 'inferno-i18next';
import Tribute from 'tributejs/src/Tribute.js'; import Tribute from 'tributejs/src/Tribute.js';
import * as emojiShortName from 'emoji-short-name';
interface CommentFormProps { interface CommentFormProps {
postId?: number; postId?: number;
@ -55,7 +55,7 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
selectTemplate: (item: any) => { selectTemplate: (item: any) => {
return `:${item.original.key}:`; return `:${item.original.key}:`;
}, },
values: Object.entries(twemojis).map(e => {return {'key': e[0], 'val': e[1]}}), values: Object.entries(emojiShortName).map(e => {return {'key': e[1], 'val': e[0]}}),
allowSpaces: false, allowSpaces: false,
autocompleteMode: true, autocompleteMode: true,
menuItemLimit: 10, menuItemLimit: 10,

1721
ui/src/twemojis.ts vendored

File diff suppressed because it is too large Load diff

12
ui/src/utils.ts vendored
View file

@ -12,7 +12,7 @@ import * as markdown_it from 'markdown-it';
import * as markdownitEmoji from 'markdown-it-emoji/light'; import * as markdownitEmoji from 'markdown-it-emoji/light';
import * as markdown_it_container from 'markdown-it-container'; import * as markdown_it_container from 'markdown-it-container';
import * as twemoji from 'twemoji'; import * as twemoji from 'twemoji';
import { twemojis } from './twemojis'; import * as emojiShortName from 'emoji-short-name';
export const repoUrl = 'https://github.com/dessalines/lemmy'; export const repoUrl = 'https://github.com/dessalines/lemmy';
export const imageUploadUrl = 'https://postimages.org/'; export const imageUploadUrl = 'https://postimages.org/';
@ -50,7 +50,7 @@ export const md = new markdown_it({
} }
} }
}).use(markdownitEmoji, { }).use(markdownitEmoji, {
defs: twemojis defs: objectFlip(emojiShortName)
}); });
md.renderer.rules.emoji = function(token, idx) { md.renderer.rules.emoji = function(token, idx) {
@ -197,6 +197,14 @@ export function getLanguage(): string {
return (navigator.language || navigator.userLanguage); return (navigator.language || navigator.userLanguage);
} }
export function objectFlip(obj: any) {
const ret = {};
Object.keys(obj).forEach((key) => {
ret[obj[key]] = key;
});
return ret;
}
export function getMomentLanguage(): string { export function getMomentLanguage(): string {
let lang = getLanguage(); let lang = getLanguage();
if (lang.startsWith('zh')) { if (lang.startsWith('zh')) {

5
ui/yarn.lock vendored
View file

@ -782,6 +782,11 @@ ee-first@1.1.1:
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
emoji-short-name@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/emoji-short-name/-/emoji-short-name-0.1.0.tgz#e2f0fd743e3e16384ae32f8a8b0ce6a47216e1d3"
integrity sha512-vpQaGMxBDC4VGHz52CjVKTJsGsgQ0YueEgQFyDkoanPIK3RgGMbHSjnek2viaCwgf8T6TKCR5v03O/SlfD7iFA==
encodeurl@~1.0.2: encodeurl@~1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"