diff --git a/example/src/ExampleInput.js b/example/src/ExampleInput.js index 5568864..950582b 100644 --- a/example/src/ExampleInput.js +++ b/example/src/ExampleInput.js @@ -72,7 +72,6 @@ const ExampleInput = () => { onEnter={text => { console.log("enter", text); }} - language="fr" placeholder="Type a message" keepOpened disableRecent diff --git a/package.json b/package.json index e8d9ff5..4fe4900 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-input-emoji", - "version": "5.6.8", + "version": "5.6.9", "description": "A React input with an option to add an emoji with language support.", "homepage": "https://cesarwbr.github.io/react-input-emoji/", "author": "cesarwbr", diff --git a/rollup.config.js b/rollup.config.js index 3bfb3e8..04bf356 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -16,13 +16,11 @@ export default { file: pkg.main, format: 'cjs', sourcemap: true, - inlineDynamicImports: true, }, { file: pkg.module, format: 'es', sourcemap: true, - inlineDynamicImports: true, }, ], plugins: [ diff --git a/src/components/emoji-picker.js b/src/components/emoji-picker.js index c45f460..880101f 100644 --- a/src/components/emoji-picker.js +++ b/src/components/emoji-picker.js @@ -2,6 +2,9 @@ import React, { memo, useEffect, useMemo, useState } from "react"; import Picker from "@emoji-mart/react"; +const EMOJI_MART_DATA_URL = "https://cdn.jsdelivr.net/npm/@emoji-mart/data"; +const cacheI18n = {}; + /** * @typedef {object} Props * @property {'light' | 'dark' | 'auto'} theme @@ -46,11 +49,17 @@ function EmojiPicker(props) { useEffect(() => { if (!language) { + if (cacheI18n.en) { + setI18n(cacheI18n.en); + return; + } + // @ts-ignore - fetch(`https://cdn.jsdelivr.net/npm/@emoji-mart/data/i18n/en.json`) + fetch(`${EMOJI_MART_DATA_URL}/i18n/en.json`) .then(async data => { const translations = await data.json(); setI18n(translations); + cacheI18n.en = translations; }) .catch(error => { console.error("Failed to load translations:", error); @@ -59,10 +68,11 @@ function EmojiPicker(props) { } // @ts-ignore - fetch(`https://cdn.jsdelivr.net/npm/@emoji-mart/data/i18n/${language}.json`) + fetch(`${EMOJI_MART_DATA_URL}/i18n/${language}.json`) .then(async data => { const translations = await data.json(); setI18n(translations); + cacheI18n[language] = translations; }) .catch(error => { console.error("Failed to load translations:", error); diff --git a/src/hooks/use-sanitize.js b/src/hooks/use-sanitize.js index ed02ab8..2b74e66 100644 --- a/src/hooks/use-sanitize.js +++ b/src/hooks/use-sanitize.js @@ -57,5 +57,8 @@ export function replaceAllHtmlToString(html, shouldReturn) { // remove all ↵ for safari text = text.replace(/\n/gi, ""); - return text; + const tempContainer = document.createElement("div"); + tempContainer.innerHTML = text; + + return tempContainer.innerText || ""; }