@bravostudioai/react 0.1.14 → 0.1.16
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/cli/commands/generate.js +90 -85
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/codegen/generator.js +218 -212
- package/dist/codegen/generator.js.map +1 -1
- package/dist/components/EncoreApp.js +34 -22
- package/dist/components/EncoreApp.js.map +1 -1
- package/dist/components.js +524 -537
- package/dist/components.js.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/packages/encore-lib/constants.js.map +1 -1
- package/dist/src/cli/commands/generate.d.ts.map +1 -1
- package/dist/src/codegen/generator.d.ts +5 -1
- package/dist/src/codegen/generator.d.ts.map +1 -1
- package/dist/src/components/EncoreApp.d.ts.map +1 -1
- package/dist/src/components.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/generate.ts +9 -1
- package/src/codegen/generator.ts +12 -1
- package/src/components/EncoreApp.tsx +9 -1
- package/src/components.tsx +11 -6
|
@@ -1,231 +1,237 @@
|
|
|
1
|
-
import { sanitizePropName as
|
|
2
|
-
function K(
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { sanitizePropName as m, getComponentPropType as W, getComponentPropName as R } from "./parser.js";
|
|
2
|
+
function K(k, x, P, E, u, c, N, v, l, d = !1, I) {
|
|
3
|
+
const y = [], a = [], p = [], f = [], D = [], A = [];
|
|
4
|
+
u.forEach((o) => {
|
|
5
|
+
y.push(` ${o.propName}?: ${o.propType};`);
|
|
6
6
|
}), c.forEach((o) => {
|
|
7
|
-
const n =
|
|
8
|
-
|
|
7
|
+
const n = m(o.groupName);
|
|
8
|
+
p.push(` ${n}?: string;`), p.push(
|
|
9
9
|
` on${n[0].toUpperCase()}${n.slice(
|
|
10
10
|
1
|
|
11
11
|
)}Change?: (value: string) => void;`
|
|
12
12
|
);
|
|
13
13
|
});
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const n =
|
|
14
|
+
const w = [];
|
|
15
|
+
N.forEach((o) => {
|
|
16
|
+
const n = m(o.formName), s = `${n[0].toUpperCase()}${n.slice(
|
|
17
17
|
1
|
|
18
|
-
)}FormData`,
|
|
18
|
+
)}FormData`, r = [];
|
|
19
19
|
o.inputs.forEach(($) => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
}),
|
|
23
|
-
${
|
|
20
|
+
const T = $.propName, b = W($.type, $.name);
|
|
21
|
+
r.push(` ${T}: ${b};`);
|
|
22
|
+
}), w.push(`export interface ${s} {
|
|
23
|
+
${r.join(`
|
|
24
24
|
`)}
|
|
25
|
-
}`),
|
|
25
|
+
}`), f.push(
|
|
26
26
|
` on${n[0].toUpperCase()}${n.slice(
|
|
27
27
|
1
|
|
28
|
-
)}Submit?: (formData: ${
|
|
28
|
+
)}Submit?: (formData: ${s}) => void;`
|
|
29
29
|
);
|
|
30
|
-
}),
|
|
31
|
-
const n = o.propName,
|
|
32
|
-
|
|
30
|
+
}), v.forEach((o) => {
|
|
31
|
+
const n = o.propName, s = n[0].toUpperCase() + n.slice(1);
|
|
32
|
+
D.push(` ${n}?: string;`), D.push(
|
|
33
33
|
` ${n}Options?: Array<string | { value: string; label: string }>;`
|
|
34
|
-
),
|
|
35
|
-
` on${
|
|
34
|
+
), D.push(
|
|
35
|
+
` on${s}Change?: (value: string) => void;`
|
|
36
36
|
);
|
|
37
|
-
}),
|
|
38
|
-
const n = o.propName,
|
|
39
|
-
|
|
40
|
-
}),
|
|
37
|
+
}), l.forEach((o) => {
|
|
38
|
+
const n = o.propName, s = n[0].toUpperCase() + n.slice(1);
|
|
39
|
+
A.push(` on${s}Click?: () => void;`);
|
|
40
|
+
}), E.forEach((o) => {
|
|
41
41
|
if (o.arrayContainer && o.arrayContainer.components.length > 0) {
|
|
42
|
-
const
|
|
42
|
+
const s = o.arrayContainer, r = `${s.propName[0].toUpperCase()}${s.propName.slice(
|
|
43
43
|
1
|
|
44
44
|
)}Item`;
|
|
45
|
-
|
|
45
|
+
y.push(` ${s.propName}: ${r}[];`);
|
|
46
46
|
}
|
|
47
|
-
const n =
|
|
48
|
-
|
|
47
|
+
const n = m(o.name || "container");
|
|
48
|
+
a.push(` ${n}CurrentIndex?: number;`), a.push(
|
|
49
49
|
` on${n[0].toUpperCase()}${n.slice(
|
|
50
50
|
1
|
|
51
51
|
)}IndexChange?: (index: number) => void;`
|
|
52
52
|
);
|
|
53
53
|
});
|
|
54
|
-
const
|
|
55
|
-
...
|
|
56
|
-
...N,
|
|
54
|
+
const z = [
|
|
55
|
+
...y,
|
|
57
56
|
...a,
|
|
58
|
-
...
|
|
59
|
-
...
|
|
60
|
-
...
|
|
61
|
-
|
|
62
|
-
${
|
|
57
|
+
...p,
|
|
58
|
+
...f,
|
|
59
|
+
...D,
|
|
60
|
+
...A
|
|
61
|
+
], j = z.length > 0, O = j ? `export interface ${P}Props {
|
|
62
|
+
${z.join(`
|
|
63
63
|
`)}
|
|
64
|
-
}` : "",
|
|
65
|
-
const n = o.arrayContainer,
|
|
64
|
+
}` : "", M = E.filter((o) => o.arrayContainer && o.arrayContainer.components.length > 0).map((o) => {
|
|
65
|
+
const n = o.arrayContainer, s = `${n.propName[0].toUpperCase()}${n.propName.slice(
|
|
66
66
|
1
|
|
67
|
-
)}Item`,
|
|
67
|
+
)}Item`, r = n.components.map(($) => ` ${$.propName}: ${$.propType};`).join(`
|
|
68
68
|
`);
|
|
69
|
-
return `export interface ${
|
|
70
|
-
${
|
|
69
|
+
return `export interface ${s} {
|
|
70
|
+
${r}
|
|
71
71
|
}`;
|
|
72
72
|
}).join(`
|
|
73
73
|
|
|
74
|
-
`),
|
|
74
|
+
`), F = w.join(`
|
|
75
75
|
|
|
76
|
-
`),
|
|
77
|
-
|
|
78
|
-
const n =
|
|
79
|
-
|
|
76
|
+
`), S = [], U = [];
|
|
77
|
+
u.forEach((o) => {
|
|
78
|
+
const n = R(o.type);
|
|
79
|
+
S.push(` // ${o.name}
|
|
80
80
|
...(props.${o.propName} !== undefined && { "${o.id}": { ${n}: props.${o.propName} } as any }),`);
|
|
81
|
-
}),
|
|
82
|
-
|
|
81
|
+
}), v.forEach((o) => {
|
|
82
|
+
S.push(` // ${o.name}
|
|
83
83
|
...((props.${o.propName} !== undefined || props.${o.propName}Options !== undefined) && {
|
|
84
84
|
"${o.id}": {
|
|
85
85
|
...(props.${o.propName} !== undefined && { value: props.${o.propName} }),
|
|
86
86
|
...(props.${o.propName}Options !== undefined && { options: props.${o.propName}Options }),
|
|
87
87
|
} as any
|
|
88
88
|
}),`);
|
|
89
|
-
}),
|
|
89
|
+
}), E.forEach((o) => {
|
|
90
90
|
if (o.arrayContainer && o.arrayContainer.components.length > 0) {
|
|
91
|
-
const $ = o.arrayContainer,
|
|
92
|
-
const
|
|
93
|
-
return ` // ${
|
|
94
|
-
"${
|
|
95
|
-
${
|
|
91
|
+
const $ = o.arrayContainer, T = $.components.map((b) => {
|
|
92
|
+
const G = R(b.type);
|
|
93
|
+
return ` // ${b.name}
|
|
94
|
+
"${b.id}": {
|
|
95
|
+
${G}: item.${b.propName},
|
|
96
96
|
}`;
|
|
97
97
|
}).join(`,
|
|
98
98
|
`);
|
|
99
|
-
|
|
99
|
+
S.push(` // ${$.name}
|
|
100
100
|
"${$.id}": props.${$.propName}.map((item) => ({
|
|
101
|
-
${
|
|
101
|
+
${T}
|
|
102
102
|
})),`);
|
|
103
103
|
}
|
|
104
|
-
const n =
|
|
104
|
+
const n = m(o.name || "container"), s = `${n[0].toUpperCase()}${n.slice(
|
|
105
105
|
1
|
|
106
|
-
)}IndexChange`,
|
|
107
|
-
o.id && (
|
|
106
|
+
)}IndexChange`, r = [];
|
|
107
|
+
o.id && (r.push(` // ${o.name}`), r.push(` "${o.id}": {`), r.push(
|
|
108
108
|
` currentIndex: props.${n}CurrentIndex,`
|
|
109
|
-
),
|
|
109
|
+
), r.push(` onIndexChange: props.on${s},`), r.push(" }")), r.length > 0 && U.push(r.join(`
|
|
110
110
|
`));
|
|
111
111
|
});
|
|
112
|
-
const
|
|
112
|
+
const B = U.length > 0 ? `
|
|
113
113
|
repeatingContainerControls={{
|
|
114
|
-
${
|
|
114
|
+
${U.join(`,
|
|
115
115
|
`)}
|
|
116
|
-
}}` : "",
|
|
117
|
-
(c.length > 0 ||
|
|
116
|
+
}}` : "", t = [], e = [];
|
|
117
|
+
(c.length > 0 || N.length > 0 || v.length > 0 || l.length > 0) && (e.push(" const handleAction = (payload: any) => {"), e.push(" const { action } = payload?.bravo || {};"), e.push(""), v.length > 0 && (e.push(" // Handle select input changes"), e.push(
|
|
118
118
|
' if (action?.action === "input-change" || action?.action === "select-change") {'
|
|
119
|
-
), e.push(" const nodeId = action?.nodeId;"), e.push(" const value = action?.params?.value;"), e.push(""),
|
|
120
|
-
const n = o.propName,
|
|
119
|
+
), e.push(" const nodeId = action?.nodeId;"), e.push(" const value = action?.params?.value;"), e.push(""), v.forEach((o) => {
|
|
120
|
+
const n = o.propName, r = `on${n[0].toUpperCase() + n.slice(1)}Change`;
|
|
121
121
|
e.push(` // ${o.name}`), e.push(
|
|
122
|
-
` if (nodeId === "${o.id}" && props.${
|
|
123
|
-
), e.push(` props.${
|
|
124
|
-
}), e.push(" }"), e.push("")),
|
|
122
|
+
` if (nodeId === "${o.id}" && props.${r}) {`
|
|
123
|
+
), e.push(` props.${r}(value);`), e.push(" return;"), e.push(" }");
|
|
124
|
+
}), e.push(" }"), e.push("")), l.length > 0 && (e.push(" // Handle button clicks"), e.push(
|
|
125
125
|
' if (action?.action === "remote" || action?.action === "tap" || action?.action === "link") {'
|
|
126
|
-
), e.push(" const nodeId = action?.nodeId;"), e.push(""),
|
|
127
|
-
const n = o.propName,
|
|
126
|
+
), e.push(" const nodeId = action?.nodeId;"), e.push(""), l.forEach((o) => {
|
|
127
|
+
const n = o.propName, r = `on${n[0].toUpperCase() + n.slice(1)}Click`;
|
|
128
128
|
e.push(` // ${o.name}`), e.push(
|
|
129
|
-
` if (nodeId === "${o.id}" && props.${
|
|
130
|
-
), e.push(` props.${
|
|
129
|
+
` if (nodeId === "${o.id}" && props.${r}) {`
|
|
130
|
+
), e.push(` props.${r}();`), e.push(" return;"), e.push(" }");
|
|
131
131
|
}), e.push(" }"), e.push("")), c.length > 0 && (e.push(
|
|
132
132
|
' if (action?.action === "input-group-change") {'
|
|
133
133
|
), e.push(
|
|
134
134
|
" const { groupName, value } = action.params;"
|
|
135
135
|
), c.forEach((o) => {
|
|
136
|
-
const n =
|
|
136
|
+
const n = m(o.groupName), s = `on${n[0].toUpperCase()}${n.slice(
|
|
137
137
|
1
|
|
138
138
|
)}Change`;
|
|
139
139
|
e.push(
|
|
140
|
-
` if (groupName === "${o.groupName}" && props.${
|
|
141
|
-
), e.push(` props.${
|
|
142
|
-
}), e.push(" }"), e.push("")),
|
|
143
|
-
` const formInputs = useEncoreState.getState().formInputs["${
|
|
144
|
-
), e.push(" const submitNodeId = action?.nodeId;"), e.push(""),
|
|
145
|
-
const
|
|
140
|
+
` if (groupName === "${o.groupName}" && props.${s}) {`
|
|
141
|
+
), e.push(` props.${s}(value);`), e.push(" return;"), e.push(" }");
|
|
142
|
+
}), e.push(" }"), e.push("")), N.length > 0 && (e.push(' if (action?.action === "submit") {'), e.push(" // Get form inputs from Encore state"), e.push(
|
|
143
|
+
` const formInputs = useEncoreState.getState().formInputs["${x}"] || {};`
|
|
144
|
+
), e.push(" const submitNodeId = action?.nodeId;"), e.push(""), N.forEach((o, n) => {
|
|
145
|
+
const s = m(o.formName), r = `on${s[0].toUpperCase()}${s.slice(
|
|
146
146
|
1
|
|
147
147
|
)}Submit`;
|
|
148
148
|
n > 0 && e.push(""), e.push(
|
|
149
149
|
` // Form: ${o.formName} (${o.formId})`
|
|
150
150
|
), o.submitButtonId ? e.push(
|
|
151
|
-
` if (submitNodeId === "${o.submitButtonId}" && props.${
|
|
152
|
-
) :
|
|
153
|
-
const $ = `${
|
|
151
|
+
` if (submitNodeId === "${o.submitButtonId}" && props.${r}) {`
|
|
152
|
+
) : N.length === 1 ? e.push(` if (props.${r}) {`) : e.push(` if (props.${r}) {`), e.push(" // Extract form inputs for this form");
|
|
153
|
+
const $ = `${s[0].toUpperCase()}${s.slice(
|
|
154
154
|
1
|
|
155
155
|
)}FormData`;
|
|
156
156
|
e.push(
|
|
157
157
|
` const formData: ${$} = {`
|
|
158
158
|
);
|
|
159
|
-
const
|
|
160
|
-
o.inputs.forEach((
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
` ${
|
|
159
|
+
const T = [];
|
|
160
|
+
o.inputs.forEach((b) => {
|
|
161
|
+
const G = b.propName;
|
|
162
|
+
T.push(
|
|
163
|
+
` ${G}: formInputs["${b.id}"]`
|
|
164
164
|
);
|
|
165
|
-
}), e.push(
|
|
166
|
-
`)), e.push(" };"), e.push(` props.${
|
|
165
|
+
}), e.push(T.join(`,
|
|
166
|
+
`)), e.push(" };"), e.push(` props.${r}(formData);`), e.push(
|
|
167
167
|
" // Note: Default form submission will still proceed after callback"
|
|
168
168
|
), e.push(" }");
|
|
169
169
|
}), e.push(" }")), e.push(" };")), c.forEach((o) => {
|
|
170
|
-
const n =
|
|
171
|
-
|
|
170
|
+
const n = m(o.groupName);
|
|
171
|
+
t.push(
|
|
172
172
|
` ...(props.${n} !== undefined && { ${n}: props.${n} }),`
|
|
173
173
|
);
|
|
174
174
|
});
|
|
175
|
-
const
|
|
175
|
+
const C = t.length > 0 ? `
|
|
176
176
|
inputGroups={{
|
|
177
|
-
${
|
|
177
|
+
${t.join(`
|
|
178
178
|
`)}
|
|
179
|
-
}}` : "",
|
|
180
|
-
onAction={handleAction}` : "",
|
|
179
|
+
}}` : "", i = e.length > 0 ? `
|
|
180
|
+
onAction={handleAction}` : "", g = j ? `props: ${P}Props` : "", h = O ? `${O}
|
|
181
181
|
|
|
182
182
|
` : "";
|
|
183
183
|
return `/**
|
|
184
|
-
* ${
|
|
184
|
+
* ${P}
|
|
185
185
|
*
|
|
186
186
|
* Wrapper component for Encore Studio app.
|
|
187
187
|
* See README.md for detailed documentation.
|
|
188
188
|
*/
|
|
189
189
|
|
|
190
|
-
import { EncoreApp${
|
|
190
|
+
import { EncoreApp${N.length > 0 ? ", useEncoreState" : ""} } from "@bravostudioai/react";
|
|
191
191
|
${d ? 'import productionData from "./data.json";' : ""}
|
|
192
192
|
|
|
193
|
-
${
|
|
193
|
+
${M ? `${M}
|
|
194
194
|
|
|
195
|
-
` : ""}${
|
|
195
|
+
` : ""}${F ? `${F}
|
|
196
196
|
|
|
197
|
-
` : ""}${
|
|
197
|
+
` : ""}${h}export function ${P}(${g}) {
|
|
198
198
|
${e.length > 0 ? e.join(`
|
|
199
199
|
`) : ""}
|
|
200
200
|
return (
|
|
201
201
|
<EncoreApp
|
|
202
|
-
appId="${
|
|
203
|
-
pageId="${
|
|
202
|
+
appId="${k}"
|
|
203
|
+
pageId="${x}"
|
|
204
204
|
${d ? `appDefinition={productionData.app}
|
|
205
205
|
pageDefinition={productionData.page}
|
|
206
206
|
componentCode={productionData.componentCode}` : ""}
|
|
207
207
|
data={{
|
|
208
|
-
${
|
|
208
|
+
${S.join(`
|
|
209
209
|
`)}
|
|
210
|
-
}}${
|
|
210
|
+
}}${B}${C}${i}
|
|
211
211
|
/>
|
|
212
212
|
);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
export default ${
|
|
215
|
+
export default ${P};
|
|
216
|
+
|
|
217
|
+
export const PageMeta = {
|
|
218
|
+
width: ${I?.width ?? "undefined"},
|
|
219
|
+
height: ${I?.height ?? "undefined"},
|
|
220
|
+
aspectRatio: ${I?.aspectRatio ?? "undefined"},
|
|
221
|
+
};
|
|
216
222
|
`;
|
|
217
223
|
}
|
|
218
|
-
function L(
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
${
|
|
224
|
-
}), c.forEach((
|
|
225
|
-
if (
|
|
226
|
-
const i =
|
|
224
|
+
function L(k, x, P, E, u, c, N, v, l, d, I) {
|
|
225
|
+
const y = [], a = [], p = [], f = [];
|
|
226
|
+
N.forEach((t) => {
|
|
227
|
+
y.push(`### \`${t.propName}\` (${t.propType}, optional)
|
|
228
|
+
|
|
229
|
+
${t.name} (${t.type}) - Component ID: ${t.id}`);
|
|
230
|
+
}), c.forEach((t) => {
|
|
231
|
+
if (t.arrayContainer && t.arrayContainer.components.length > 0) {
|
|
232
|
+
const i = t.arrayContainer, g = i.components.map((h) => `- \`${h.propName}\` (${h.propType}): ${h.name} (${h.type}) - Component ID: ${h.id}`).join(`
|
|
227
233
|
`);
|
|
228
|
-
|
|
234
|
+
y.push(`### \`${i.propName}\` (${i.propName[0].toUpperCase()}${i.propName.slice(
|
|
229
235
|
1
|
|
230
236
|
)}Item[])
|
|
231
237
|
|
|
@@ -233,24 +239,24 @@ Array of items for "${i.name}" container (ID: ${i.id})
|
|
|
233
239
|
|
|
234
240
|
**Properties:**
|
|
235
241
|
|
|
236
|
-
${
|
|
242
|
+
${g}`);
|
|
237
243
|
}
|
|
238
|
-
const
|
|
244
|
+
const e = m(t.name || "container"), C = `${e[0].toUpperCase()}${e.slice(
|
|
239
245
|
1
|
|
240
246
|
)}IndexChange`;
|
|
241
|
-
a.push(`### \`${
|
|
247
|
+
a.push(`### \`${e}CurrentIndex\` (number, optional)
|
|
242
248
|
|
|
243
|
-
Controls the currently visible slide/index for the "${
|
|
249
|
+
Controls the currently visible slide/index for the "${t.name}" container (ID: ${t.id}).
|
|
244
250
|
|
|
245
251
|
When provided, the slider operates in controlled mode - the parent component controls which slide is displayed. When not provided, the slider manages its own state.
|
|
246
252
|
|
|
247
|
-
### \`on${
|
|
253
|
+
### \`on${C}\` ((index: number) => void, optional)
|
|
248
254
|
|
|
249
255
|
Callback fired when the user navigates to a different slide. Called with the new slide index (0-based).
|
|
250
256
|
|
|
251
257
|
This event fires whenever the slide changes, whether by user interaction, automatic advancement, or programmatic control.`);
|
|
252
258
|
});
|
|
253
|
-
const
|
|
259
|
+
const D = y.length > 0 ? y.join(`
|
|
254
260
|
|
|
255
261
|
`) : "This component currently has no data-bound props.", A = a.length > 0 ? `## Control Props
|
|
256
262
|
|
|
@@ -258,84 +264,84 @@ These props allow you to imperatively control repeating containers (sliders, lis
|
|
|
258
264
|
|
|
259
265
|
${a.join(`
|
|
260
266
|
|
|
261
|
-
`)}` : "",
|
|
262
|
-
|
|
263
|
-
const
|
|
267
|
+
`)}` : "", w = [];
|
|
268
|
+
v.forEach((t) => {
|
|
269
|
+
const e = m(t.groupName), C = `on${e[0].toUpperCase()}${e.slice(
|
|
264
270
|
1
|
|
265
|
-
)}Change`, i =
|
|
271
|
+
)}Change`, i = t.elements.map((g) => `- "${g.name}"`).join(`
|
|
266
272
|
`);
|
|
267
|
-
|
|
273
|
+
w.push(`### \`${e}\` (string, optional)
|
|
268
274
|
|
|
269
|
-
Sets which element is active in the "${
|
|
275
|
+
Sets which element is active in the "${t.groupName}" input group (type: ${t.groupType}).
|
|
270
276
|
|
|
271
277
|
**Available elements:**
|
|
272
278
|
${i}
|
|
273
279
|
|
|
274
|
-
### \`${
|
|
280
|
+
### \`${C}\` ((value: string) => void, optional)
|
|
275
281
|
|
|
276
|
-
Callback fired when the user selects a different element in the "${
|
|
282
|
+
Callback fired when the user selects a different element in the "${t.groupName}" input group. Called with the name of the selected element.`);
|
|
277
283
|
});
|
|
278
|
-
const z =
|
|
284
|
+
const z = w.length > 0 ? `## Input Group Props
|
|
279
285
|
|
|
280
286
|
These props allow you to control input groups (radio button-like behavior) and receive notifications when the selection changes.
|
|
281
287
|
|
|
282
|
-
${
|
|
288
|
+
${w.join(`
|
|
283
289
|
|
|
284
|
-
`)}` : "",
|
|
285
|
-
|
|
286
|
-
const
|
|
290
|
+
`)}` : "", j = [];
|
|
291
|
+
l.forEach((t) => {
|
|
292
|
+
const e = m(t.formName), C = `on${e[0].toUpperCase()}${e.slice(
|
|
287
293
|
1
|
|
288
|
-
)}Submit`, i = `${
|
|
294
|
+
)}Submit`, i = `${e[0].toUpperCase()}${e.slice(
|
|
289
295
|
1
|
|
290
|
-
)}FormData`,
|
|
291
|
-
const
|
|
292
|
-
return `- \`${
|
|
296
|
+
)}FormData`, g = t.inputs.map((h) => {
|
|
297
|
+
const o = h.propName, n = W(h.type, h.name);
|
|
298
|
+
return `- \`${o}\` (${n}) - ${h.name}`;
|
|
293
299
|
}).join(`
|
|
294
300
|
`);
|
|
295
|
-
|
|
301
|
+
j.push(`### \`${C}\` ((formData: ${i}) => void, optional)
|
|
296
302
|
|
|
297
|
-
Callback fired when the "${
|
|
303
|
+
Callback fired when the "${t.formName}" form is submitted. Called with a typed object containing all form input values with human-readable property names.
|
|
298
304
|
|
|
299
305
|
**Form data shape:**
|
|
300
306
|
\`\`\`typescript
|
|
301
307
|
interface ${i} {
|
|
302
|
-
${
|
|
303
|
-
const
|
|
304
|
-
return ` ${
|
|
308
|
+
${t.inputs.map((h) => {
|
|
309
|
+
const o = h.propName, n = W(h.type, h.name);
|
|
310
|
+
return ` ${o}: ${n};`;
|
|
305
311
|
}).join(`
|
|
306
312
|
`)}
|
|
307
313
|
}
|
|
308
314
|
\`\`\`
|
|
309
315
|
|
|
310
316
|
**Form inputs:**
|
|
311
|
-
${
|
|
317
|
+
${g}`);
|
|
312
318
|
});
|
|
313
|
-
const O =
|
|
319
|
+
const O = j.length > 0 ? `## Form Submission Props
|
|
314
320
|
|
|
315
321
|
These props allow you to handle form submissions and access form input values.
|
|
316
322
|
|
|
317
|
-
${
|
|
323
|
+
${j.join(`
|
|
318
324
|
|
|
319
325
|
`)}` : "";
|
|
320
|
-
d.forEach((
|
|
321
|
-
const
|
|
322
|
-
|
|
326
|
+
d.forEach((t) => {
|
|
327
|
+
const e = t.propName, i = `on${e[0].toUpperCase() + e.slice(1)}Change`, g = `${e}Options`;
|
|
328
|
+
p.push(`### \`${e}\` (string, optional)
|
|
323
329
|
|
|
324
|
-
Controls the selected value of the "${
|
|
330
|
+
Controls the selected value of the "${t.name}" dropdown (Component ID: ${t.id}).
|
|
325
331
|
|
|
326
332
|
When provided, the select input operates in controlled mode - the parent component controls the current value.
|
|
327
333
|
|
|
328
|
-
### \`${
|
|
334
|
+
### \`${g}\` (Array<string | { value: string; label: string }>, optional)
|
|
329
335
|
|
|
330
|
-
Sets the available options for the "${
|
|
336
|
+
Sets the available options for the "${t.name}" dropdown. Can be an array of strings (used as both value and label) or an array of objects with \`value\` and \`label\` properties.
|
|
331
337
|
|
|
332
338
|
**Example:**
|
|
333
339
|
\`\`\`tsx
|
|
334
340
|
// Simple string array
|
|
335
|
-
${
|
|
341
|
+
${g}={["Option 1", "Option 2", "Option 3"]}
|
|
336
342
|
|
|
337
343
|
// Object array with separate values and labels
|
|
338
|
-
${
|
|
344
|
+
${g}={[
|
|
339
345
|
{ value: "opt1", label: "Option 1" },
|
|
340
346
|
{ value: "opt2", label: "Option 2" },
|
|
341
347
|
]}
|
|
@@ -343,34 +349,34 @@ ${C}={[
|
|
|
343
349
|
|
|
344
350
|
### \`${i}\` ((value: string) => void, optional)
|
|
345
351
|
|
|
346
|
-
Callback fired when the user selects a different option in the "${
|
|
352
|
+
Callback fired when the user selects a different option in the "${t.name}" dropdown. Called with the selected value.`);
|
|
347
353
|
});
|
|
348
|
-
const M =
|
|
354
|
+
const M = p.length > 0 ? `## Select Input Props
|
|
349
355
|
|
|
350
356
|
These props allow you to control select/dropdown inputs and respond to value changes.
|
|
351
357
|
|
|
352
|
-
${
|
|
358
|
+
${p.join(`
|
|
353
359
|
|
|
354
360
|
`)}` : "";
|
|
355
|
-
|
|
356
|
-
const
|
|
357
|
-
|
|
361
|
+
I.forEach((t) => {
|
|
362
|
+
const e = t.propName, i = `on${e[0].toUpperCase() + e.slice(1)}Click`;
|
|
363
|
+
f.push(`### \`${i}\` (() => void, optional)
|
|
358
364
|
|
|
359
|
-
Callback fired when the "${
|
|
365
|
+
Callback fired when the "${t.name}" button is clicked (Component ID: ${t.id}).
|
|
360
366
|
|
|
361
|
-
Action type: \`${
|
|
367
|
+
Action type: \`${t.actionType}\``);
|
|
362
368
|
});
|
|
363
|
-
const
|
|
369
|
+
const F = f.length > 0 ? `## Action Button Props
|
|
364
370
|
|
|
365
371
|
These props allow you to respond to button clicks and other user interactions.
|
|
366
372
|
|
|
367
|
-
${
|
|
373
|
+
${f.join(`
|
|
368
374
|
|
|
369
|
-
`)}` : "",
|
|
375
|
+
`)}` : "", S = `## Props
|
|
370
376
|
|
|
371
377
|
### Data Props
|
|
372
378
|
|
|
373
|
-
${
|
|
379
|
+
${D}
|
|
374
380
|
|
|
375
381
|
${A}
|
|
376
382
|
|
|
@@ -380,31 +386,31 @@ ${O}
|
|
|
380
386
|
|
|
381
387
|
${M}
|
|
382
388
|
|
|
383
|
-
${
|
|
389
|
+
${F}`, U = c.length > 0 && c[0].arrayContainer ? `<${u}
|
|
384
390
|
${c.map(
|
|
385
|
-
(
|
|
391
|
+
(t) => t.arrayContainer ? `${t.arrayContainer.propName}={[
|
|
386
392
|
{
|
|
387
|
-
${
|
|
388
|
-
(
|
|
393
|
+
${t.arrayContainer?.components.map(
|
|
394
|
+
(e) => `${e.propName}: "${e.type === "component:image" ? "https://example.com/image.jpg" : "Example value"}"`
|
|
389
395
|
).join(`,
|
|
390
396
|
`)}
|
|
391
397
|
}
|
|
392
398
|
]}` : ""
|
|
393
399
|
).filter(Boolean).join(`
|
|
394
400
|
`)}
|
|
395
|
-
/>` : `<${
|
|
396
|
-
let
|
|
401
|
+
/>` : `<${u} />`;
|
|
402
|
+
let B = "";
|
|
397
403
|
if (c.length > 0 && c[0]) {
|
|
398
|
-
const
|
|
404
|
+
const t = c[0], e = m(t.name || "container"), C = `${e[0].toUpperCase()}${e.slice(
|
|
399
405
|
1
|
|
400
406
|
)}IndexChange`;
|
|
401
|
-
|
|
407
|
+
B = `## Controlling Slides
|
|
402
408
|
|
|
403
409
|
You can imperatively control which slide is displayed and listen for slide changes:
|
|
404
410
|
|
|
405
411
|
\`\`\`tsx
|
|
406
412
|
import { useState } from "react";
|
|
407
|
-
import { ${
|
|
413
|
+
import { ${u} } from "./${u}";
|
|
408
414
|
|
|
409
415
|
function MyComponent() {
|
|
410
416
|
const [currentSlide, setCurrentSlide] = useState(0);
|
|
@@ -417,39 +423,39 @@ function MyComponent() {
|
|
|
417
423
|
<button onClick={() => setCurrentSlide((prev) => prev + 1)}>
|
|
418
424
|
Next
|
|
419
425
|
</button>
|
|
420
|
-
<${
|
|
426
|
+
<${u}
|
|
421
427
|
${c.map(
|
|
422
428
|
(i) => i.arrayContainer ? `${i.arrayContainer.propName}={[/* array of items */]}` : ""
|
|
423
429
|
).filter(Boolean).join(`
|
|
424
430
|
`)}
|
|
425
|
-
${
|
|
426
|
-
on${
|
|
431
|
+
${e}CurrentIndex={currentSlide}
|
|
432
|
+
on${C}={(index) => setCurrentSlide(index)}
|
|
427
433
|
/>
|
|
428
434
|
</>
|
|
429
435
|
);
|
|
430
436
|
}
|
|
431
437
|
\`\`\``;
|
|
432
438
|
}
|
|
433
|
-
return `# ${
|
|
439
|
+
return `# ${u}
|
|
434
440
|
|
|
435
441
|
Encore App Wrapper Component
|
|
436
442
|
|
|
437
|
-
This component wraps the Encore Studio app **"${
|
|
443
|
+
This component wraps the Encore Studio app **"${P}"** (App ID: \`${k}\`) for the page **"${E}"** (Page ID: \`${x}\`).
|
|
438
444
|
|
|
439
445
|
The component automatically maps props to data-bound components within the app. Components marked with \`encore:data\` tags are exposed as props, allowing you to dynamically populate content.
|
|
440
446
|
|
|
441
|
-
${
|
|
447
|
+
${S}
|
|
442
448
|
|
|
443
449
|
## Usage
|
|
444
450
|
|
|
445
451
|
\`\`\`tsx
|
|
446
|
-
import { ${
|
|
452
|
+
import { ${u} } from "./${u}";
|
|
447
453
|
|
|
448
454
|
function MyComponent() {
|
|
449
455
|
return (
|
|
450
|
-
<${
|
|
456
|
+
<${u}
|
|
451
457
|
${c.map(
|
|
452
|
-
(
|
|
458
|
+
(t) => t.arrayContainer ? `${t.arrayContainer.propName}={[/* array of items */]}` : ""
|
|
453
459
|
).filter(Boolean).join(`
|
|
454
460
|
`)}
|
|
455
461
|
/>
|
|
@@ -460,52 +466,52 @@ function MyComponent() {
|
|
|
460
466
|
## Example
|
|
461
467
|
|
|
462
468
|
\`\`\`tsx
|
|
463
|
-
${
|
|
469
|
+
${U}
|
|
464
470
|
\`\`\`
|
|
465
471
|
|
|
466
|
-
${
|
|
472
|
+
${B}
|
|
467
473
|
`;
|
|
468
474
|
}
|
|
469
|
-
function
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}),
|
|
474
|
-
const
|
|
475
|
-
|
|
475
|
+
function Y(k, x, P, E, u, c, N, v) {
|
|
476
|
+
const l = [], d = [], I = m(x);
|
|
477
|
+
E.forEach((a) => {
|
|
478
|
+
l.push(a.propName);
|
|
479
|
+
}), u.forEach((a) => {
|
|
480
|
+
const p = m(a.groupName);
|
|
481
|
+
l.push(p), d.push(`on${p[0].toUpperCase()}${p.slice(1)}Change`);
|
|
476
482
|
}), c.forEach((a) => {
|
|
477
|
-
const
|
|
483
|
+
const p = m(a.formName);
|
|
478
484
|
d.push(
|
|
479
|
-
`on${
|
|
485
|
+
`on${p[0].toUpperCase()}${p.slice(1)}Submit`
|
|
480
486
|
);
|
|
481
|
-
}),
|
|
482
|
-
const
|
|
483
|
-
|
|
487
|
+
}), N.forEach((a) => {
|
|
488
|
+
const p = a.propName, f = p[0].toUpperCase() + p.slice(1);
|
|
489
|
+
l.push(p), l.push(`${p}Options`), d.push(`on${f}Change`);
|
|
490
|
+
}), v.forEach((a) => {
|
|
491
|
+
const p = a.propName, f = p[0].toUpperCase() + p.slice(1);
|
|
492
|
+
d.push(`on${f}Click`);
|
|
484
493
|
}), P.forEach((a) => {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}), y.forEach((a) => {
|
|
488
|
-
a.arrayContainer && a.arrayContainer.components.length > 0 && h.push(a.arrayContainer.propName);
|
|
489
|
-
const r = l(a.name || "container"), u = `${r[0].toUpperCase()}${r.slice(
|
|
494
|
+
a.arrayContainer && a.arrayContainer.components.length > 0 && l.push(a.arrayContainer.propName);
|
|
495
|
+
const p = m(a.name || "container"), f = `${p[0].toUpperCase()}${p.slice(
|
|
490
496
|
1
|
|
491
497
|
)}IndexChange`;
|
|
492
|
-
|
|
498
|
+
l.push(`${p}CurrentIndex`), d.push(`on${f}`);
|
|
493
499
|
});
|
|
494
|
-
const
|
|
495
|
-
${
|
|
500
|
+
const y = `<${I}
|
|
501
|
+
${l.map((a) => `${a}={${a}}`).join(`
|
|
496
502
|
`)}
|
|
497
503
|
${d.map((a) => `${a}={${a}}`).join(`
|
|
498
504
|
`)}
|
|
499
505
|
/>`;
|
|
500
506
|
return {
|
|
501
|
-
props:
|
|
507
|
+
props: l,
|
|
502
508
|
events: d,
|
|
503
|
-
jsx:
|
|
509
|
+
jsx: y
|
|
504
510
|
};
|
|
505
511
|
}
|
|
506
512
|
export {
|
|
507
513
|
K as generateComponentCode,
|
|
508
|
-
|
|
514
|
+
Y as generateComponentMetadata,
|
|
509
515
|
L as generateReadme
|
|
510
516
|
};
|
|
511
517
|
//# sourceMappingURL=generator.js.map
|