@pushwoosh/dumb-components 1.0.53 → 1.0.55

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.
@@ -47,21 +47,16 @@ export const RichMessageEditor = ({
47
47
  }
48
48
  }
49
49
  };
50
- const insertDynamicContent = editor => {
50
+ const insertDynamicContent = (editor, dc) => {
51
51
  const newDC = {
52
52
  type: 'dc',
53
- dc: {
54
- tagName: '',
55
- modifier: 'regular',
56
- defaultValue: ''
57
- },
53
+ dc,
58
54
  children: [{
59
55
  text: ''
60
56
  }]
61
57
  };
62
58
  Transforms.insertNodes(editor, newDC);
63
59
  Transforms.select(editor, editor.selection);
64
- onSelectionChange(editor.selection);
65
60
  };
66
61
  const clickAwayHandler = usePersistentFunction(() => {
67
62
  setShowDrop(undefined);
@@ -84,45 +79,54 @@ export const RichMessageEditor = ({
84
79
  onSelectionChange: onSelectionChange
85
80
  }, ({
86
81
  editor
87
- }) => React.createElement(FieldBox, {
88
- title: title,
89
- boxRef: rootRef,
90
- error: error,
91
- actions: React.createElement(Collapse, {
92
- expanded: isFocused
93
- }, React.createElement(Horizontal, {
94
- "$gap": 8
95
- }, canUsePersonalization && React.createElement(ImSpan, {
96
- onClick: () => insertDynamicContent(editor)
97
- }, React.createElement(PersonalizationIcon, null), "Personalization"), canUseEmoji && React.createElement(ImSpan, {
98
- onClick: () => showDropArea({
99
- type: 'emoji'
100
- })
101
- }, React.createElement(EmojiIcon, null), "Emoji")))
102
- }, React.createElement(SlateEditable, {
103
- minHeight: minHeight,
104
- onFocus: () => {
105
- setIsFocused(true);
106
- const {
107
- selection
108
- } = editor;
109
- if (selection) {
110
- onSelectionChange(selection);
82
+ }) => {
83
+ var _getDcByPath;
84
+ return React.createElement(FieldBox, {
85
+ title: title,
86
+ boxRef: rootRef,
87
+ error: error,
88
+ actions: React.createElement(Collapse, {
89
+ expanded: isFocused
90
+ }, React.createElement(Horizontal, {
91
+ "$gap": 8
92
+ }, canUsePersonalization && React.createElement(ImSpan, {
93
+ onClick: () => showDropArea({
94
+ type: 'personalization'
95
+ })
96
+ }, React.createElement(PersonalizationIcon, null), "Personalization"), canUseEmoji && React.createElement(ImSpan, {
97
+ onClick: () => showDropArea({
98
+ type: 'emoji'
99
+ })
100
+ }, React.createElement(EmojiIcon, null), "Emoji")))
101
+ }, React.createElement(SlateEditable, {
102
+ minHeight: minHeight,
103
+ onFocus: () => {
104
+ setIsFocused(true);
105
+ const {
106
+ selection
107
+ } = editor;
108
+ if (selection) {
109
+ onSelectionChange(selection);
110
+ }
111
111
  }
112
- }
113
- }), showDrop && React.createElement(DropContent, {
114
- top: showDrop.yValue,
115
- left: showDrop.xValue
116
- }, showDrop.type === 'personalization' && getDcByPath(editor.children, showDrop.path) && (renderDynamicContent === null || renderDynamicContent === void 0 ? void 0 : renderDynamicContent({
117
- dc: getDcByPath(editor.children, showDrop.path).dc,
118
- onChange: newDC => {
119
- Transforms.setNodes(editor, {
120
- dc: newDC
121
- }, {
122
- at: showDrop.path
123
- });
124
- }
125
- })), showDrop.type === 'emoji' && React.createElement(EmojiPicker, {
126
- onEmojiSelect: s => editor.insertText(s)
127
- }))));
112
+ }), showDrop && React.createElement(DropContent, {
113
+ top: showDrop.yValue,
114
+ left: showDrop.xValue
115
+ }, showDrop.type === 'personalization' && (renderDynamicContent === null || renderDynamicContent === void 0 ? void 0 : renderDynamicContent({
116
+ dc: showDrop.path ? (_getDcByPath = getDcByPath(editor.children, showDrop.path)) === null || _getDcByPath === void 0 ? void 0 : _getDcByPath.dc : undefined,
117
+ onChange: newDC => {
118
+ if (showDrop.path) {
119
+ Transforms.setNodes(editor, {
120
+ dc: newDC
121
+ }, {
122
+ at: showDrop.path
123
+ });
124
+ } else {
125
+ insertDynamicContent(editor, newDC);
126
+ }
127
+ }
128
+ })), showDrop.type === 'emoji' && React.createElement(EmojiPicker, {
129
+ onEmojiSelect: s => editor.insertText(s)
130
+ })));
131
+ });
128
132
  };
@@ -6,7 +6,7 @@ type DropValueCommon = {
6
6
  };
7
7
  export type DropValuePersonalization = {
8
8
  type: 'personalization';
9
- path: number[];
9
+ path?: number[];
10
10
  };
11
11
  export type DropValueEmoji = {
12
12
  type: 'emoji';
@@ -22,7 +22,7 @@ export type RichMessageEditorProps = {
22
22
  canUseEmoji?: boolean;
23
23
  onBlur?: () => void;
24
24
  renderDynamicContent?: (props: {
25
- dc: DynamicContent;
25
+ dc?: DynamicContent;
26
26
  onChange: (newDC: DynamicContent) => void;
27
27
  }) => ReactNode;
28
28
  };
@@ -149,8 +149,8 @@ export function content2string(state) {
149
149
  export function validateContent(value) {
150
150
  for (const el of value) {
151
151
  if (isElement(el)) {
152
- if (el.type === 'dc') {
153
- return !!el.dc.tagName;
152
+ if (el.type === 'dc' && !el.dc.tagName) {
153
+ return false;
154
154
  }
155
155
  if (!validateContent(el.children)) {
156
156
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",