@developer_tribe/react-builder 0.1.26 → 0.1.27
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/dist/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.d.ts +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/types/Project.d.ts +1 -1
- package/package.json +1 -1
- package/src/assets/samples/getSamples.ts +5 -1
- package/src/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.ts +1 -0
- package/src/build-components/OnboardSubtitle/pattern.json +1 -0
- package/src/types/Project.ts +1 -1
- package/src/utils/novaToJson.ts +159 -3
package/dist/types/Project.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -32,10 +32,14 @@ export function getBasicSamples(): Project[] {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function getOnboardSamples(): Project[] {
|
|
35
|
-
|
|
35
|
+
const legacySamples = [
|
|
36
36
|
vpnOnboard1 as Project,
|
|
37
37
|
vpnOnboard2 as Project,
|
|
38
38
|
vpnOnboard3 as Project,
|
|
39
39
|
vpnOnboard4 as Project,
|
|
40
40
|
];
|
|
41
|
+
legacySamples.forEach((sample) => {
|
|
42
|
+
sample.data = novaToJson(sample);
|
|
43
|
+
});
|
|
44
|
+
return legacySamples;
|
|
41
45
|
}
|
package/src/types/Project.ts
CHANGED
package/src/utils/novaToJson.ts
CHANGED
|
@@ -95,17 +95,45 @@ function buildCarouselItem(
|
|
|
95
95
|
if (comp?.layout === 'title-layout') {
|
|
96
96
|
const title = comp?.attributes?.title_localization_key || '';
|
|
97
97
|
const color = comp?.attributes?.title_color || undefined;
|
|
98
|
+
const { fontSize: titleFontSize, fontWeight: titleFontWeight } =
|
|
99
|
+
extractTextStyleAttributesFromComponent(comp);
|
|
98
100
|
children.push({
|
|
99
101
|
type: 'OnboardTitle',
|
|
100
|
-
attributes:
|
|
102
|
+
attributes:
|
|
103
|
+
color || titleFontSize || titleFontWeight
|
|
104
|
+
? {
|
|
105
|
+
...(color ? { color } : {}),
|
|
106
|
+
...(typeof titleFontSize === 'number'
|
|
107
|
+
? { fontSize: titleFontSize }
|
|
108
|
+
: {}),
|
|
109
|
+
...(titleFontWeight ? { fontWeight: titleFontWeight } : {}),
|
|
110
|
+
}
|
|
111
|
+
: undefined,
|
|
101
112
|
children: title,
|
|
102
113
|
});
|
|
103
114
|
} else if (comp?.layout === 'subtitle-layout') {
|
|
104
115
|
const subtitle = comp?.attributes?.subtitle_localization_key || '';
|
|
105
116
|
const color = comp?.attributes?.subtitle_color || undefined;
|
|
117
|
+
const {
|
|
118
|
+
fontSize: subtitleFontSize,
|
|
119
|
+
textAlign: subtitleTextAlign,
|
|
120
|
+
fontWeight: subtitleFontWeight,
|
|
121
|
+
} = extractTextStyleAttributesFromComponent(comp);
|
|
106
122
|
children.push({
|
|
107
123
|
type: 'OnboardSubtitle',
|
|
108
|
-
attributes:
|
|
124
|
+
attributes:
|
|
125
|
+
color || subtitleFontSize || subtitleTextAlign || subtitleFontWeight
|
|
126
|
+
? {
|
|
127
|
+
...(color ? { color } : {}),
|
|
128
|
+
...(typeof subtitleFontSize === 'number'
|
|
129
|
+
? { fontSize: subtitleFontSize }
|
|
130
|
+
: {}),
|
|
131
|
+
...(subtitleTextAlign ? { textAlign: subtitleTextAlign } : {}),
|
|
132
|
+
...(subtitleFontWeight
|
|
133
|
+
? { fontWeight: subtitleFontWeight }
|
|
134
|
+
: {}),
|
|
135
|
+
}
|
|
136
|
+
: undefined,
|
|
109
137
|
children: subtitle,
|
|
110
138
|
});
|
|
111
139
|
} else if (comp?.layout === 'image-layout') {
|
|
@@ -121,13 +149,20 @@ function buildCarouselItem(
|
|
|
121
149
|
? rawHeight
|
|
122
150
|
: undefined;
|
|
123
151
|
|
|
152
|
+
// derive resizeMode from is_bg_image and try to extract borderRadius from styles
|
|
153
|
+
const isBgImage = Boolean(comp?.attributes?.is_bg_image);
|
|
154
|
+
const imageStyle = extractViewStyleAttributesFromComponent(comp);
|
|
155
|
+
|
|
124
156
|
if (src) {
|
|
125
157
|
children.push({
|
|
126
158
|
type: 'OnboardImage',
|
|
127
159
|
attributes: {
|
|
128
160
|
src,
|
|
129
161
|
...(height ? { height } : {}),
|
|
130
|
-
resizeMode: 'contain',
|
|
162
|
+
resizeMode: isBgImage ? 'cover' : 'contain',
|
|
163
|
+
...(typeof imageStyle.borderRadius === 'number'
|
|
164
|
+
? { borderRadius: imageStyle.borderRadius }
|
|
165
|
+
: {}),
|
|
131
166
|
},
|
|
132
167
|
children: undefined as unknown as Node,
|
|
133
168
|
} as unknown as NodeData);
|
|
@@ -236,6 +271,127 @@ function buildCarouselItem(
|
|
|
236
271
|
};
|
|
237
272
|
}
|
|
238
273
|
|
|
274
|
+
//@eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
275
|
+
function extractTextStyleAttributesFromComponent(comp: any): {
|
|
276
|
+
fontSize?: number;
|
|
277
|
+
textAlign?: 'left' | 'center' | 'right' | 'justify';
|
|
278
|
+
fontWeight?:
|
|
279
|
+
| 'normal'
|
|
280
|
+
| 'bold'
|
|
281
|
+
| '100'
|
|
282
|
+
| '200'
|
|
283
|
+
| '300'
|
|
284
|
+
| '400'
|
|
285
|
+
| '500'
|
|
286
|
+
| '600'
|
|
287
|
+
| '700'
|
|
288
|
+
| '800'
|
|
289
|
+
| '900';
|
|
290
|
+
} {
|
|
291
|
+
const result: {
|
|
292
|
+
fontSize?: number;
|
|
293
|
+
textAlign?: 'left' | 'center' | 'right' | 'justify';
|
|
294
|
+
fontWeight?:
|
|
295
|
+
| 'normal'
|
|
296
|
+
| 'bold'
|
|
297
|
+
| '100'
|
|
298
|
+
| '200'
|
|
299
|
+
| '300'
|
|
300
|
+
| '400'
|
|
301
|
+
| '500'
|
|
302
|
+
| '600'
|
|
303
|
+
| '700'
|
|
304
|
+
| '800'
|
|
305
|
+
| '900';
|
|
306
|
+
} = {};
|
|
307
|
+
|
|
308
|
+
//@eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
309
|
+
const stylesRoot = (comp?.attributes?.styles || []) as any[];
|
|
310
|
+
if (!Array.isArray(stylesRoot) || stylesRoot.length === 0) return result;
|
|
311
|
+
|
|
312
|
+
const allowedAligns = new Set(['left', 'center', 'right', 'justify']);
|
|
313
|
+
const allowedWeights = new Set([
|
|
314
|
+
'normal',
|
|
315
|
+
'bold',
|
|
316
|
+
'100',
|
|
317
|
+
'200',
|
|
318
|
+
'300',
|
|
319
|
+
'400',
|
|
320
|
+
'500',
|
|
321
|
+
'600',
|
|
322
|
+
'700',
|
|
323
|
+
'800',
|
|
324
|
+
'900',
|
|
325
|
+
]);
|
|
326
|
+
|
|
327
|
+
for (const s of stylesRoot) {
|
|
328
|
+
if (s?.layout !== 'style-layout') continue;
|
|
329
|
+
//@eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
330
|
+
const nested = (s?.attributes?.styles || []) as any[];
|
|
331
|
+
if (!Array.isArray(nested)) continue;
|
|
332
|
+
for (const st of nested) {
|
|
333
|
+
if (st?.layout !== 'Styles') continue;
|
|
334
|
+
const type = st?.attributes?.type;
|
|
335
|
+
if (type !== 'textStyle') continue;
|
|
336
|
+
const style = st?.attributes?.style || {};
|
|
337
|
+
|
|
338
|
+
const rawFontSize = style?.fontSize;
|
|
339
|
+
if (typeof rawFontSize === 'number' && Number.isFinite(rawFontSize)) {
|
|
340
|
+
result.fontSize = rawFontSize;
|
|
341
|
+
} else if (typeof rawFontSize === 'string') {
|
|
342
|
+
const n = Number.parseInt(rawFontSize, 10);
|
|
343
|
+
if (Number.isFinite(n)) result.fontSize = n;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const align = style?.textAlign;
|
|
347
|
+
if (typeof align === 'string' && allowedAligns.has(align)) {
|
|
348
|
+
result.textAlign = align as typeof result.textAlign;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const rawWeight = style?.fontWeight;
|
|
352
|
+
let normalizedWeight: string | undefined;
|
|
353
|
+
if (typeof rawWeight === 'number' && Number.isFinite(rawWeight)) {
|
|
354
|
+
normalizedWeight = String(rawWeight);
|
|
355
|
+
} else if (typeof rawWeight === 'string') {
|
|
356
|
+
normalizedWeight = rawWeight;
|
|
357
|
+
}
|
|
358
|
+
if (normalizedWeight && allowedWeights.has(normalizedWeight)) {
|
|
359
|
+
result.fontWeight = normalizedWeight as typeof result.fontWeight;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
//@eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
368
|
+
function extractViewStyleAttributesFromComponent(comp: any): {
|
|
369
|
+
borderRadius?: number;
|
|
370
|
+
} {
|
|
371
|
+
const result: { borderRadius?: number } = {};
|
|
372
|
+
//@eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
373
|
+
const stylesRoot = (comp?.attributes?.styles || []) as any[];
|
|
374
|
+
if (!Array.isArray(stylesRoot) || stylesRoot.length === 0) return result;
|
|
375
|
+
for (const s of stylesRoot) {
|
|
376
|
+
if (s?.layout !== 'style-layout') continue;
|
|
377
|
+
//@eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
378
|
+
const nested = (s?.attributes?.styles || []) as any[];
|
|
379
|
+
if (!Array.isArray(nested)) continue;
|
|
380
|
+
for (const st of nested) {
|
|
381
|
+
if (st?.layout !== 'Styles') continue;
|
|
382
|
+
const style = st?.attributes?.style || {};
|
|
383
|
+
const rawBr = style?.borderRadius;
|
|
384
|
+
if (typeof rawBr === 'number' && Number.isFinite(rawBr)) {
|
|
385
|
+
result.borderRadius = rawBr;
|
|
386
|
+
} else if (typeof rawBr === 'string') {
|
|
387
|
+
const n = Number.parseInt(rawBr, 10);
|
|
388
|
+
if (Number.isFinite(n)) result.borderRadius = n;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return result;
|
|
393
|
+
}
|
|
394
|
+
|
|
239
395
|
function mapDotsFromGeneralComponents(generalComponents: any[]): Node | null {
|
|
240
396
|
const dots = generalComponents.find((gc) => gc?.layout === 'dots-layout');
|
|
241
397
|
if (!dots) return null;
|