@pushwoosh/dumb-components 1.1.8 → 1.1.10

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,14 +1,35 @@
1
- import Picker from '@emoji-mart/react';
2
- import React from 'react';
1
+ import { Picker } from 'emoji-mart';
2
+ import React, { useEffect, useRef } from 'react';
3
3
  import { EmojiPickerStyled } from './EmojiPicker.styled';
4
4
  async function data() {
5
5
  const response = await fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data');
6
6
  return response.json();
7
7
  }
8
+ function PickerBase(props) {
9
+ const ref = useRef(null);
10
+ const instance = useRef(null);
11
+ if (instance.current) {
12
+ instance.current.update(props);
13
+ }
14
+ useEffect(() => {
15
+ var _window;
16
+ const PickerElement = (_window = window) === null || _window === void 0 ? void 0 : _window.customElements.get('em-emoji-picker');
17
+ instance.current = new (PickerElement || Picker)({
18
+ ...props,
19
+ ref
20
+ });
21
+ return () => {
22
+ instance.current = null;
23
+ };
24
+ }, [props]);
25
+ return React.createElement('div', {
26
+ ref
27
+ });
28
+ }
8
29
  export const EmojiPicker = ({
9
30
  onEmojiSelect
10
31
  }) => {
11
- return React.createElement(EmojiPickerStyled, null, React.createElement(Picker, {
32
+ return React.createElement(EmojiPickerStyled, null, React.createElement(PickerBase, {
12
33
  data: data,
13
34
  onEmojiSelect: emoji => {
14
35
  onEmojiSelect(emoji.native);
@@ -67,9 +67,12 @@ export const RichMessageEditor = ({
67
67
  Transforms.move(editor);
68
68
  setShowDrop(undefined);
69
69
  };
70
- const clickAwayHandler = usePersistentFunction(() => {
70
+ const onClose = () => {
71
71
  setShowDrop(undefined);
72
72
  setIsFocused(false);
73
+ };
74
+ const clickAwayHandler = usePersistentFunction(() => {
75
+ onClose();
73
76
  onBlur === null || onBlur === void 0 || onBlur();
74
77
  });
75
78
  useEffect(() => {
@@ -138,6 +141,7 @@ export const RichMessageEditor = ({
138
141
  insertDynamicContent(editor, newDC);
139
142
  }
140
143
  },
144
+ onClose,
141
145
  update
142
146
  })), showDrop.type === 'emoji' && React.createElement(EmojiPicker, {
143
147
  onEmojiSelect: s => editor.insertText(s)
@@ -11,6 +11,7 @@ export type DropValue = DropValueEmoji | DropValuePersonalization;
11
11
  export type RenderDynamicContentProps = {
12
12
  dc?: DynamicContent;
13
13
  onChange: (newDC: DynamicContent) => void;
14
+ onClose: () => void;
14
15
  update: () => void;
15
16
  };
16
17
  export type RichMessageEditorProps = {
@@ -1,3 +1,4 @@
1
1
  export { type RichMessageEditorContent } from './types';
2
2
  export { RichMessageEditor } from './RichMessageEditor';
3
3
  export { RichMessageViewer } from './RichMessageViewer';
4
+ export { type DynamicContent } from './slate/types';
package/index.d.ts CHANGED
@@ -36,4 +36,4 @@ export { NumberPicker } from './NumberPicker';
36
36
  export { CodeEditor } from './CodeEditor';
37
37
  export { EnhancedInput, SearchInput } from './EnhancedInput';
38
38
  export { Chip } from './Chip';
39
- export { RichMessageEditor, RichMessageViewer } from './RichMessageEditor';
39
+ export { RichMessageEditor, RichMessageViewer, type DynamicContent } from './RichMessageEditor';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",