Skip to content

Commit

Permalink
Merge pull request #8936 from weseek/imprv/142615-148862-support-dark…
Browse files Browse the repository at this point in the history
…-theme-of-emoji-mart

imprv: Dark theme support for emoji mart
  • Loading branch information
yuki-takei authored Jul 3, 2024
2 parents 689f128 + 7d8d94a commit f512b7c
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 245 deletions.
30 changes: 0 additions & 30 deletions apps/app/public/static/locales/en_US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -707,36 +707,6 @@
"password_and_confirm_password_does_not_match": "Password and confirm password does not match",
"please_enable_mailer_alert": "The password reset feature is disabled because email setup has not been completed. Please ask administrator to complete the email setup."
},
"emoji": {
"title": "Pick an Emoji",
"search": "Search",
"clear": "Clear",
"notfound": "No Emoji Found",
"skintext": "Choose your default skin tone",
"categories": {
"search": "Search Results",
"recent": "Frequently Used",
"smileys": "Smileys & Emotion",
"people": "People & Body",
"nature": "Animals & Nature",
"foods": "Food & Drink",
"activity": "Activity",
"places": "Travel & Places",
"objects": "Objects",
"symbols": "Symbols",
"flags": "Flags",
"custom": "Custom"
},
"categorieslabel": "Emoji categories",
"skintones": {
"1": "Default Skin Tone",
"2": "Light Skin Tone",
"3": "Medium-Light Skin Tone",
"4": "Medium Skin Tone",
"5": "Medium-Dark Skin Tone",
"6": "Dark Skin Tone"
}
},
"maintenance_mode": {
"maintenance_mode": "Maintenance Mode",
"growi_is_under_maintenance": "GROWI is under maintenance. Please wait until it ends.",
Expand Down
30 changes: 0 additions & 30 deletions apps/app/public/static/locales/fr_FR/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,36 +701,6 @@
"password_and_confirm_password_does_not_match": "Le mot de passe ne correspond pas",
"please_enable_mailer_alert": "La réinitialisation de mot de passe est désactivée, car la configuration d'envois de courriels est incomplète."
},
"emoji": {
"title": "Choisir un émoji",
"search": "Rechercher",
"clear": "Vider",
"notfound": "Aucun émoji trouvé",
"skintext": "Choisir le teint par défaut",
"categories": {
"search": "Résultats de recherche",
"recent": "Récents",
"smileys": "Émotions",
"people": "Individus & corps",
"nature": "Animaux & nature",
"foods": "Nourriture & boisson",
"activity": "Activités",
"places": "Voyage",
"objects": "Objets",
"symbols": "Symboles",
"flags": "Drapeaux",
"custom": "Personnalisé"
},
"categorieslabel": "Catégories d'émojis",
"skintones": {
"1": "Teint par défaut",
"2": "Teint clair",
"3": "Teint moyen-clair",
"4": "Teint moyen",
"5": "Teint moyen-foncé",
"6": "Teint foncé"
}
},
"maintenance_mode": {
"maintenance_mode": "Mode maintenance",
"growi_is_under_maintenance": "GROWI est actuellement en maintenance.",
Expand Down
30 changes: 0 additions & 30 deletions apps/app/public/static/locales/ja_JP/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -740,36 +740,6 @@
"password_and_confirm_password_does_not_match": "パスワードと確認パスワードが一致しません",
"please_enable_mailer_alert": "メール設定が完了していないため、パスワード再設定機能が無効になっています。メール設定を完了させるよう管理者に依頼してください。"
},
"emoji": {
"title": "絵文字を選択",
"search": "探す",
"clear": "リセット",
"notfound": "絵文字が見つかりません",
"skintext": "デフォルトの肌の色を選択",
"categories": {
"search": "検索結果",
"recent": "最新履歴",
"smileys": "スマイリーと感情",
"people": "人と体",
"nature": "動物と自然",
"foods": "食べ物や飲み物",
"activity": "アクティビティ",
"places": "旅行と場所",
"objects": "オブジェクト",
"symbols": "シンボル",
"flags": "国旗",
"custom": "カスタマイズ"
},
"categorieslabel": "絵文字カテゴリ",
"skintones": {
"1": "デフォルトの肌の色",
"2": "明るい肌のトーン",
"3": "ミディアム-明るい肌のトーン",
"4": "ミディアムスキントーン",
"5": "ミディアムダークスキントーン",
"6": "肌の色が濃い"
}
},
"maintenance_mode": {
"maintenance_mode": "メンテナンスモード",
"growi_is_under_maintenance": "GROWI はメンテナンス中です。終了するまでお待ちください",
Expand Down
30 changes: 0 additions & 30 deletions apps/app/public/static/locales/zh_CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -710,36 +710,6 @@
"password_and_confirm_password_does_not_match": "密码和确认密码不匹配",
"please_enable_mailer_alert": "密码重置功能被禁用,因为电子邮件设置尚未完成。请要求管理员完成电子邮件的设置。"
},
"emoji": {
"title": "选择一个表情符号",
"search": "搜索",
"clear": "重置",
"notfound": "找不到表情符号",
"skintext": "选择您的默认肤色",
"categories": {
"search": "搜索结果",
"recent": "经常使用",
"smileys": "笑脸和情感",
"people": "人和身体",
"nature": "动物与自然",
"foods": "食物和饮料",
"activity": "活动",
"places": "旅行和地方",
"objects": "对象",
"symbols": "符号",
"flags": "旗帜",
"custom": "定制"
},
"categorieslabel": "表情符号类别",
"skintones": {
"1": "默认肤色",
"2": "浅肤色",
"3": "中浅肤色",
"4": "中等肤色",
"5": "中深肤色",
"6": "深色肤色"
}
},
"maintenance_mode": {
"maintenance_mode": "维护模式",
"growi_is_under_maintenance": "GROWI正在进行维护。请等待,直到它结束。",
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@codemirror/merge": "6.0.0",
"@codemirror/state": "^6.2.1",
"@codemirror/view": "^6.15.3",
"@emoji-mart/data": "^1.2.1",
"@emoji-mart/react": "^1.1.1",
"@growi/core": "link:../core",
"@growi/core-styles": "link:../core-styles",
"@popperjs/core": "^2.11.8",
Expand All @@ -51,7 +53,7 @@
"cm6-theme-nord": "^0.2.0",
"codemirror": "^6.0.1",
"csv-to-markdown-table": "^1.4.1",
"emoji-mart": "npm:panta82-emoji-mart@^3.0.1",
"emoji-mart": "^5.6.0",
"eslint-plugin-react-refresh": "^0.4.1",
"markdown-table": "^3.0.3",
"react-dropzone": "^14.2.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/@types/emoji-mart.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
declare module 'emoji-mart';
declare module '@emoji-mart/data';
declare module '@emoji-mart/react';
Original file line number Diff line number Diff line change
@@ -1,102 +1,45 @@
import {
useState, useCallback,
type FC, type CSSProperties,
type CSSProperties,
} from 'react';

import { Picker } from 'emoji-mart';
import i18n from 'i18next';
import emojiData from '@emoji-mart/data';
import Picker from '@emoji-mart/react';
import { Modal } from 'reactstrap';

import 'emoji-mart/css/emoji-mart.css';
import { useCodeMirrorEditorIsolated } from '../../../stores/codemirror-editor';
import { useResolvedThemeForEditor } from '../../../stores/use-resolved-theme';

type Props = {
editorKey: string,
}

type Translation = {
search: string
clear: string
notfound: string
skintext: string
categories: object
categorieslabel: string
skintones: object
title: string
}

// TODO: https://redmine.weseek.co.jp/issues/133681
const getEmojiTranslation = (): Translation => {

const categories: { [key: string]: string } = {};
[
'search',
'recent',
'smileys',
'people',
'nature',
'foods',
'activity',
'places',
'objects',
'symbols',
'flags',
'custom',
].forEach((category) => {
categories[category] = i18n.t(`emoji.categories.${category}`);
});

const skintones: { [key: string]: string} = {};
(Array.from(Array(6).keys())).forEach((tone) => {
skintones[tone + 1] = i18n.t(`emoji.skintones.${tone + 1}`);
});

const translation = {
search: i18n.t('emoji.search'),
clear: i18n.t('emoji.clear'),
notfound: i18n.t('emoji.notfound'),
skintext: i18n.t('emoji.skintext'),
categories,
categorieslabel: i18n.t('emoji.categorieslabel'),
skintones,
title: i18n.t('emoji.title'),
};

return translation;
};

const translation = getEmojiTranslation();

export const EmojiButton: FC<Props> = (props) => {
export const EmojiButton = (props: Props): JSX.Element => {
const { editorKey } = props;

const [isOpen, setIsOpen] = useState(false);

const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(editorKey);
const { data: resolvedTheme } = useResolvedThemeForEditor();

const view = codeMirrorEditor?.view;
const cursorIndex = view?.state.selection.main.head;
const toggle = useCallback(() => setIsOpen(!isOpen), [isOpen]);

const selectEmoji = useCallback((emoji: { colons: string }): void => {
const selectEmoji = useCallback((emoji: { shortcodes: string }): void => {

if (cursorIndex == null || !isOpen) {
if (!isOpen) {
return;
}

view?.dispatch({
changes: {
from: cursorIndex,
insert: emoji.colons,
},
});
codeMirrorEditor?.insertText(emoji.shortcodes);

toggle();
}, [cursorIndex, isOpen, toggle, view]);
}, [isOpen, toggle, codeMirrorEditor]);


const setStyle = useCallback((): CSSProperties => {

const view = codeMirrorEditor?.view;
const cursorIndex = view?.state.selection.main.head;

if (view == null || cursorIndex == null || !isOpen) {
return {};
}
Expand All @@ -123,7 +66,7 @@ export const EmojiButton: FC<Props> = (props) => {
left: cursorRect.left + offset,
position: 'fixed',
};
}, [cursorIndex, isOpen, view]);
}, [isOpen, codeMirrorEditor]);

return (
<>
Expand All @@ -134,14 +77,15 @@ export const EmojiButton: FC<Props> = (props) => {
&& (
<div className="mb-2 d-none d-md-block">
<Modal isOpen={isOpen} toggle={toggle} backdropClassName="emoji-picker-modal" fade={false}>
<Picker
onSelect={selectEmoji}
i18n={translation}
title={translation.title}
emojiTooltip
style={setStyle()}
theme={resolvedTheme}
/>
<span style={setStyle()}>
<Picker
onEmojiSelect={selectEmoji}
theme={resolvedTheme?.themeData}
data={emojiData}
// TODO: https://redmine.weseek.co.jp/issues/133681
// i18n={}
/>
</span>
</Modal>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type CompletionContext, type Completion, autocompletion } from '@codemirror/autocomplete';
import { syntaxTree } from '@codemirror/language';
import { emojiIndex } from 'emoji-mart';
import emojiData from 'emoji-mart/data/all.json';
import emojiData from '@emoji-mart/data';


const getEmojiDataArray = (): string[] => {
const rawEmojiDataArray = emojiData.categories;
Expand All @@ -20,7 +20,7 @@ const getEmojiDataArray = (): string[] => {
const fixedEmojiDataArray: string[] = [];

emojiCategoriesData.forEach((value) => {
const tempArray = rawEmojiDataArray.find(obj => obj.id === value)?.emojis;
const tempArray = rawEmojiDataArray.find((obj: {id: string}) => obj.id === value)?.emojis;

if (tempArray == null) {
return;
Expand Down Expand Up @@ -60,9 +60,7 @@ export const emojiAutocompletionSettings = autocompletion({
addToOptions: [{
render: (completion: Completion) => {
const emojiName = completion.type ?? '';
const emojiData = emojiIndex.emojis[emojiName];

const emoji = emojiData.native ?? emojiData[1].native;
const emoji = emojiData.emojis[emojiName].skins[0].native;

const element = document.createElement('span');
element.innerHTML = emoji;
Expand Down
3 changes: 0 additions & 3 deletions packages/editor/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ export default defineConfig({
preserveModules: true,
preserveModulesRoot: 'src',
},
external: [
'emoji-mart/css/emoji-mart.css',
],
},
},
});
Loading

0 comments on commit f512b7c

Please sign in to comment.