@pushwoosh/dumb-components 1.0.50 → 1.0.51
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isEqual } from 'es-toolkit';
|
|
2
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { Transforms } from 'slate';
|
|
4
|
-
import { Collapse, Horizontal,
|
|
4
|
+
import { Collapse, elementAddListener, Horizontal, usePersistentFunction } from '@pushwoosh/kit-helpers';
|
|
5
5
|
import { FieldBox } from '../FieldBox';
|
|
6
6
|
import EmojiIcon from './assets/EmojiIcon.svg';
|
|
7
7
|
import PersonalizationIcon from './assets/PersonalizationIcon.svg';
|
|
@@ -18,6 +18,7 @@ export const RichMessageEditor = ({
|
|
|
18
18
|
canUsePersonalization,
|
|
19
19
|
canUseEmoji,
|
|
20
20
|
onChange,
|
|
21
|
+
onBlur,
|
|
21
22
|
renderDynamicContent
|
|
22
23
|
}) => {
|
|
23
24
|
const rootRef = useRef(null);
|
|
@@ -62,10 +63,18 @@ export const RichMessageEditor = ({
|
|
|
62
63
|
Transforms.select(editor, editor.selection);
|
|
63
64
|
onSelectionChange(editor.selection);
|
|
64
65
|
};
|
|
65
|
-
|
|
66
|
+
const clickAwayHandler = usePersistentFunction(() => {
|
|
66
67
|
setShowDrop(undefined);
|
|
67
68
|
setIsFocused(false);
|
|
69
|
+
onBlur === null || onBlur === void 0 || onBlur();
|
|
68
70
|
});
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
return elementAddListener(document, ['mousedown', 'touchstart', 'focusin'], event => {
|
|
73
|
+
if (rootRef.current && !rootRef.current.contains(event.target)) {
|
|
74
|
+
clickAwayHandler();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}, [clickAwayHandler]);
|
|
69
78
|
return React.createElement(SlateEditor, {
|
|
70
79
|
initialValue: initialValue,
|
|
71
80
|
onChange: onChange,
|