From 1c93fbc00770d5364df47c1166f3bd7e30ae4879 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Mon, 26 May 2025 13:12:58 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20fix=20multiple=20Emoji?= =?UTF-8?q?Picker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit emoji-mart is used to display emojis in the editor. It is used by the callout block and by Blocknotes editor. The problem is that the emoji-mart is a singleton, so if Blocknotes components init the emoji-mart first, the picker in the callout block will not display correctly. This commit fixes the issue by initializing the emoji-mart in the callout block first. --- CHANGELOG.md | 3 +- .../doc-editor/components/EmojiPicker.tsx | 13 +--- .../components/custom-blocks/CalloutBlock.tsx | 51 +------------ .../custom-blocks/initEmojiCallout.ts | 76 +++++++++++++++++++ 4 files changed, 85 insertions(+), 58 deletions(-) create mode 100644 src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/initEmojiCallout.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 470cfa52..ee9f23c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ and this project adheres to ### Fixed -🐛(frontend) table of content disappearing #982 +-🐛(frontend) table of content disappearing #982 +-🐛(frontend) fix multiple EmojiPicker #1012 ## [3.3.0] - 2025-05-06 diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/EmojiPicker.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/EmojiPicker.tsx index f2ff859b..8c5f5b79 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/EmojiPicker.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/EmojiPicker.tsx @@ -1,4 +1,4 @@ -import data from '@emoji-mart/data'; +import { EmojiMartData } from '@emoji-mart/data'; import Picker from '@emoji-mart/react'; import React from 'react'; import { useTranslation } from 'react-i18next'; @@ -6,19 +6,15 @@ import { useTranslation } from 'react-i18next'; import { Box } from '@/components'; interface EmojiPickerProps { + emojiData: EmojiMartData; categories: string[]; - custom: { - name: string; - id: string; - emojis: string[]; - }[]; onClickOutside: () => void; onEmojiSelect: ({ native }: { native: string }) => void; } export const EmojiPicker = ({ + emojiData, categories, - custom, onClickOutside, onEmojiSelect, }: EmojiPickerProps) => { @@ -27,9 +23,8 @@ export const EmojiPicker = ({ return ( diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/initEmojiCallout.ts b/src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/initEmojiCallout.ts new file mode 100644 index 00000000..b104568b --- /dev/null +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/initEmojiCallout.ts @@ -0,0 +1,76 @@ +/** + * "emoji-mart" is a singleton, multiple imports in the same + * application could cause issues. + * BlockNote uses "emoji-mart" internally as well, if + * Blocknote emoji picker is init before the callout emoji picker, + * the callout emoji picker will not be set up correctly. + * To avoid this, we initialize emoji-mart here and before any + * other components that uses it. + */ +import data, { Category, EmojiMartData } from '@emoji-mart/data'; +import { init } from 'emoji-mart'; + +type EmojiMartDataFixed = Omit & { + categories: (Category & { name: string })[]; +}; + +const emojidata = structuredClone(data) as EmojiMartDataFixed; + +const CALLOUT_ID = 'callout'; +const CALLOUT_EMOJIS = [ + 'bulb', + 'point_right', + 'point_up', + 'ok_hand', + 'key', + 'construction', + 'warning', + 'fire', + 'pushpin', + 'scissors', + 'question', + 'no_entry', + 'no_entry_sign', + 'alarm_clock', + 'phone', + 'rotating_light', + 'recycle', + 'white_check_mark', + 'lock', + 'paperclip', + 'book', + 'speaking_head_in_silhouette', + 'arrow_right', + 'loudspeaker', + 'hammer_and_wrench', + 'gear', +]; + +if (!emojidata.categories.some((c) => c.id === CALLOUT_ID)) { + emojidata.categories.unshift({ + id: CALLOUT_ID, + name: 'Callout', + emojis: CALLOUT_EMOJIS, + }); +} + +void init({ data: emojidata }); + +const calloutCategories = [ + 'callout', + 'people', + 'nature', + 'foods', + 'activity', + 'places', + 'flags', + 'objects', + 'symbols', +]; + +const calloutEmojiData = { + emojidata, + calloutCategories, +}; + +export default calloutEmojiData;