@developer_tribe/react-builder 0.1.16 → 0.1.18
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/OnboardButton/OnboardButtonProps.generated.d.ts +6 -1
- package/dist/build-components/OnboardFooter/OnboardFooter.d.ts +1 -1
- package/dist/build-components/OnboardFooter/OnboardFooterProps.generated.d.ts +8 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/types/Node.d.ts +1 -1
- package/dist/utils/patterns.d.ts +10 -0
- package/package.json +1 -1
- package/scripts/prebuild/utils/createGeneratedProps.js +39 -4
- package/scripts/prebuild/utils/validateAllComponentsOrThrow.js +49 -7
- package/src/AttributesEditor.tsx +239 -1
- package/src/RenderPage.tsx +12 -6
- package/src/build-components/OnboardButton/OnboardButtonProps.generated.ts +7 -1
- package/src/build-components/OnboardButton/pattern.json +8 -1
- package/src/build-components/OnboardFooter/OnboardFooter.tsx +58 -2
- package/src/build-components/OnboardFooter/OnboardFooterProps.generated.ts +8 -0
- package/src/build-components/OnboardFooter/pattern.json +9 -1
- package/src/styles/index.scss +14 -0
- package/src/types/Node.ts +8 -1
- package/src/utils/novaToJson.ts +40 -9
- package/src/utils/patterns.ts +36 -0
package/src/utils/novaToJson.ts
CHANGED
|
@@ -229,25 +229,56 @@ function mapFooterFromGeneralComponents(generalComponents: any[]): Node | null {
|
|
|
229
229
|
const footer = generalComponents.find((gc) => gc?.layout === 'footer-layout');
|
|
230
230
|
if (!footer) return null;
|
|
231
231
|
const texts = (footer?.attributes?.texts || []) as any[];
|
|
232
|
-
const
|
|
232
|
+
const linkedWords: { text_key?: string; color?: string; page?: string }[] =
|
|
233
|
+
[];
|
|
234
|
+
let baseTextKey: string | undefined;
|
|
235
|
+
let baseTextColor: string | undefined;
|
|
233
236
|
|
|
234
237
|
for (const t of texts) {
|
|
235
238
|
if (t?.layout === 'Text') {
|
|
236
239
|
const textKey = t?.attributes?.text_localization_key || '';
|
|
237
240
|
const color = t?.attributes?.text_color || undefined;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
241
|
+
if (!baseTextKey) baseTextKey = textKey;
|
|
242
|
+
if (!baseTextColor && typeof color === 'string') baseTextColor = color;
|
|
243
|
+
|
|
244
|
+
// Extract linked words if present
|
|
245
|
+
const lws = (t?.attributes?.linkedwords || []) as any[];
|
|
246
|
+
for (const w of lws) {
|
|
247
|
+
if (w?.layout === 'LinkedWords') {
|
|
248
|
+
const text_key = w?.attributes?.linked_word_localization_key as
|
|
249
|
+
| string
|
|
250
|
+
| undefined;
|
|
251
|
+
const lwColor = w?.attributes?.linked_word_color as
|
|
252
|
+
| string
|
|
253
|
+
| undefined;
|
|
254
|
+
const page = w?.attributes?.page as string | undefined;
|
|
255
|
+
linkedWords.push({ text_key, color: lwColor, page });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
243
258
|
}
|
|
244
259
|
}
|
|
245
260
|
|
|
246
|
-
|
|
261
|
+
const attributes: Record<string, unknown> = { gap: 8 };
|
|
262
|
+
if (baseTextKey) attributes.textLocalizationKey = baseTextKey;
|
|
263
|
+
if (baseTextColor) attributes.textColor = baseTextColor;
|
|
264
|
+
const first = linkedWords[0];
|
|
265
|
+
const second = linkedWords[1];
|
|
266
|
+
if (first) {
|
|
267
|
+
if (first.text_key)
|
|
268
|
+
attributes.linkedWordFirstLocalizationKey = first.text_key;
|
|
269
|
+
if (first.color) attributes.linkedWordFirstColor = first.color;
|
|
270
|
+
if (first.page) attributes.linkedWordFirstPage = first.page;
|
|
271
|
+
}
|
|
272
|
+
if (second) {
|
|
273
|
+
if (second.text_key)
|
|
274
|
+
attributes.linkedWordSecondLocalizationKey = second.text_key;
|
|
275
|
+
if (second.color) attributes.linkedWordSecondColor = second.color;
|
|
276
|
+
if (second.page) attributes.linkedWordSecondPage = second.page;
|
|
277
|
+
}
|
|
247
278
|
|
|
248
279
|
return {
|
|
249
280
|
type: 'OnboardFooter',
|
|
250
|
-
attributes
|
|
251
|
-
children,
|
|
281
|
+
attributes,
|
|
282
|
+
children: undefined as unknown as Node,
|
|
252
283
|
} as NodeData;
|
|
253
284
|
}
|
package/src/utils/patterns.ts
CHANGED
|
@@ -26,6 +26,10 @@ type Pattern = {
|
|
|
26
26
|
children: unknown;
|
|
27
27
|
attributes: Record<string, string | string[]>;
|
|
28
28
|
};
|
|
29
|
+
// Optional custom complex types referenced by attributes like "X[]" or "X"
|
|
30
|
+
// Each entry maps a type name (e.g., "EventObject") to its field schema
|
|
31
|
+
// where the inner record maps fieldName -> primitive type or enum options
|
|
32
|
+
types?: Record<string, Record<string, string | string[]>>;
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
const patterns: Pattern[] = [
|
|
@@ -61,3 +65,35 @@ export function getAttributeSchema(
|
|
|
61
65
|
const p = getPatternByType(type);
|
|
62
66
|
return p?.pattern.attributes;
|
|
63
67
|
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns the schema of a custom complex type declared under a component pattern's `types` block.
|
|
71
|
+
* For example, OnboardButton.pattern.types.EventObject
|
|
72
|
+
*/
|
|
73
|
+
export function getTypeSchema(
|
|
74
|
+
componentType?: string | null,
|
|
75
|
+
typeName?: string | null,
|
|
76
|
+
): Record<string, string | string[]> | undefined {
|
|
77
|
+
if (!componentType || !typeName) return undefined;
|
|
78
|
+
const p = getPatternByType(componentType);
|
|
79
|
+
// Some JSON imports may not type-check "types" so we fallback to any access
|
|
80
|
+
const types: Record<string, Record<string, string | string[]>> | undefined = (
|
|
81
|
+
p as unknown as {
|
|
82
|
+
types?: Record<string, Record<string, string | string[]>>;
|
|
83
|
+
}
|
|
84
|
+
)?.types;
|
|
85
|
+
return types?.[typeName];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Utility: returns true if the type name refers to a primitive scalar */
|
|
89
|
+
export function isPrimitiveType(typeName: string): boolean {
|
|
90
|
+
return (
|
|
91
|
+
typeName === 'string' || typeName === 'number' || typeName === 'boolean'
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Utility: parse `X[]` forms and return the item type if present */
|
|
96
|
+
export function getArrayItemType(typeName: string): string | null {
|
|
97
|
+
if (typeof typeName !== 'string') return null;
|
|
98
|
+
return typeName.endsWith('[]') ? typeName.slice(0, -2) : null;
|
|
99
|
+
}
|