@developer_tribe/react-builder 0.1.31 → 0.1.32
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/Button/ButtonProps.generated.d.ts +2 -1
- package/dist/build-components/CarouselButtons/CarouselButtonsProps.generated.d.ts +2 -1
- package/dist/build-components/CarouselDots/CarouselDotsProps.generated.d.ts +2 -1
- package/dist/build-components/Image/ImageProps.generated.d.ts +2 -1
- package/dist/build-components/OnboardButton/OnboardButtonProps.generated.d.ts +8 -4
- package/dist/build-components/OnboardButtons/OnboardButtonsProps.generated.d.ts +6 -3
- package/dist/build-components/OnboardDot/OnboardDotProps.generated.d.ts +2 -1
- package/dist/build-components/OnboardFooter/OnboardFooterProps.generated.d.ts +10 -5
- package/dist/build-components/OnboardImage/OnboardImageProps.generated.d.ts +4 -1
- package/dist/build-components/OnboardItem/OnboardItemProps.generated.d.ts +4 -2
- package/dist/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.d.ts +10 -5
- package/dist/build-components/OnboardTitle/OnboardTitleProps.generated.d.ts +10 -5
- package/dist/build-components/Text/TextProps.generated.d.ts +10 -5
- package/dist/build-components/View/ViewProps.generated.d.ts +6 -3
- package/dist/build-components/patterns.generated.d.ts +7 -2
- package/dist/index.cjs.js +6 -4
- package/dist/index.esm.js +6 -4
- package/package.json +2 -1
- package/scripts/prebuild/utils/createGeneratedProps.js +64 -5
- package/src/assets/samples/getSamples.ts +6 -0
- package/src/assets/samples/vpn-onboard-5.json +1025 -0
- package/src/assets/samples/vpn-onboard-6.json +709 -0
- package/src/build-components/Button/ButtonProps.generated.ts +14 -12
- package/src/build-components/CarouselButtons/CarouselButtonsProps.generated.ts +6 -1
- package/src/build-components/CarouselDots/CarouselDotsProps.generated.ts +9 -7
- package/src/build-components/Image/ImageProps.generated.ts +3 -1
- package/src/build-components/OnboardButton/OnboardButtonProps.generated.ts +14 -9
- package/src/build-components/OnboardButton/pattern.json +3 -2
- package/src/build-components/OnboardButtons/OnboardButtonsProps.generated.ts +10 -3
- package/src/build-components/OnboardDot/OnboardDotProps.generated.ts +9 -7
- package/src/build-components/OnboardFooter/OnboardFooterProps.generated.ts +33 -22
- package/src/build-components/OnboardImage/OnboardImage.tsx +24 -1
- package/src/build-components/OnboardImage/OnboardImageProps.generated.ts +5 -1
- package/src/build-components/OnboardImage/pattern.json +3 -5
- package/src/build-components/OnboardItem/OnboardItemProps.generated.ts +5 -2
- package/src/build-components/OnboardSubtitle/OnboardSubtitleProps.generated.ts +33 -22
- package/src/build-components/OnboardTitle/OnboardTitleProps.generated.ts +33 -22
- package/src/build-components/Text/TextProps.generated.ts +33 -22
- package/src/build-components/View/ViewProps.generated.ts +18 -9
- package/src/build-components/patterns.generated.ts +7 -2
- package/src/utils/novaToJson.ts +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@developer_tribe/react-builder",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"restricted": true,
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"eslint-plugin-react": "^7.37.5",
|
|
46
46
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
47
47
|
"globals": "^16.4.0",
|
|
48
|
+
"lottie-react": "^2.4.1",
|
|
48
49
|
"prettier": "^3.6.2",
|
|
49
50
|
"react": "^18.3.1",
|
|
50
51
|
"rimraf": "^6.0.1",
|
|
@@ -7,15 +7,43 @@ import { formatWithPrettier } from './formatWithPrettier.js';
|
|
|
7
7
|
const isPrimitive = t => t === 'string' || t === 'number' || t === 'boolean';
|
|
8
8
|
const getArrayItem = t =>
|
|
9
9
|
typeof t === 'string' && t.endsWith('[]') ? t.slice(0, -2) : null;
|
|
10
|
+
// Convert a property name like "animation" or "on-press" to PascalCase
|
|
11
|
+
const toPascalCase = s =>
|
|
12
|
+
String(s)
|
|
13
|
+
.replace(/([A-Z]+)/g, ' $1')
|
|
14
|
+
.split(/[^a-zA-Z0-9]+|\s+/)
|
|
15
|
+
.filter(Boolean)
|
|
16
|
+
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
|
17
|
+
.join('');
|
|
10
18
|
|
|
11
19
|
// Convert attribute type spec to TS type. Supports enum arrays, primitives, CustomType, and CustomType[]
|
|
12
|
-
|
|
20
|
+
// If an enum array is detected, "registerEnumAlias" will be called to create an exported alias
|
|
21
|
+
function tsTypeFromAttributeType(
|
|
22
|
+
attrType,
|
|
23
|
+
allTypes,
|
|
24
|
+
propertyName,
|
|
25
|
+
registerEnumAlias
|
|
26
|
+
) {
|
|
13
27
|
if (attrType === 'string') return 'string';
|
|
14
28
|
if (attrType === 'number') return 'number';
|
|
15
29
|
if (attrType === 'boolean') return 'boolean';
|
|
16
30
|
if (Array.isArray(attrType)) {
|
|
17
|
-
const
|
|
18
|
-
|
|
31
|
+
const rawMembers = attrType;
|
|
32
|
+
if (rawMembers.length === 0) return 'string';
|
|
33
|
+
const hasNull = rawMembers.some(v => v === 'null');
|
|
34
|
+
const nonNullMembers = rawMembers.filter(v => v !== 'null');
|
|
35
|
+
const nonNullLiteralMembers = nonNullMembers.map(v => JSON.stringify(v));
|
|
36
|
+
|
|
37
|
+
// Only null specified
|
|
38
|
+
if (hasNull && nonNullLiteralMembers.length === 0) return 'null';
|
|
39
|
+
|
|
40
|
+
if (typeof registerEnumAlias === 'function' && propertyName) {
|
|
41
|
+
const alias = registerEnumAlias(propertyName, nonNullLiteralMembers);
|
|
42
|
+
return hasNull ? `${alias} | null` : alias;
|
|
43
|
+
}
|
|
44
|
+
// Fallback if no registrar provided
|
|
45
|
+
const baseUnion = nonNullLiteralMembers.join(' | ');
|
|
46
|
+
return hasNull ? `${baseUnion} | null` : baseUnion;
|
|
19
47
|
}
|
|
20
48
|
if (typeof attrType === 'string') {
|
|
21
49
|
const item = getArrayItem(attrType);
|
|
@@ -44,11 +72,36 @@ export async function createGeneratedProps(
|
|
|
44
72
|
const attributes = pattern.attributes || {};
|
|
45
73
|
const allTypes = patternJson.types || {};
|
|
46
74
|
|
|
75
|
+
// Collect option type aliases for any enum arrays encountered across attributes and custom types
|
|
76
|
+
const optionAliases = new Map(); // name -> union (string like `'a' | 'b'`)
|
|
77
|
+
const registerEnumAlias = (propName, literalMembers) => {
|
|
78
|
+
const base = `${toPascalCase(propName)}OptionType`;
|
|
79
|
+
const union = literalMembers.join(' | ');
|
|
80
|
+
if (!optionAliases.has(base)) {
|
|
81
|
+
optionAliases.set(base, union);
|
|
82
|
+
return base;
|
|
83
|
+
}
|
|
84
|
+
const existing = optionAliases.get(base);
|
|
85
|
+
if (existing === union) return base;
|
|
86
|
+
let i = 2;
|
|
87
|
+
// find a non-conflicting alias name
|
|
88
|
+
// eslint-disable-next-line no-constant-condition
|
|
89
|
+
while (true) {
|
|
90
|
+
const candidate = `${base}${i}`;
|
|
91
|
+
if (!optionAliases.has(candidate)) {
|
|
92
|
+
optionAliases.set(candidate, union);
|
|
93
|
+
return candidate;
|
|
94
|
+
}
|
|
95
|
+
if (optionAliases.get(candidate) === union) return candidate;
|
|
96
|
+
i += 1;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
47
100
|
// Emit custom type interfaces if present
|
|
48
101
|
const customTypeEntries = Object.entries(allTypes);
|
|
49
102
|
const customTypeBlocks = customTypeEntries.map(([typeName, schema]) => {
|
|
50
103
|
const fields = Object.entries(schema).map(([k, t]) => {
|
|
51
|
-
const tsType = tsTypeFromAttributeType(t, allTypes);
|
|
104
|
+
const tsType = tsTypeFromAttributeType(t, allTypes, k, registerEnumAlias);
|
|
52
105
|
return ` ${k}?: ${tsType};`;
|
|
53
106
|
});
|
|
54
107
|
return (
|
|
@@ -59,7 +112,7 @@ export async function createGeneratedProps(
|
|
|
59
112
|
});
|
|
60
113
|
|
|
61
114
|
const attributeLines = Object.entries(attributes).map(([key, t]) => {
|
|
62
|
-
const tsType = tsTypeFromAttributeType(t, allTypes);
|
|
115
|
+
const tsType = tsTypeFromAttributeType(t, allTypes, key, registerEnumAlias);
|
|
63
116
|
return ` ${key}?: ${tsType};`;
|
|
64
117
|
});
|
|
65
118
|
|
|
@@ -81,6 +134,12 @@ export async function createGeneratedProps(
|
|
|
81
134
|
// Re-export a component props helper to avoid repeating the local type in each component file
|
|
82
135
|
`import type { NodeData } from '../../types/Node';\n` +
|
|
83
136
|
`\n` +
|
|
137
|
+
// Export per-property option types for enum arrays
|
|
138
|
+
(optionAliases.size
|
|
139
|
+
? Array.from(optionAliases.entries())
|
|
140
|
+
.map(([name, union]) => `export type ${name} = ${union};`)
|
|
141
|
+
.join('\n') + '\n\n'
|
|
142
|
+
: '') +
|
|
84
143
|
(customTypeBlocks.length ? customTypeBlocks.join('\n') + '\n' : '') +
|
|
85
144
|
`\n` +
|
|
86
145
|
`export interface ${componentName}PropsGenerated {\n` +
|
|
@@ -6,6 +6,8 @@ import vpnOnboard1 from './vpn-onboard-1.json';
|
|
|
6
6
|
import vpnOnboard2 from './vpn-onboard-2.json';
|
|
7
7
|
import vpnOnboard3 from './vpn-onboard-3.json';
|
|
8
8
|
import vpnOnboard4 from './vpn-onboard-4.json';
|
|
9
|
+
import vpnOnboard5 from './vpn-onboard-5.json';
|
|
10
|
+
import vpnOnboard6 from './vpn-onboard-6.json';
|
|
9
11
|
import { novaToJson } from '../../utils/novaToJson';
|
|
10
12
|
|
|
11
13
|
export function getSamples(): Project[] {
|
|
@@ -14,6 +16,8 @@ export function getSamples(): Project[] {
|
|
|
14
16
|
{ ...vpnOnboard2 } as ProjectBase<unknown>,
|
|
15
17
|
{ ...vpnOnboard3 } as ProjectBase<unknown>,
|
|
16
18
|
{ ...vpnOnboard4 } as ProjectBase<unknown>,
|
|
19
|
+
{ ...vpnOnboard5 } as ProjectBase<unknown>,
|
|
20
|
+
{ ...vpnOnboard6 } as ProjectBase<unknown>,
|
|
17
21
|
];
|
|
18
22
|
legacySamples.forEach((sample) => {
|
|
19
23
|
sample.data = novaToJson(sample);
|
|
@@ -37,6 +41,8 @@ export function getOnboardSamples(): Project[] {
|
|
|
37
41
|
vpnOnboard2 as Project,
|
|
38
42
|
vpnOnboard3 as Project,
|
|
39
43
|
vpnOnboard4 as Project,
|
|
44
|
+
vpnOnboard5 as Project,
|
|
45
|
+
vpnOnboard6 as Project,
|
|
40
46
|
];
|
|
41
47
|
legacySamples.forEach((sample) => {
|
|
42
48
|
sample.data = novaToJson(sample);
|