@cntrl-site/sdk-nextjs 0.8.4 → 0.8.5
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.
- package/.idea/inspectionProfiles/Project_Default.xml +15 -0
- package/cntrl-site-sdk-nextjs-0.8.5.tgz +0 -0
- package/lib/utils/RichTextConverter/RichTextConverter.js +32 -8
- package/package.json +1 -1
- package/src/utils/RichTextConverter/RichTextConverter.tsx +32 -8
- package/cntrl-site-sdk-nextjs-0.7.1.tgz +0 -0
- package/cntrl-site-sdk-nextjs-0.8.4.tgz +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="HtmlUnknownAttribute" enabled="true" level="WARNING" enabled_by_default="true">
|
|
5
|
+
<option name="myValues">
|
|
6
|
+
<value>
|
|
7
|
+
<list size="1">
|
|
8
|
+
<item index="0" class="java.lang.String" itemvalue="jsx" />
|
|
9
|
+
</list>
|
|
10
|
+
</value>
|
|
11
|
+
</option>
|
|
12
|
+
<option name="myCustomValuesEnabled" value="true" />
|
|
13
|
+
</inspection_tool>
|
|
14
|
+
</profile>
|
|
15
|
+
</component>
|
|
Binary file
|
|
@@ -11,8 +11,7 @@ exports.FontStyles = {
|
|
|
11
11
|
};
|
|
12
12
|
class RichTextConverter {
|
|
13
13
|
toHtml(richText, layouts, hasPreset) {
|
|
14
|
-
const { text
|
|
15
|
-
const text = Array.from(rawText); // because of emoji
|
|
14
|
+
const { text, blocks = [] } = richText.commonParams;
|
|
16
15
|
const root = [];
|
|
17
16
|
const styleRules = layouts.reduce((rec, layout) => {
|
|
18
17
|
rec[layout.id] = [];
|
|
@@ -71,18 +70,18 @@ class RichTextConverter {
|
|
|
71
70
|
for (const entity of entitiesGroups) {
|
|
72
71
|
const entityKids = [];
|
|
73
72
|
if (offset < entity.start) {
|
|
74
|
-
kids.push(content
|
|
73
|
+
kids.push(sliceSymbols(content, offset, entity.start));
|
|
75
74
|
offset = entity.start;
|
|
76
75
|
}
|
|
77
76
|
for (const style of entity.stylesGroup) {
|
|
78
77
|
if (offset < style.start) {
|
|
79
|
-
entityKids.push(content
|
|
78
|
+
entityKids.push(sliceSymbols(content, offset, style.start));
|
|
80
79
|
}
|
|
81
|
-
entityKids.push((0, jsx_runtime_1.jsx)("span", { className: `s-${style.start}-${style.end}`, children: content
|
|
80
|
+
entityKids.push((0, jsx_runtime_1.jsx)("span", { className: `s-${style.start}-${style.end}`, children: sliceSymbols(content, style.start, style.end) }, style.start));
|
|
82
81
|
offset = style.end;
|
|
83
82
|
}
|
|
84
83
|
if (offset < entity.end) {
|
|
85
|
-
entityKids.push(content
|
|
84
|
+
entityKids.push(sliceSymbols(content, offset, entity.end));
|
|
86
85
|
offset = entity.end;
|
|
87
86
|
}
|
|
88
87
|
if (entity.link) {
|
|
@@ -91,8 +90,8 @@ class RichTextConverter {
|
|
|
91
90
|
}
|
|
92
91
|
kids.push(...entityKids);
|
|
93
92
|
}
|
|
94
|
-
if (offset < content
|
|
95
|
-
kids.push(content
|
|
93
|
+
if (offset < getSymbolsCount(content)) {
|
|
94
|
+
kids.push(sliceSymbols(content, offset));
|
|
96
95
|
}
|
|
97
96
|
for (const item of group) {
|
|
98
97
|
const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];
|
|
@@ -224,3 +223,28 @@ function getResolvedValue(value, name) {
|
|
|
224
223
|
return value;
|
|
225
224
|
return value ? sdk_1.CntrlColor.parse(value).toCss() : value;
|
|
226
225
|
}
|
|
226
|
+
function sliceSymbols(text, start, end = NaN) {
|
|
227
|
+
let startOffset = NaN;
|
|
228
|
+
let endOffset = 0;
|
|
229
|
+
let count = -1;
|
|
230
|
+
for (const ch of text) {
|
|
231
|
+
count += 1;
|
|
232
|
+
if (count === start) {
|
|
233
|
+
startOffset = endOffset;
|
|
234
|
+
}
|
|
235
|
+
if (count === end)
|
|
236
|
+
break;
|
|
237
|
+
endOffset += ch.length;
|
|
238
|
+
}
|
|
239
|
+
if (isNaN(startOffset))
|
|
240
|
+
return '';
|
|
241
|
+
return text.slice(startOffset, endOffset + 1);
|
|
242
|
+
}
|
|
243
|
+
function getSymbolsCount(input) {
|
|
244
|
+
let count = 0;
|
|
245
|
+
let ch;
|
|
246
|
+
for (ch of input) {
|
|
247
|
+
count += 1;
|
|
248
|
+
}
|
|
249
|
+
return count;
|
|
250
|
+
}
|
package/package.json
CHANGED
|
@@ -41,8 +41,7 @@ export class RichTextConverter {
|
|
|
41
41
|
layouts: TLayout[],
|
|
42
42
|
hasPreset: boolean
|
|
43
43
|
): [ReactNode[], string] {
|
|
44
|
-
const { text
|
|
45
|
-
const text = Array.from(rawText); // because of emoji
|
|
44
|
+
const { text, blocks = [] } = richText.commonParams;
|
|
46
45
|
const root: ReactElement[] = [];
|
|
47
46
|
const styleRules = layouts.reduce<Record<string, string[]>>((rec, layout) => {
|
|
48
47
|
rec[layout.id] = [];
|
|
@@ -102,18 +101,18 @@ export class RichTextConverter {
|
|
|
102
101
|
for (const entity of entitiesGroups) {
|
|
103
102
|
const entityKids: ReactNode[] = [];
|
|
104
103
|
if (offset < entity.start) {
|
|
105
|
-
kids.push(content
|
|
104
|
+
kids.push(sliceSymbols(content, offset, entity.start));
|
|
106
105
|
offset = entity.start;
|
|
107
106
|
}
|
|
108
107
|
for (const style of entity.stylesGroup) {
|
|
109
108
|
if (offset < style.start) {
|
|
110
|
-
entityKids.push(content
|
|
109
|
+
entityKids.push(sliceSymbols(content, offset, style.start));
|
|
111
110
|
}
|
|
112
|
-
entityKids.push(<span key={style.start} className={`s-${style.start}-${style.end}`}>{content
|
|
111
|
+
entityKids.push(<span key={style.start} className={`s-${style.start}-${style.end}`}>{sliceSymbols(content, style.start, style.end)}</span>);
|
|
113
112
|
offset = style.end;
|
|
114
113
|
}
|
|
115
114
|
if (offset < entity.end) {
|
|
116
|
-
entityKids.push(content
|
|
115
|
+
entityKids.push(sliceSymbols(content, offset, entity.end));
|
|
117
116
|
offset = entity.end;
|
|
118
117
|
}
|
|
119
118
|
if (entity.link) {
|
|
@@ -122,8 +121,8 @@ export class RichTextConverter {
|
|
|
122
121
|
}
|
|
123
122
|
kids.push(...entityKids);
|
|
124
123
|
}
|
|
125
|
-
if (offset < content
|
|
126
|
-
kids.push(content
|
|
124
|
+
if (offset < getSymbolsCount(content)) {
|
|
125
|
+
kids.push(sliceSymbols(content, offset));
|
|
127
126
|
}
|
|
128
127
|
for (const item of group) {
|
|
129
128
|
const entitiesGroups = this.groupEntities(entities, item.styles) ?? [];
|
|
@@ -258,3 +257,28 @@ function getResolvedValue(value: string | undefined, name: string) {
|
|
|
258
257
|
if (name !== 'COLOR') return value;
|
|
259
258
|
return value ? CntrlColor.parse(value).toCss() : value;
|
|
260
259
|
}
|
|
260
|
+
|
|
261
|
+
function sliceSymbols(text: string, start: number, end: number = NaN): string {
|
|
262
|
+
let startOffset = NaN;
|
|
263
|
+
let endOffset = 0;
|
|
264
|
+
let count = -1;
|
|
265
|
+
for (const ch of text) {
|
|
266
|
+
count += 1;
|
|
267
|
+
if (count === start) {
|
|
268
|
+
startOffset = endOffset;
|
|
269
|
+
}
|
|
270
|
+
if (count === end) break;
|
|
271
|
+
endOffset += ch.length;
|
|
272
|
+
}
|
|
273
|
+
if (isNaN(startOffset)) return '';
|
|
274
|
+
return text.slice(startOffset, endOffset + 1);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function getSymbolsCount(input: string): number {
|
|
278
|
+
let count = 0;
|
|
279
|
+
let ch: string;
|
|
280
|
+
for (ch of input) {
|
|
281
|
+
count += 1;
|
|
282
|
+
}
|
|
283
|
+
return count;
|
|
284
|
+
}
|
|
Binary file
|
|
Binary file
|