@pushwoosh/dumb-components 1.0.48 → 1.0.49
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,6 @@
|
|
|
1
1
|
import React, { Fragment, useMemo } from 'react';
|
|
2
2
|
import { DynamicContentBracket, DynamicContentRoot } from './RichMessageViewer.styled';
|
|
3
3
|
import { isElement, string2content } from './slate/helpers';
|
|
4
|
-
const arrayJoinReact = (arr, separator) => arr.flatMap((item, index) => index ? [separator, item] : [item]);
|
|
5
4
|
export const RichMessageViewer = ({
|
|
6
5
|
value,
|
|
7
6
|
lineBreaks
|
|
@@ -9,7 +8,8 @@ export const RichMessageViewer = ({
|
|
|
9
8
|
const content = useMemo(() => {
|
|
10
9
|
return Array.isArray(value) ? value : string2content(value);
|
|
11
10
|
}, [value]);
|
|
12
|
-
|
|
11
|
+
const separator = lineBreaks ? React.createElement("br", null) : ' ';
|
|
12
|
+
return content.map((node, index) => {
|
|
13
13
|
const children = node.children.map((child, idx) => {
|
|
14
14
|
if (isElement(child) && child.type === 'dc') {
|
|
15
15
|
return (
|
|
@@ -21,8 +21,11 @@ export const RichMessageViewer = ({
|
|
|
21
21
|
}
|
|
22
22
|
return child.text;
|
|
23
23
|
});
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
return (
|
|
25
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
26
|
+
React.createElement(Fragment, {
|
|
27
|
+
key: index
|
|
28
|
+
}, index > 0 && separator, children)
|
|
29
|
+
);
|
|
30
|
+
});
|
|
28
31
|
};
|