@cntrl-site/sdk-nextjs 0.0.6 → 0.0.7
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.
|
@@ -10,7 +10,8 @@ exports.FontStyles = {
|
|
|
10
10
|
};
|
|
11
11
|
class RichTextConverter {
|
|
12
12
|
toHtml(richText, layouts) {
|
|
13
|
-
const { text, blocks = [] } = richText.commonParams;
|
|
13
|
+
const { text: rawText, blocks = [] } = richText.commonParams;
|
|
14
|
+
const text = Array.from(rawText); // because of emoji
|
|
14
15
|
const root = [];
|
|
15
16
|
const styleRules = layouts.reduce((rec, layout) => {
|
|
16
17
|
rec[layout.id] = [];
|
|
@@ -65,18 +66,18 @@ class RichTextConverter {
|
|
|
65
66
|
for (const entity of entitiesGroups) {
|
|
66
67
|
const entityKids = [];
|
|
67
68
|
if (offset < entity.start) {
|
|
68
|
-
kids.push(content.slice(offset, entity.start));
|
|
69
|
+
kids.push(content.slice(offset, entity.start).join(''));
|
|
69
70
|
offset = entity.start;
|
|
70
71
|
}
|
|
71
72
|
for (const style of entity.stylesGroup) {
|
|
72
73
|
if (offset < style.start) {
|
|
73
|
-
entityKids.push(content.slice(offset, style.start));
|
|
74
|
+
entityKids.push(content.slice(offset, style.start).join(''));
|
|
74
75
|
}
|
|
75
|
-
entityKids.push((0, jsx_runtime_1.jsx)("span", { className: `s-${style.start}-${style.end}`, children: content.slice(style.start, style.end) }, style.start));
|
|
76
|
+
entityKids.push((0, jsx_runtime_1.jsx)("span", { className: `s-${style.start}-${style.end}`, children: content.slice(style.start, style.end).join('') }, style.start));
|
|
76
77
|
offset = style.end;
|
|
77
78
|
}
|
|
78
79
|
if (offset < entity.end) {
|
|
79
|
-
entityKids.push(content.slice(offset, entity.end));
|
|
80
|
+
entityKids.push(content.slice(offset, entity.end).join(''));
|
|
80
81
|
offset = entity.end;
|
|
81
82
|
}
|
|
82
83
|
if (entity.link) {
|
|
@@ -86,7 +87,7 @@ class RichTextConverter {
|
|
|
86
87
|
kids.push(...entityKids);
|
|
87
88
|
}
|
|
88
89
|
if (offset < content.length) {
|
|
89
|
-
kids.push(content.slice(offset));
|
|
90
|
+
kids.push(content.slice(offset).join(''));
|
|
90
91
|
}
|
|
91
92
|
for (const item of group) {
|
|
92
93
|
const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];
|
package/package.json
CHANGED
|
@@ -38,7 +38,8 @@ export class RichTextConverter {
|
|
|
38
38
|
richText: TRichTextItem,
|
|
39
39
|
layouts: TLayout[]
|
|
40
40
|
): [ReactNode[], string] {
|
|
41
|
-
const { text, blocks = [] } = richText.commonParams;
|
|
41
|
+
const { text: rawText, blocks = [] } = richText.commonParams;
|
|
42
|
+
const text = Array.from(rawText); // because of emoji
|
|
42
43
|
const root: ReactElement[] = [];
|
|
43
44
|
const styleRules = layouts.reduce<Record<string, string[]>>((rec, layout) => {
|
|
44
45
|
rec[layout.id] = [];
|
|
@@ -94,18 +95,18 @@ export class RichTextConverter {
|
|
|
94
95
|
for (const entity of entitiesGroups) {
|
|
95
96
|
const entityKids: ReactNode[] = [];
|
|
96
97
|
if (offset < entity.start) {
|
|
97
|
-
kids.push(content.slice(offset, entity.start));
|
|
98
|
+
kids.push(content.slice(offset, entity.start).join(''));
|
|
98
99
|
offset = entity.start;
|
|
99
100
|
}
|
|
100
101
|
for (const style of entity.stylesGroup) {
|
|
101
102
|
if (offset < style.start) {
|
|
102
|
-
entityKids.push(content.slice(offset, style.start));
|
|
103
|
+
entityKids.push(content.slice(offset, style.start).join(''));
|
|
103
104
|
}
|
|
104
|
-
entityKids.push(<span key={style.start} className={`s-${style.start}-${style.end}`}>{content.slice(style.start, style.end)}</span>);
|
|
105
|
+
entityKids.push(<span key={style.start} className={`s-${style.start}-${style.end}`}>{content.slice(style.start, style.end).join('')}</span>);
|
|
105
106
|
offset = style.end;
|
|
106
107
|
}
|
|
107
108
|
if (offset < entity.end) {
|
|
108
|
-
entityKids.push(content.slice(offset, entity.end));
|
|
109
|
+
entityKids.push(content.slice(offset, entity.end).join(''));
|
|
109
110
|
offset = entity.end;
|
|
110
111
|
}
|
|
111
112
|
if (entity.link) {
|
|
@@ -115,7 +116,7 @@ export class RichTextConverter {
|
|
|
115
116
|
kids.push(...entityKids);
|
|
116
117
|
}
|
|
117
118
|
if (offset < content.length) {
|
|
118
|
-
kids.push(content.slice(offset));
|
|
119
|
+
kids.push(content.slice(offset).join(''));
|
|
119
120
|
}
|
|
120
121
|
for (const item of group) {
|
|
121
122
|
const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];
|