@chayns-components/emoji-input 5.0.0-beta.499 → 5.0.0-beta.501

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,7 +54,7 @@ export const escapeHTML = text => {
54
54
  '"': '"',
55
55
  "'": '''
56
56
  };
57
- return text.replace(/[&<>"']/g, match => escaped[match] ?? match);
57
+ return text.replace(/&nbsp;/g, 'TMP_NON_BREAKING_SPACE').replace(/[&<>"']/g, match => escaped[match] ?? match).replace(/TMP_NON_BREAKING_SPACE/g, '&nbsp;');
58
58
  };
59
59
  export const convertEmojisToUnicode = text => {
60
60
  let result = text;
@@ -1 +1 @@
1
- {"version":3,"file":"emoji.js","names":["emojiList","asciiList","regAscii","regShortnames","shortNameList","convert","unicode","indexOf","parts","s","split","i","length","part","parseInt","hi","Math","floor","lo","String","fromCharCode","push","join","unescapeHTML","text","unescaped","replace","match","escapeHTML","escaped","convertEmojisToUnicode","result","fullMatch","shortname","toUpperCase","m1","m2","m3","addSkinToneToEmoji","emoji","skinTone","map","rawEmoji","skin_tone_support"],"sources":["../../src/utils/emoji.ts"],"sourcesContent":["import emojiList from 'unicode-emoji-json/data-by-emoji.json';\nimport { asciiList, regAscii, regShortnames, shortNameList } from '../constants/emoji';\n\nconst convert = (unicode: string) => {\n if (unicode.indexOf('-') > -1) {\n const parts = [];\n\n const s = unicode.split('-');\n\n for (let i = 0; i < s.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n let part: number | string = parseInt(s[i]!, 16);\n\n if (part >= 0x10000 && part <= 0x10ffff) {\n const hi = Math.floor((part - 0x10000) / 0x400) + 0xd800;\n const lo = ((part - 0x10000) % 0x400) + 0xdc00;\n\n part = String.fromCharCode(hi) + String.fromCharCode(lo);\n } else {\n part = String.fromCharCode(part);\n }\n\n parts.push(part);\n }\n\n return parts.join('');\n }\n\n const s = parseInt(unicode, 16);\n\n if (s >= 0x10000 && s <= 0x10ffff) {\n const hi = Math.floor((s - 0x10000) / 0x400) + 0xd800;\n const lo = ((s - 0x10000) % 0x400) + 0xdc00;\n\n return String.fromCharCode(hi) + String.fromCharCode(lo);\n }\n\n return String.fromCharCode(s);\n};\n\nexport const unescapeHTML = (text: string) => {\n const unescaped: { [key: string]: string } = {\n '&amp;': '&',\n '&#38;': '&',\n '&#x26;': '&',\n '&lt;': '<',\n '&#60;': '<',\n '&#x3C;': '<',\n '&gt;': '>',\n '&#62;': '>',\n '&#x3E;': '>',\n '&quot;': '\"',\n '&#34;': '\"',\n '&#x22;': '\"',\n '&apos;': \"'\",\n '&#39;': \"'\",\n '&#x27;': \"'\",\n };\n\n return text.replace(\n /&(?:amp|#38|#x26|lt|#60|#x3C|gt|#62|#x3E|apos|#39|#x27|quot|#34|#x22);/gi,\n (match) => unescaped[match] ?? match,\n );\n};\n\nexport const escapeHTML = (text: string) => {\n const escaped: { [key: string]: string } = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n \"'\": '&apos;',\n };\n\n return text.replace(/[&<>\"']/g, (match) => escaped[match] ?? match);\n};\n\nexport const convertEmojisToUnicode = (text: string): string => {\n let result = text;\n\n result = result.replace(/https?:\\/\\/.*?(?=$|\\s)/gi, (fullMatch) =>\n fullMatch.replace(/:/g, '%3A'),\n );\n\n result = result.replace(regShortnames, (shortname) => {\n if (shortname) {\n const unicode = shortNameList[shortname];\n\n if (unicode) {\n return convert(unicode.toUpperCase());\n }\n }\n\n return shortname;\n });\n\n result = result.replace(/https?%3A\\/\\/.*?(?=$|\\s)/gi, (fullMatch) =>\n fullMatch.replace(/%3A/g, ':'),\n );\n\n result = result.replace(regAscii, (fullMatch, m1, m2, m3) => {\n if (typeof m3 === 'string' && m3 !== '') {\n const unicode = asciiList[unescapeHTML(m3)];\n\n if (unicode) {\n return (m2 as string) + convert(unicode.toUpperCase());\n }\n }\n\n return fullMatch;\n });\n\n return result;\n};\n\nexport const addSkinToneToEmoji = (emoji: string, skinTone: string): string =>\n emoji\n .split('\\u{200D}')\n .map((rawEmoji) => {\n const parts = [rawEmoji.replace(/\\ufe0f/, '')];\n\n // @ts-expect-error: Difficult to type external json file\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (emojiList[rawEmoji]?.skin_tone_support) {\n parts.push(skinTone);\n }\n\n return parts.join('');\n })\n .join('\\u{200D}');\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,uCAAuC;AAC7D,SAASC,SAAS,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,aAAa,QAAQ,oBAAoB;AAEtF,MAAMC,OAAO,GAAIC,OAAe,IAAK;EACjC,IAAIA,OAAO,CAACC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;IAC3B,MAAMC,KAAK,GAAG,EAAE;IAEhB,MAAMC,CAAC,GAAGH,OAAO,CAACI,KAAK,CAAC,GAAG,CAAC;IAE5B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,CAAC,CAACG,MAAM,EAAED,CAAC,EAAE,EAAE;MAC/B;MACA,IAAIE,IAAqB,GAAGC,QAAQ,CAACL,CAAC,CAACE,CAAC,CAAC,EAAG,EAAE,CAAC;MAE/C,IAAIE,IAAI,IAAI,OAAO,IAAIA,IAAI,IAAI,QAAQ,EAAE;QACrC,MAAME,EAAE,GAAGC,IAAI,CAACC,KAAK,CAAC,CAACJ,IAAI,GAAG,OAAO,IAAI,KAAK,CAAC,GAAG,MAAM;QACxD,MAAMK,EAAE,GAAI,CAACL,IAAI,GAAG,OAAO,IAAI,KAAK,GAAI,MAAM;QAE9CA,IAAI,GAAGM,MAAM,CAACC,YAAY,CAACL,EAAE,CAAC,GAAGI,MAAM,CAACC,YAAY,CAACF,EAAE,CAAC;MAC5D,CAAC,MAAM;QACHL,IAAI,GAAGM,MAAM,CAACC,YAAY,CAACP,IAAI,CAAC;MACpC;MAEAL,KAAK,CAACa,IAAI,CAACR,IAAI,CAAC;IACpB;IAEA,OAAOL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,MAAMO,kBAAkB,GAAGA,CAACC,KAAa,EAAEC,QAAgB,KAC9DD,KAAK,CACA7B,KAAK,CAAC,UAAU,CAAC,CACjB+B,GAAG,CAAEC,QAAQ,IAAK;EACf,MAAMlC,KAAK,GAAG,CAACkC,QAAQ,CAAChB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;;EAE9C;EACA;EACA,IAAI1B,SAAS,CAAC0C,QAAQ,CAAC,EAAEC,iBAAiB,EAAE;IACxCnC,KAAK,CAACa,IAAI,CAACmB,QAAQ,CAAC;EACxB;EAEA,OAAOhC,KAAK,CAACc,IAAI,CAAC,EAAE,CAAC;AACzB,CAAC,CAAC,CACDA,IAAI,CAAC,UAAU,CAAC"}
1
+ {"version":3,"file":"emoji.js","names":["emojiList","asciiList","regAscii","regShortnames","shortNameList","convert","unicode","indexOf","parts","s","split","i","length","part","parseInt","hi","Math","floor","lo","String","fromCharCode","push","join","unescapeHTML","text","unescaped","replace","match","escapeHTML","escaped","convertEmojisToUnicode","result","fullMatch","shortname","toUpperCase","m1","m2","m3","addSkinToneToEmoji","emoji","skinTone","map","rawEmoji","skin_tone_support"],"sources":["../../src/utils/emoji.ts"],"sourcesContent":["import emojiList from 'unicode-emoji-json/data-by-emoji.json';\nimport { asciiList, regAscii, regShortnames, shortNameList } from '../constants/emoji';\n\nconst convert = (unicode: string) => {\n if (unicode.indexOf('-') > -1) {\n const parts = [];\n\n const s = unicode.split('-');\n\n for (let i = 0; i < s.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n let part: number | string = parseInt(s[i]!, 16);\n\n if (part >= 0x10000 && part <= 0x10ffff) {\n const hi = Math.floor((part - 0x10000) / 0x400) + 0xd800;\n const lo = ((part - 0x10000) % 0x400) + 0xdc00;\n\n part = String.fromCharCode(hi) + String.fromCharCode(lo);\n } else {\n part = String.fromCharCode(part);\n }\n\n parts.push(part);\n }\n\n return parts.join('');\n }\n\n const s = parseInt(unicode, 16);\n\n if (s >= 0x10000 && s <= 0x10ffff) {\n const hi = Math.floor((s - 0x10000) / 0x400) + 0xd800;\n const lo = ((s - 0x10000) % 0x400) + 0xdc00;\n\n return String.fromCharCode(hi) + String.fromCharCode(lo);\n }\n\n return String.fromCharCode(s);\n};\n\nexport const unescapeHTML = (text: string) => {\n const unescaped: { [key: string]: string } = {\n '&amp;': '&',\n '&#38;': '&',\n '&#x26;': '&',\n '&lt;': '<',\n '&#60;': '<',\n '&#x3C;': '<',\n '&gt;': '>',\n '&#62;': '>',\n '&#x3E;': '>',\n '&quot;': '\"',\n '&#34;': '\"',\n '&#x22;': '\"',\n '&apos;': \"'\",\n '&#39;': \"'\",\n '&#x27;': \"'\",\n };\n\n return text.replace(\n /&(?:amp|#38|#x26|lt|#60|#x3C|gt|#62|#x3E|apos|#39|#x27|quot|#34|#x22);/gi,\n (match) => unescaped[match] ?? match,\n );\n};\n\nexport const escapeHTML = (text: string) => {\n const escaped: { [key: string]: string } = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n \"'\": '&apos;',\n };\n\n return text\n .replace(/&nbsp;/g, 'TMP_NON_BREAKING_SPACE')\n .replace(/[&<>\"']/g, (match) => escaped[match] ?? match)\n .replace(/TMP_NON_BREAKING_SPACE/g, '&nbsp;');\n};\n\nexport const convertEmojisToUnicode = (text: string): string => {\n let result = text;\n\n result = result.replace(/https?:\\/\\/.*?(?=$|\\s)/gi, (fullMatch) =>\n fullMatch.replace(/:/g, '%3A'),\n );\n\n result = result.replace(regShortnames, (shortname) => {\n if (shortname) {\n const unicode = shortNameList[shortname];\n\n if (unicode) {\n return convert(unicode.toUpperCase());\n }\n }\n\n return shortname;\n });\n\n result = result.replace(/https?%3A\\/\\/.*?(?=$|\\s)/gi, (fullMatch) =>\n fullMatch.replace(/%3A/g, ':'),\n );\n\n result = result.replace(regAscii, (fullMatch, m1, m2, m3) => {\n if (typeof m3 === 'string' && m3 !== '') {\n const unicode = asciiList[unescapeHTML(m3)];\n\n if (unicode) {\n return (m2 as string) + convert(unicode.toUpperCase());\n }\n }\n\n return fullMatch;\n });\n\n return result;\n};\n\nexport const addSkinToneToEmoji = (emoji: string, skinTone: string): string =>\n emoji\n .split('\\u{200D}')\n .map((rawEmoji) => {\n const parts = [rawEmoji.replace(/\\ufe0f/, '')];\n\n // @ts-expect-error: Difficult to type external json file\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n if (emojiList[rawEmoji]?.skin_tone_support) {\n parts.push(skinTone);\n }\n\n return parts.join('');\n })\n .join('\\u{200D}');\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,uCAAuC;AAC7D,SAASC,SAAS,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,aAAa,QAAQ,oBAAoB;AAEtF,MAAMC,OAAO,GAAIC,OAAe,IAAK;EACjC,IAAIA,OAAO,CAACC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;IAC3B,MAAMC,KAAK,GAAG,EAAE;IAEhB,MAAMC,CAAC,GAAGH,OAAO,CAACI,KAAK,CAAC,GAAG,CAAC;IAE5B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,CAAC,CAACG,MAAM,EAAED,CAAC,EAAE,EAAE;MAC/B;MACA,IAAIE,IAAqB,GAAGC,QAAQ,CAACL,CAAC,CAACE,CAAC,CAAC,EAAG,EAAE,CAAC;MAE/C,IAAIE,IAAI,IAAI,OAAO,IAAIA,IAAI,IAAI,QAAQ,EAAE;QACrC,MAAME,EAAE,GAAGC,IAAI,CAACC,KAAK,CAAC,CAACJ,IAAI,GAAG,OAAO,IAAI,KAAK,CAAC,GAAG,MAAM;QACxD,MAAMK,EAAE,GAAI,CAACL,IAAI,GAAG,OAAO,IAAI,KAAK,GAAI,MAAM;QAE9CA,IAAI,GAAGM,MAAM,CAACC,YAAY,CAACL,EAAE,CAAC,GAAGI,MAAM,CAACC,YAAY,CAACF,EAAE,CAAC;MAC5D,CAAC,MAAM;QACH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E,CAAC,CAAC;MAE3C,IAAI/B,OAAO,EAAE;QACT,OAAQ8B,EAAE,GAAc/B,OAAO,CAACC,OAAO,CAAC4B,WAAW,CAAC,CAAC,CAAC;MAC1D;IACJ;IAEA,OAAOF,SAAS;EACpB,CAAC,CAAC;EAEF,OAAOD,MAAM;AACjB,CAAC;AAED,OAAO,MAAMO,kBAAkB,GAAGA,CAACC,KAAa,EAAEC,QAAgB,KAC9DD,KAAK,CACA7B,KAAK,CAAC,UAAU,CAAC,CACjB+B,GAAG,CAAEC,QAAQ,IAAK;EACf,MAAMlC,KAAK,GAAG,CAACkC,QAAQ,CAAChB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;;EAE9C;EACA;EACA,IAAI1B,SAAS,CAAC0C,QAAQ,CAAC,EAAEC,iBAAiB,EAAE;IACxCnC,KAAK,CAACa,IAAI,CAACmB,QAAQ,CAAC;EACxB;EAEA,OAAOhC,KAAK,CAACc,IAAI,CAAC,EAAE,CAAC;AACzB,CAAC,CAAC,CACDA,IAAI,CAAC,UAAU,CAAC"}
@@ -76,7 +76,6 @@ export const replaceText = _ref2 => {
76
76
  pasteText
77
77
  } = _ref2;
78
78
  const selection = window.getSelection();
79
- saveSelection(editorElement);
80
79
  const rangeToReplace = findAndSelectText({
81
80
  editorElement,
82
81
  searchText
@@ -84,9 +83,10 @@ export const replaceText = _ref2 => {
84
83
  if (rangeToReplace && selection) {
85
84
  selection.removeAllRanges();
86
85
  selection.addRange(rangeToReplace);
87
- rangeToReplace.deleteContents();
88
- rangeToReplace.insertNode(document.createTextNode(pasteText));
89
- restoreSelection(editorElement);
86
+ insertTextAtCursorPosition({
87
+ editorElement,
88
+ text: pasteText
89
+ });
90
90
  }
91
91
  };
92
92
  //# sourceMappingURL=insert.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"insert.js","names":["findAndSelectText","moveSelectionOffset","restoreSelection","saveSelection","setChildIndex","insertTextAtCursorPosition","_ref","editorElement","text","selection","window","getSelection","anchorNode","contains","range","getRangeAt","parts","split","firstPart","shift","textNodes","map","part","document","createTextNode","deleteContents","nodeType","Node","TEXT_NODE","nodeValue","slice","startOffset","length","textNode","appendChild","textNodeIndex","Array","from","childNodes","indexOf","brElement","createElement","insertNode","setEndAfter","setStartAfter","forEach","index","collapse","removeAllRanges","addRange","innerText","replaceText","_ref2","searchText","pasteText","rangeToReplace"],"sources":["../../src/utils/insert.ts"],"sourcesContent":["import {\n findAndSelectText,\n moveSelectionOffset,\n restoreSelection,\n saveSelection,\n setChildIndex,\n} from './selection';\n\ninterface InsertTextAtCursorPositionOptions {\n editorElement: HTMLDivElement;\n text: string;\n}\n\n/**\n * This function inserts the passed text at the correct position in the editor element. If the\n * element has the focus, the new emoji is inserted at the cursor position. If not, the emoji\n * will be appended to the back of the input field content.\n *\n * In addition, this function also sets the cursor to the correct position when the input field\n * has the focus. For this purpose, the current position of the cursor or a selection is read to\n * calculate the cursor position after inserting the text.\n *\n * @param {Object} options - Object with element and text to insert\n * @param {HTMLDivElement} options.editorElement - Element to insert text into\n * @param {string} options.text - Text to insert into element\n */\nexport const insertTextAtCursorPosition = ({\n editorElement,\n text,\n}: InsertTextAtCursorPositionOptions) => {\n const selection = window.getSelection();\n\n saveSelection(editorElement);\n\n if (selection?.anchorNode && editorElement.contains(selection.anchorNode)) {\n let range = selection.getRangeAt(0);\n\n const parts = text.split(/\\r\\n|\\r|\\n/);\n\n const firstPart = parts.shift();\n\n const textNodes = parts.map((part) => document.createTextNode(part));\n\n range.deleteContents();\n\n if (firstPart) {\n if (selection.anchorNode.nodeType === Node.TEXT_NODE) {\n const { nodeValue } = selection.anchorNode;\n\n if (typeof nodeValue === 'string') {\n selection.anchorNode.nodeValue =\n nodeValue.slice(0, range.startOffset) +\n firstPart +\n nodeValue.slice(range.startOffset);\n\n moveSelectionOffset(firstPart.length);\n }\n } else if (selection.anchorNode === editorElement) {\n const textNode = document.createTextNode(firstPart);\n\n editorElement.appendChild(textNode);\n\n const textNodeIndex = Array.from(editorElement.childNodes).indexOf(textNode);\n\n moveSelectionOffset(firstPart.length);\n setChildIndex(textNodeIndex);\n }\n }\n\n restoreSelection(editorElement);\n\n if (textNodes.length > 0) {\n range = selection.getRangeAt(0);\n\n let brElement = document.createElement('br');\n\n range.insertNode(brElement);\n range.setEndAfter(brElement);\n range.setStartAfter(brElement);\n\n textNodes.forEach((textNode, index) => {\n range.insertNode(textNode);\n range.setEndAfter(textNode);\n range.setStartAfter(textNode);\n\n if (index !== textNodes.length - 1) {\n brElement = document.createElement('br');\n\n range.insertNode(brElement);\n range.setEndAfter(brElement);\n range.setStartAfter(brElement);\n }\n });\n\n range.collapse(false);\n\n selection.removeAllRanges();\n selection.addRange(range);\n }\n } else {\n // eslint-disable-next-line no-param-reassign\n editorElement.innerText += text;\n }\n};\n\nexport interface ReplaceTextOptions {\n editorElement: HTMLDivElement;\n searchText: string;\n pasteText: string;\n}\n\nexport const replaceText = ({ editorElement, searchText, pasteText }: ReplaceTextOptions) => {\n const selection = window.getSelection();\n\n saveSelection(editorElement);\n\n const rangeToReplace = findAndSelectText({ editorElement, searchText });\n\n if (rangeToReplace && selection) {\n selection.removeAllRanges();\n selection.addRange(rangeToReplace);\n\n rangeToReplace.deleteContents();\n\n rangeToReplace.insertNode(document.createTextNode(pasteText));\n\n restoreSelection(editorElement);\n }\n};\n"],"mappings":"AAAA,SACIA,iBAAiB,EACjBC,mBAAmB,EACnBC,gBAAgB,EAChBC,aAAa,EACbC,aAAa,QACV,aAAa;AAOpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,0BAA0B,GAAGC,IAAA,IAGD;EAAA,IAHE;IACvCC,aAAa;IACbC;EAC+B,CAAC,GAAAF,IAAA;EAChC,MAAMG,SAAS,GAAGC,MAAM,CAACC,YAAY,CAAC,CAAC;EAEvCR,aAAa,CAACI,aAAa,CAAC;EAE5B,IAAIE,SAAS,EAAEG,UAAU,IAAIL,aAAa,CAAC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AAY,CAAC,CAAC;EAEvCR,aAAa,CAACI,aAAa,CAAC;EAE5B,MAAMgD,cAAc,GAAGvD,iBAAiB,CAAC;IAAEO,aAAa;IAAE8C;EAAW,CAAC,CAAC;EAEvE,IAAIE,cAAc,IAAI9C,SAAS,EAAE;IAC7BA,SAAS,CAACuC,eAAe,CAAC,CAAC;IAC3BvC,SAAS,CAACwC,QAAQ,CAACM,cAAc,CAAC;IAElCA,cAAc,CAAC9B,cAAc,CAAC,CAAC;IAE/B8B,cAAc,CAACb,UAAU,CAACnB,QAAQ,CAACC,cAAc,CAAC8B,SAAS,CAAC,CAAC;IAE7DpD,gBAAgB,CAACK,aAAa,CAAC;EACnC;AACJ,CAAC"}
1
+ {"version":3,"file":"insert.js","names":["findAndSelectText","moveSelectionOffset","restoreSelection","saveSelection","setChildIndex","insertTextAtCursorPosition","_ref","editorElement","text","selection","window","getSelection","anchorNode","contains","range","getRangeAt","parts","split","firstPart","shift","textNodes","map","part","document","createTextNode","deleteContents","nodeType","Node","TEXT_NODE","nodeValue","slice","startOffset","length","textNode","appendChild","textNodeIndex","Array","from","childNodes","indexOf","brElement","createElement","insertNode","setEndAfter","setStartAfter","forEach","index","collapse","removeAllRanges","addRange","innerText","replaceText","_ref2","searchText","pasteText","rangeToReplace"],"sources":["../../src/utils/insert.ts"],"sourcesContent":["import {\n findAndSelectText,\n moveSelectionOffset,\n restoreSelection,\n saveSelection,\n setChildIndex,\n} from './selection';\n\ninterface InsertTextAtCursorPositionOptions {\n editorElement: HTMLDivElement;\n text: string;\n}\n\n/**\n * This function inserts the passed text at the correct position in the editor element. If the\n * element has the focus, the new emoji is inserted at the cursor position. If not, the emoji\n * will be appended to the back of the input field content.\n *\n * In addition, this function also sets the cursor to the correct position when the input field\n * has the focus. For this purpose, the current position of the cursor or a selection is read to\n * calculate the cursor position after inserting the text.\n *\n * @param {Object} options - Object with element and text to insert\n * @param {HTMLDivElement} options.editorElement - Element to insert text into\n * @param {string} options.text - Text to insert into element\n */\nexport const insertTextAtCursorPosition = ({\n editorElement,\n text,\n}: InsertTextAtCursorPositionOptions) => {\n const selection = window.getSelection();\n\n saveSelection(editorElement);\n\n if (selection?.anchorNode && editorElement.contains(selection.anchorNode)) {\n let range = selection.getRangeAt(0);\n\n const parts = text.split(/\\r\\n|\\r|\\n/);\n\n const firstPart = parts.shift();\n\n const textNodes = parts.map((part) => document.createTextNode(part));\n\n range.deleteContents();\n\n if (firstPart) {\n if (selection.anchorNode.nodeType === Node.TEXT_NODE) {\n const { nodeValue } = selection.anchorNode;\n\n if (typeof nodeValue === 'string') {\n selection.anchorNode.nodeValue =\n nodeValue.slice(0, range.startOffset) +\n firstPart +\n nodeValue.slice(range.startOffset);\n\n moveSelectionOffset(firstPart.length);\n }\n } else if (selection.anchorNode === editorElement) {\n const textNode = document.createTextNode(firstPart);\n\n editorElement.appendChild(textNode);\n\n const textNodeIndex = Array.from(editorElement.childNodes).indexOf(textNode);\n\n moveSelectionOffset(firstPart.length);\n setChildIndex(textNodeIndex);\n }\n }\n\n restoreSelection(editorElement);\n\n if (textNodes.length > 0) {\n range = selection.getRangeAt(0);\n\n let brElement = document.createElement('br');\n\n range.insertNode(brElement);\n range.setEndAfter(brElement);\n range.setStartAfter(brElement);\n\n textNodes.forEach((textNode, index) => {\n range.insertNode(textNode);\n range.setEndAfter(textNode);\n range.setStartAfter(textNode);\n\n if (index !== textNodes.length - 1) {\n brElement = document.createElement('br');\n\n range.insertNode(brElement);\n range.setEndAfter(brElement);\n range.setStartAfter(brElement);\n }\n });\n\n range.collapse(false);\n\n selection.removeAllRanges();\n selection.addRange(range);\n }\n } else {\n // eslint-disable-next-line no-param-reassign\n editorElement.innerText += text;\n }\n};\n\nexport interface ReplaceTextOptions {\n editorElement: HTMLDivElement;\n searchText: string;\n pasteText: string;\n}\n\nexport const replaceText = ({ editorElement, searchText, pasteText }: ReplaceTextOptions) => {\n const selection = window.getSelection();\n\n const rangeToReplace = findAndSelectText({ editorElement, searchText });\n\n if (rangeToReplace && selection) {\n selection.removeAllRanges();\n selection.addRange(rangeToReplace);\n\n insertTextAtCursorPosition({ editorElement, text: pasteText });\n }\n};\n"],"mappings":"AAAA,SACIA,iBAAiB,EACjBC,mBAAmB,EACnBC,gBAAgB,EAChBC,aAAa,EACbC,aAAa,QACV,aAAa;AAOpB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,0BAA0B,GAAGC,IAAA,IAGD;EAAA,IAHE;IACvCC,aAAa;IACbC;EAC+B,CAAC,GAAAF,IAAA;EAChC,MAAMG,SAAS,GAAGC,MAAM,CAACC,YAAY,CAAC,CAAC;EAEvCR,aAAa,CAACI,aAAa,CAAC;EAE5B,IAAIE,SAAS,EAAEG,UAAU,IAAIL,aAAa,CAACM,QAAQ,CAACJ,SAAS,CAACG,UAAU,CAAC,EAAE;IACvE,IAAIE,KAAK,GAAGL,SAAS,CAACM,UAAU,CAAC,CAAC,CAAC;IAEnC,MAAMC,KAAK,GAAGR,IAAI,CAACS,KAAK,CAAC,YAAY,CAAC;IAEtC,MAAMC,SAAS,GAAGF,KAAK,CAACG,KAAK,CAAC,CAAC;IAE/B,MAAMC,SAAS,GAAGJ,KAAK,CAACK,GAAG,CAAEC,IAAI,IAAKC,QAAQ,CAACC,cAAc,CAACF,IAAI,CAAC,CAAC;IAEpER,KAAK,CAACW,cAAc,CAAC,CAAC;IAEtB,IAAIP,SAAS,EAAE;MACX,IAAIT,SAAS,CAACG,UAAU,CAACc,QAAQ,KAAKC,IAAI,CAACC,SAAS,EAAE;QAClD,MAAM;UAAEC;QAAU,CAAC,GAAGpB,SAAS,CAACG,UAAU;QAE1C,IAAI,OAAOiB,SAAS,KAAK,QAAQ,EAAE;UAC/BpB,SAAS,CAACG,UAAU,CAACiB,SAAS,GAC1BA,SAAS,CAACC,KAAK,CAAC,CAAC,EAAEhB,KAAK,CAACiB,WAAW,CAAC,GACrCb,SAAS,GACTW,SAAS,CAACC,KAAK,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K,CAAC6B,WAAW,CAACH,SAAS,CAAC;UAC5B1B,KAAK,CAAC8B,aAAa,CAACJ,SAAS,CAAC;QAClC;MACJ,CAAC,CAAC;MAEF1B,KAAK,CAACiC,QAAQ,CAAC,KAAK,CAAC;MAErBtC,SAAS,CAACuC,eAAe,CAAC,CAAC;MAC3BvC,SAAS,CAACwC,QAAQ,CAACnC,KAAK,CAAC;IAC7B;EACJ,CAAC,MAAM;IACH;IACAP,aAAa,CAAC2C,SAAS,IAAI1C,IAAI;EACnC;AACJ,CAAC;AAQD,OAAO,MAAM2C,WAAW,GAAGC,KAAA,IAAkE;EAAA,IAAjE;IAAE7C,aAAa;IAAE8C,UAAU;IAAEC;EAA8B,CAAC,GAAAF,KAAA;EACpF,MAAM3C,SAAS,GAAGC,MAAM,CAACC,YAAY,CAAC,CAAC;EAEvC,MAAM4C,cAAc,GAAGvD,iBAAiB,CAAC;IAAEO,aAAa;IAAE8C;EAAW,CAAC,CAAC;EAEvE,IAAIE,cAAc,IAAI9C,SAAS,EAAE;IAC7BA,SAAS,CAACuC,eAAe,CAAC,CAAC;IAC3BvC,SAAS,CAACwC,QAAQ,CAACM,cAAc,CAAC;IAElClD,0BAA0B,CAAC;MAAEE,aAAa;MAAEC,IAAI,EAAE8C;IAAU,CAAC,CAAC;EAClE;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/emoji-input",
3
- "version": "5.0.0-beta.499",
3
+ "version": "5.0.0-beta.501",
4
4
  "description": "Input field that supports HTML elements and emojis",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -74,5 +74,5 @@
74
74
  "publishConfig": {
75
75
  "access": "public"
76
76
  },
77
- "gitHead": "aa6a94472c8971571f4289c3c7077cac905c23ee"
77
+ "gitHead": "c464236a285cee96bd9a4ce3fa3af56bead3a8b4"
78
78
  }