@pushwoosh/dumb-components 1.0.50 → 1.0.52

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, useClickAway } from '@pushwoosh/kit-helpers';
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,21 @@ export const RichMessageEditor = ({
62
63
  Transforms.select(editor, editor.selection);
63
64
  onSelectionChange(editor.selection);
64
65
  };
65
- useClickAway(true, rootRef, () => {
66
+ const clickAwayHandler = usePersistentFunction(() => {
66
67
  setShowDrop(undefined);
67
68
  setIsFocused(false);
69
+ onBlur === null || onBlur === void 0 || onBlur();
68
70
  });
71
+ useEffect(() => {
72
+ if (!isFocused) {
73
+ return;
74
+ }
75
+ return elementAddListener(document, ['mousedown', 'touchstart', 'focusin'], event => {
76
+ if (rootRef.current && !rootRef.current.contains(event.target)) {
77
+ clickAwayHandler();
78
+ }
79
+ });
80
+ }, [clickAwayHandler, isFocused]);
69
81
  return React.createElement(SlateEditor, {
70
82
  initialValue: initialValue,
71
83
  onChange: onChange,
@@ -20,6 +20,7 @@ export type RichMessageEditorProps = {
20
20
  error?: ReactNode;
21
21
  canUsePersonalization?: boolean;
22
22
  canUseEmoji?: boolean;
23
+ onBlur?: () => void;
23
24
  renderDynamicContent?: (props: {
24
25
  dc: DynamicContent;
25
26
  onChange: (newDC: DynamicContent) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.0.50",
3
+ "version": "1.0.52",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",