Skip to content

Commit 74c218d

Browse files
committed
Use fname to render emojis properly
1 parent 9975f41 commit 74c218d

File tree

10 files changed

+29
-31
lines changed

10 files changed

+29
-31
lines changed

draft-js-emoji-plugin/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "draft-js-emoji-plugin",
3-
"version": "2.1.1",
2+
"name": "draft-js-emoji-bump",
3+
"version": "2.1.1-beta5",
44
"description": "Emoji Plugin for DraftJS",
55
"author": {
66
"name": "Nik Graf",
@@ -32,11 +32,11 @@
3232
"license": "MIT",
3333
"dependencies": {
3434
"decorate-component-with-props": "^1.1.0",
35-
"emojione": "^2.2.7",
35+
"emojione": "^4.5.0",
3636
"find-with-regex": "^1.1.3",
3737
"immutable": "~3.7.4",
38-
"prop-types": "^15.5.8",
3938
"lodash.keys": "^4.2.0",
39+
"prop-types": "^15.5.8",
4040
"react-custom-scrollbars": "^4.2.0",
4141
"react-icons": "^2.2.6",
4242
"to-style": "^1.3.3",

draft-js-emoji-plugin/src/components/Emoji/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ const Emoji = ({ theme = {}, cacheBustParam, imagePath, imageType, className, de
1616
);
1717
} else {
1818
// short name to image url code steal from emojione source code
19-
const shortNameForImage = emojione.emojioneList[shortName].unicode[emojione.emojioneList[shortName].unicode.length - 1];
20-
const backgroundImage = `url(${imagePath}${shortNameForImage}.${imageType}${cacheBustParam})`;
19+
const codepointsForImage = emojione.emojioneList[shortName].fname;
20+
const backgroundImage = `url(${imagePath}${codepointsForImage}.${imageType}${cacheBustParam})`;
2121
const combinedClassName = unionClassNames(theme.emoji, className);
2222

2323
emojiDisplay = (
2424
<span
2525
className={combinedClassName}
26-
title={emojione.toShort(decoratedText)}
26+
title={shortName}
2727
style={{ backgroundImage }}
2828
>
2929
{props.children}

draft-js-emoji-plugin/src/components/EmojiSelect/Popover/Entry/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export default class Entry extends Component {
6666
emojiDisplay = convertShortNameToUnicode(unicode);
6767
} else {
6868
// short name to image url code steal from emojione source code
69-
const shortNameForImage = emojione.emojioneList[emoji].unicode[emojione.emojioneList[emoji].unicode.length - 1];
70-
const fullImagePath = `${imagePath}${shortNameForImage}.${imageType}${cacheBustParam}`;
69+
const codePointsForImage = emojione.emojioneList[emoji].fname;
70+
const fullImagePath = `${imagePath}${codePointsForImage}.${imageType}${cacheBustParam}`;
7171
emojiDisplay = (
7272
<img
7373
src={fullImagePath}

draft-js-emoji-plugin/src/components/EmojiSuggestions/Entry/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ export default class Entry extends Component {
4141

4242
let emojiDisplay = null;
4343
if (useNativeArt === true) {
44-
const unicode = emojiList.list[this.props.emoji][0];
44+
const unicode = emojiList.list[this.props.emoji];
4545
emojiDisplay = convertShortNameToUnicode(unicode);
4646
} else {
4747
// short name to image url code steal from emojione source code
48-
const shortNameForImage = emojione.emojioneList[this.props.emoji].unicode[emojione.emojioneList[this.props.emoji].unicode.length - 1];
49-
const fullImagePath = `${imagePath}${shortNameForImage}.${imageType}${cacheBustParam}`;
48+
const codePointsForImage = emojione.emojioneList[this.props.emoji].fname;
49+
const fullImagePath = `${imagePath}${codePointsForImage}.${imageType}${cacheBustParam}`;
5050
emojiDisplay = (
5151
<img
5252
src={fullImagePath}

draft-js-emoji-plugin/src/emojiStrategy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import findWithRegex from 'find-with-regex';
22
import emojione from 'emojione';
33

4-
const unicodeRegex = new RegExp(emojione.unicodeRegexp, 'g');
4+
const unicodeRegex = emojione.regUnicode;
55

66
export default (contentBlock: Object, callback: Function) => {
77
findWithRegex(unicodeRegex, contentBlock, callback);

draft-js-emoji-plugin/src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import attachImmutableEntitiesToEmojis from './modifiers/attachImmutableEntities
1717
import defaultPositionSuggestions from './utils/positionSuggestions';
1818
import emojiList from './utils/emojiList';
1919

20-
const defaultImagePath = '//cdn.jsdelivr.net/emojione/assets/svg/';
21-
const defaultImageType = 'svg';
22-
const defaultCacheBustParam = '?v=2.2.7';
20+
const defaultImagePath = '//cdn.jsdelivr.net/npm/emojione-assets@3.1.0/png/128/';
21+
const defaultImageType = 'png';
22+
const defaultCacheBustParam = '?v=4.5.0';
2323

2424
// TODO activate/deactivate different the conversion or search part
2525

draft-js-emoji-plugin/src/modifiers/addEmoji.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Mode = {
1111
};
1212

1313
const addEmoji = (editorState, emojiShortName, mode = Mode.INSERT) => {
14-
const unicode = emojiList.list[emojiShortName][0];
14+
const unicode = emojiList.list[emojiShortName];
1515
const emoji = convertShortNameToUnicode(unicode);
1616

1717
const contentState = editorState.getCurrentContent();

draft-js-emoji-plugin/src/modifiers/attachImmutableEntitiesToEmojis.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EditorState, Modifier, SelectionState } from 'draft-js';
22
import findWithRegex from 'find-with-regex';
33
import emojione from 'emojione';
44

5-
const unicodeRegex = new RegExp(emojione.unicodeRegexp, 'g');
5+
const unicodeRegex = emojione.regUnicode;
66

77
/*
88
* Attaches Immutable DraftJS Entities to the Emoji text.

draft-js-emoji-plugin/src/utils/emojiList.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const newEmojiListWithOutPriorityList = (priorityList) => {
66
if (priorityList.hasOwnProperty(key)) { // eslint-disable-line no-prototype-builtins
77
continue; // eslint-disable-line no-continue
88
}
9-
list[key] = emojione.emojioneList[key].unicode;
9+
list[key] = emojione.emojioneList[key].fname;
1010
}
1111

1212
return { ...priorityList, ...list };
@@ -21,15 +21,15 @@ emojiList.setPriorityList = (newPriorityList) => {
2121

2222
// init emojiList
2323
const priorityList = {
24-
':thumbsup:': ['1f44d'],
25-
':smile:': ['1f604'],
26-
':heart:': ['2764-fe0f', '2764'],
27-
':ok_hand:': ['1f44c'],
28-
':joy:': ['1f602'],
29-
':tada:': ['1f389'],
30-
':see_no_evil:': ['1f648'],
31-
':raised_hands:': ['1f64c'],
32-
':100:': ['1f4af'],
24+
':thumbsup:': '1f44d',
25+
':smile:': '1f604',
26+
':heart:': '2764-fe0f',
27+
':ok_hand:': '1f44c',
28+
':joy:': '1f602',
29+
':tada:': '1f389',
30+
':see_no_evil:': '1f648',
31+
':raised_hands:': '1f64c',
32+
':100:': '1f4af',
3333
};
3434
emojiList.setPriorityList(priorityList);
3535

draft-js-emoji-plugin/src/utils/mappedUnicode.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ const mapUnicode = () => {
99
continue;// eslint-disable-line no-continue
1010
}
1111

12-
for (let i = 0, len = emojiList.list[shortname].length; i < len; i += 1) {
13-
unicodes[emojiList.list[shortname][i]] = shortname;
14-
}
12+
unicodes[emojiList.list[shortname]] = shortname;
1513
}
1614

1715
return unicodes;

0 commit comments

Comments
 (0)