+
+
-
+
);
diff --git a/src/components/Widget/components/Conversation/style.scss b/src/components/Widget/components/Conversation/style.scss
index a6300eb37..b0138aeac 100644
--- a/src/components/Widget/components/Conversation/style.scss
+++ b/src/components/Widget/components/Conversation/style.scss
@@ -1,6 +1,7 @@
@import 'common';
@import 'variables/colors';
@import 'animation';
+@import "~emoji-mart/css/emoji-mart.css";
.rcw-conversation-container {
border-radius: 10px;
@@ -33,6 +34,10 @@
width: 5px;
}
+.emoji-mart-preview {
+ display: none;
+}
+
.rcw-full-screen {
.rcw-conversation-container {
@include conversation-container-fs;
diff --git a/src/components/Widget/index.tsx b/src/components/Widget/index.tsx
index 7fcecfb51..df7897557 100644
--- a/src/components/Widget/index.tsx
+++ b/src/components/Widget/index.tsx
@@ -31,6 +31,7 @@ type Props = {
zoomStep?: number;
handleSubmit?: AnyFunction;
resizable?: boolean;
+ emojis?: boolean;
}
function Widget({
@@ -58,6 +59,7 @@ function Widget({
zoomStep,
handleSubmit,
resizable,
+ emojis
}: Props) {
const dispatch = useDispatch();
@@ -106,6 +108,7 @@ function Widget({
imagePreview={imagePreview}
zoomStep={zoomStep}
resizable={resizable}
+ emojis={emojis}
/>
);
}
diff --git a/src/components/Widget/layout.tsx b/src/components/Widget/layout.tsx
index 958f94285..09911be4c 100644
--- a/src/components/Widget/layout.tsx
+++ b/src/components/Widget/layout.tsx
@@ -36,6 +36,7 @@ type Props = {
imagePreview?: boolean;
zoomStep?: number;
resizable?: boolean;
+ emojis?: boolean
}
function WidgetLayout({
@@ -62,6 +63,7 @@ function WidgetLayout({
imagePreview,
zoomStep,
resizable,
+ emojis
}: Props) {
const dispatch = useDispatch();
const { dissableInput, showChat, visible } = useSelector((state: GlobalState) => ({
@@ -139,6 +141,7 @@ function WidgetLayout({
sendButtonAlt={sendButtonAlt}
showTimeStamp={showTimeStamp}
resizable={resizable}
+ emojis={emojis}
/>
}
{customLauncher ?
diff --git a/src/index.tsx b/src/index.tsx
index 7d0a41ff3..9aaeb066e 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -29,6 +29,7 @@ type Props = {
showTimeStamp?: boolean;
imagePreview?: boolean;
zoomStep?: number;
+ emojis?: boolean;
handleSubmit?: AnyFunction;
resizable?: boolean;
} & typeof defaultProps;
@@ -58,6 +59,7 @@ function ConnectedWidget({
zoomStep,
handleSubmit,
resizable,
+ emojis
}: Props) {
return (
@@ -86,6 +88,7 @@ function ConnectedWidget({
zoomStep={zoomStep}
handleSubmit={handleSubmit}
resizable={resizable}
+ emojis={emojis}
/>
);
diff --git a/src/scss/_common.scss b/src/scss/_common.scss
index 92a1c0dad..279ee7afc 100644
--- a/src/scss/_common.scss
+++ b/src/scss/_common.scss
@@ -4,10 +4,6 @@
max-width: 215px;
padding: 15px;
text-align: left;
-
- > p {
- white-space: pre-wrap;
- }
}
// Full screen mixins
diff --git a/src/utils/contentEditable.ts b/src/utils/contentEditable.ts
new file mode 100644
index 000000000..dfc2dfe7c
--- /dev/null
+++ b/src/utils/contentEditable.ts
@@ -0,0 +1,67 @@
+export const getCaretIndex = (el) => {
+ let position = 0;
+ const selection = window.getSelection()!;
+ if (selection.rangeCount !== 0) {
+ const range = window.getSelection()!.getRangeAt(0);
+ const preCaretRange = range.cloneRange();
+ preCaretRange.selectNodeContents(el);
+ preCaretRange.setEnd(range.endContainer, range.endOffset);
+ position = preCaretRange.toString().length;
+ }
+ return position;
+}
+
+export const getSelection = (el) => {
+ const range = window.getSelection()!.getRangeAt(0);
+ const preSelectionRange = range.cloneRange();
+ preSelectionRange.selectNodeContents(el);
+ preSelectionRange.setEnd(range.startContainer, range.startOffset);
+
+ const start = preSelectionRange.toString().length;
+ return {
+ start: start,
+ end: start + range.toString().length
+ }
+}
+
+export const isFirefox = () => navigator.userAgent.search("Firefox") > 0;
+
+export const updateCaret = (el, caret, offset) => {
+ const range = document.createRange();
+ const selection = window.getSelection()!;
+ range.setStart(el.childNodes[0], caret+offset);
+ range.collapse(true);
+ selection.removeAllRanges();
+ selection.addRange(range);
+ el.focus();
+}
+
+export const insertNodeAtCaret = (el) => {
+ const position = getCaretIndex(el)
+ let characterToEnter = '\n\n';
+ let prevChar, char = '';
+ if (position > 0) {
+ prevChar = el.innerHTML.charAt(position - 1);
+ char = el.innerHTML.charAt(position);
+ const newLines = el.innerHTML.match(/\n/g);
+ if(
+ prevChar === char ||
+ (prevChar === '\n' && char === '') ||
+ (isFirefox() && newLines?.length > 0)
+ ) {
+ characterToEnter = '\n';
+ }
+ }
+ const selection = window.getSelection()!;
+ const node = document.createTextNode(characterToEnter);
+ const range = selection.getRangeAt(0);
+ range.collapse(false);
+ range.insertNode(node);
+ const cloneRange = range.cloneRange();
+ cloneRange.selectNodeContents(node);
+ cloneRange.collapse(false);
+ selection.removeAllRanges();
+ selection.addRange(cloneRange);
+ el.innerHTML = el.innerHTML.replace(/
/g, '');
+ updateCaret(el, position, 1);
+}