@bravostudioai/react 0.1.0 → 0.1.2
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/_virtual/main.js +3 -2
- package/dist/cli/commands/generate.js +161 -1438
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/codegen/generator.js +473 -0
- package/dist/codegen/generator.js.map +1 -0
- package/dist/codegen/parser.js +720 -0
- package/dist/codegen/parser.js.map +1 -0
- package/dist/components/EncoreApp.js +197 -162
- package/dist/components/EncoreApp.js.map +1 -1
- package/dist/contexts/EncoreRouterContext.js +13 -0
- package/dist/contexts/EncoreRouterContext.js.map +1 -0
- package/dist/hooks/usePusherUpdates.js +4 -2
- package/dist/hooks/usePusherUpdates.js.map +1 -1
- package/dist/lib/dynamicModules.js +75 -85
- package/dist/lib/dynamicModules.js.map +1 -1
- package/dist/lib/moduleRegistry.js +20 -0
- package/dist/lib/moduleRegistry.js.map +1 -0
- package/dist/lib/packages.js +1 -3
- package/dist/lib/packages.js.map +1 -1
- package/dist/src/cli/commands/generate.d.ts.map +1 -1
- package/dist/src/codegen/generator.d.ts +10 -0
- package/dist/src/codegen/generator.d.ts.map +1 -0
- package/dist/src/codegen/index.d.ts +4 -0
- package/dist/src/codegen/index.d.ts.map +1 -0
- package/dist/src/codegen/parser.d.ts +37 -0
- package/dist/src/codegen/parser.d.ts.map +1 -0
- package/dist/src/codegen/types.d.ts +53 -0
- package/dist/src/codegen/types.d.ts.map +1 -0
- package/dist/src/components/EncoreApp.d.ts +5 -1
- package/dist/src/components/EncoreApp.d.ts.map +1 -1
- package/dist/src/contexts/EncoreRouterContext.d.ts +10 -0
- package/dist/src/contexts/EncoreRouterContext.d.ts.map +1 -0
- package/dist/src/hooks/useAuthRedirect.d.ts.map +1 -1
- package/dist/src/lib/dynamicModules.d.ts +1 -5
- package/dist/src/lib/dynamicModules.d.ts.map +1 -1
- package/dist/src/lib/moduleRegistry.d.ts +9 -0
- package/dist/src/lib/moduleRegistry.d.ts.map +1 -0
- package/dist/src/lib/packages.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/generate.ts +88 -2723
- package/src/codegen/generator.ts +877 -0
- package/src/codegen/index.ts +3 -0
- package/src/codegen/parser.ts +1614 -0
- package/src/codegen/types.ts +58 -0
- package/src/components/EncoreApp.tsx +75 -22
- package/src/contexts/EncoreRouterContext.ts +28 -0
- package/src/hooks/useAuthRedirect.ts +56 -55
- package/src/lib/packages.ts +8 -15
|
@@ -1,1465 +1,191 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join as
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
ne.
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { promises as M, existsSync as R } from "fs";
|
|
2
|
+
import { join as c, dirname as k } from "path";
|
|
3
|
+
import { m as W } from "../../_virtual/main.js";
|
|
4
|
+
import { CONST_APPS_SERVICE_URL as Y, CONST_COMPONENTS_CDN_URL as q } from "../../packages/encore-lib/constants.js";
|
|
5
|
+
import { findSlidersAndDataBindings as z, findStandaloneComponents as X, findInputGroups as Z, findForms as H, qualifyFormInputs as Q, findStandaloneSelectInputs as ee, findActionButtons as te, sanitizePropName as L } from "../../codegen/parser.js";
|
|
6
|
+
import { generateComponentCode as oe, generateReadme as ne } from "../../codegen/generator.js";
|
|
7
|
+
const { writeFile: C, mkdir: T, readFile: $ } = M;
|
|
8
|
+
W.config();
|
|
9
|
+
const S = process.env.APPS_SERVICE_URL || process.env.VITE_APPS_SERVICE_URL || Y;
|
|
10
|
+
console.log(`Using APPS_SERVICE_URL: ${S}`);
|
|
11
|
+
const ae = q;
|
|
12
|
+
async function _(o, n) {
|
|
13
|
+
const t = await fetch(o, {
|
|
14
|
+
headers: n || {}
|
|
15
|
+
});
|
|
16
|
+
if (!t.ok)
|
|
15
17
|
throw new Error(
|
|
16
|
-
`Failed to download ${
|
|
17
|
-
);
|
|
18
|
-
return await o.text();
|
|
19
|
-
}
|
|
20
|
-
function M(h) {
|
|
21
|
-
const l = h.replace(/[^a-zA-Z0-9\s]/g, "").trim();
|
|
22
|
-
return l ? l.split(/\s+/).map((o, d) => {
|
|
23
|
-
if (!o) return "";
|
|
24
|
-
const e = o === o.toUpperCase() && o.length > 1 ? o.toLowerCase() : o, p = e.charAt(0), n = e.slice(1);
|
|
25
|
-
return d === 0 ? p.toLowerCase() + n : p.toUpperCase() + n;
|
|
26
|
-
}).join("").replace(/^[0-9]/, "_$&") : "item";
|
|
27
|
-
}
|
|
28
|
-
function L(h, l) {
|
|
29
|
-
const o = M(h);
|
|
30
|
-
if (l.length === 0)
|
|
31
|
-
return o;
|
|
32
|
-
const d = l.filter((n) => n && n.trim()).reverse();
|
|
33
|
-
return d.length === 0 ? o : d.map(
|
|
34
|
-
(n) => M(n)
|
|
35
|
-
).map((n) => n.charAt(0).toUpperCase() + n.slice(1)).join("") + o;
|
|
36
|
-
}
|
|
37
|
-
function z(h, l) {
|
|
38
|
-
if (l.length === 0)
|
|
39
|
-
return [];
|
|
40
|
-
let o = 0;
|
|
41
|
-
const d = Math.min(
|
|
42
|
-
h.length,
|
|
43
|
-
...l.map((p) => p.length)
|
|
44
|
-
);
|
|
45
|
-
for (let p = 0; p < d; p++) {
|
|
46
|
-
const n = h[p];
|
|
47
|
-
if (l.every((g) => g[p] === n))
|
|
48
|
-
o++;
|
|
49
|
-
else
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
const e = h.slice(o);
|
|
53
|
-
for (let p = 1; p <= e.length; p++) {
|
|
54
|
-
const n = e.slice(0, p);
|
|
55
|
-
if (l.every((g) => {
|
|
56
|
-
if (g.length < o + p)
|
|
57
|
-
return !0;
|
|
58
|
-
const c = g.slice(
|
|
59
|
-
o,
|
|
60
|
-
o + p
|
|
61
|
-
);
|
|
62
|
-
return !Q(n, c);
|
|
63
|
-
}))
|
|
64
|
-
return n;
|
|
65
|
-
}
|
|
66
|
-
return e;
|
|
67
|
-
}
|
|
68
|
-
function Q(h, l) {
|
|
69
|
-
return h.length !== l.length ? !1 : h.every((o, d) => o === l[d]);
|
|
70
|
-
}
|
|
71
|
-
function J(h, l) {
|
|
72
|
-
return h === "component:image" || h === "component:text" || h?.startsWith("component:input-") ? "string" : "any";
|
|
73
|
-
}
|
|
74
|
-
function Y(h) {
|
|
75
|
-
return h === "component:image" ? "imageUrl" : h === "component:text" ? "text" : "value";
|
|
76
|
-
}
|
|
77
|
-
function ie(h) {
|
|
78
|
-
const l = [];
|
|
79
|
-
function o(e, p = []) {
|
|
80
|
-
if (!(!e || typeof e != "object")) {
|
|
81
|
-
if (e.type === "container:slider") {
|
|
82
|
-
let n = function(c) {
|
|
83
|
-
if (!g && !(!c || typeof c != "object")) {
|
|
84
|
-
if (Array.isArray(c.tags) && (c.tags.includes("encore:data:array") || c.tags.includes("bravo:data:array"))) {
|
|
85
|
-
g = c;
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
c.body && Array.isArray(c.body) && c.body.forEach(n), c.containers && Array.isArray(c.containers) && c.containers.forEach(n), c.components && Array.isArray(c.components) && c.components.forEach(n);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
const i = {
|
|
92
|
-
id: e.id,
|
|
93
|
-
name: e.name || "Slider",
|
|
94
|
-
arrayContainer: null
|
|
95
|
-
};
|
|
96
|
-
let g = null;
|
|
97
|
-
if (e.containers && Array.isArray(e.containers) && e.containers.forEach(n), !g && e.components && Array.isArray(e.components) && e.components.forEach(n), g) {
|
|
98
|
-
let c = function(f, $ = []) {
|
|
99
|
-
if (!f || typeof f != "object") return;
|
|
100
|
-
if (f.type === "component:image" && N.push(f), Array.isArray(f.tags) && (f.tags.includes("encore:data") || f.tags.includes("bravo:data"))) {
|
|
101
|
-
const x = M(f.name || "item"), _ = J(f.type, f.name);
|
|
102
|
-
m.push({
|
|
103
|
-
id: f.id,
|
|
104
|
-
name: f.name || "Unnamed",
|
|
105
|
-
type: f.type,
|
|
106
|
-
tags: f.tags || [],
|
|
107
|
-
propName: x,
|
|
108
|
-
// Will be qualified later if needed
|
|
109
|
-
propType: _,
|
|
110
|
-
// Store parent path for later qualification
|
|
111
|
-
_parentPath: [...$]
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
const A = [...$];
|
|
115
|
-
if (f.name && (f.type?.startsWith("container:") || f.type?.startsWith("component:"))) {
|
|
116
|
-
const x = f.name.trim(), _ = /^frame\s*\d*$/i.test(x) || x.toUpperCase() === "FRAME";
|
|
117
|
-
x && !_ && A.push(f.name);
|
|
118
|
-
}
|
|
119
|
-
f.components && Array.isArray(f.components) && f.components.forEach(
|
|
120
|
-
(x) => c(x, A)
|
|
121
|
-
);
|
|
122
|
-
};
|
|
123
|
-
const y = g;
|
|
124
|
-
let m = [];
|
|
125
|
-
const N = [];
|
|
126
|
-
if (y.components && Array.isArray(y.components) && y.components.forEach(
|
|
127
|
-
(f) => c(f, [])
|
|
128
|
-
), !m.some(
|
|
129
|
-
(f) => f.type === "component:image"
|
|
130
|
-
) && N.length > 0) {
|
|
131
|
-
const f = N[0], A = (f.name || "image").toLowerCase().includes("image") ? "imageUrl" : M(f.name || "image");
|
|
132
|
-
m.push({
|
|
133
|
-
id: f.id,
|
|
134
|
-
name: f.name || "Image",
|
|
135
|
-
type: f.type,
|
|
136
|
-
tags: f.tags || [],
|
|
137
|
-
propName: A,
|
|
138
|
-
// Will be qualified later if needed
|
|
139
|
-
propType: "string",
|
|
140
|
-
// imageUrl is always string
|
|
141
|
-
_parentPath: []
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
const C = /* @__PURE__ */ new Map();
|
|
145
|
-
if (m.forEach((f) => {
|
|
146
|
-
const $ = f, A = f.propName;
|
|
147
|
-
C.has(A) || C.set(A, []), C.get(A).push($);
|
|
148
|
-
}), C.forEach((f, $) => {
|
|
149
|
-
if (f.length === 1)
|
|
150
|
-
return;
|
|
151
|
-
f.forEach((v) => {
|
|
152
|
-
const U = f.filter((w) => w.id !== v.id).map((w) => w._parentPath || []), j = z(
|
|
153
|
-
v._parentPath || [],
|
|
154
|
-
U
|
|
155
|
-
);
|
|
156
|
-
v.propName = L(
|
|
157
|
-
v.name || "item",
|
|
158
|
-
j
|
|
159
|
-
);
|
|
160
|
-
});
|
|
161
|
-
let A = !0, x = 0;
|
|
162
|
-
const _ = 10;
|
|
163
|
-
for (; A && x < _; ) {
|
|
164
|
-
x++;
|
|
165
|
-
const v = /* @__PURE__ */ new Map();
|
|
166
|
-
f.forEach((U) => {
|
|
167
|
-
v.has(U.propName) || v.set(U.propName, []), v.get(U.propName).push(U);
|
|
168
|
-
}), A = !1, v.forEach((U, j) => {
|
|
169
|
-
U.length > 1 && (A = !0, U.forEach((w) => {
|
|
170
|
-
const T = w._parentPath || [], a = U.filter((t) => t.id !== w.id).map((t) => t._parentPath || []);
|
|
171
|
-
let b = 0;
|
|
172
|
-
const D = Math.min(
|
|
173
|
-
T.length,
|
|
174
|
-
...a.map((t) => t.length)
|
|
175
|
-
);
|
|
176
|
-
for (let t = 0; t < D; t++) {
|
|
177
|
-
const u = T[t];
|
|
178
|
-
if (a.every((I) => I[t] === u))
|
|
179
|
-
b++;
|
|
180
|
-
else
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
const s = T.slice(b);
|
|
184
|
-
let E = !1;
|
|
185
|
-
for (let t = 1; t <= s.length; t++) {
|
|
186
|
-
const u = s.slice(
|
|
187
|
-
0,
|
|
188
|
-
t
|
|
189
|
-
), P = L(
|
|
190
|
-
w.name || "item",
|
|
191
|
-
u
|
|
192
|
-
);
|
|
193
|
-
if (m.every((F) => {
|
|
194
|
-
if (F.id === w.id) return !0;
|
|
195
|
-
if (U.some((O) => O.id === F.id)) {
|
|
196
|
-
const O = F._parentPath || [], W = Math.min(
|
|
197
|
-
b,
|
|
198
|
-
O.length
|
|
199
|
-
), ee = O.slice(
|
|
200
|
-
W
|
|
201
|
-
).slice(0, t), te = L(
|
|
202
|
-
F.name || "item",
|
|
203
|
-
ee
|
|
204
|
-
);
|
|
205
|
-
return P !== te;
|
|
206
|
-
}
|
|
207
|
-
return P !== F.propName;
|
|
208
|
-
})) {
|
|
209
|
-
w.propName = P, E = !0;
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
E || (w.propName = L(
|
|
214
|
-
w.name || "item",
|
|
215
|
-
s.length > 0 ? s : []
|
|
216
|
-
));
|
|
217
|
-
}));
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
const S = /* @__PURE__ */ new Map();
|
|
221
|
-
f.forEach((v) => {
|
|
222
|
-
S.has(v.propName) || S.set(v.propName, []), S.get(v.propName).push(v);
|
|
223
|
-
}), S.forEach(
|
|
224
|
-
(v, U) => {
|
|
225
|
-
if (v.length > 1 && v.every((w) => {
|
|
226
|
-
const T = w._parentPath || [];
|
|
227
|
-
return v.every((a) => {
|
|
228
|
-
if (a.id === w.id) return !0;
|
|
229
|
-
const b = a._parentPath || [];
|
|
230
|
-
return Q(T, b);
|
|
231
|
-
});
|
|
232
|
-
})) {
|
|
233
|
-
let w = 0;
|
|
234
|
-
v.forEach((T) => {
|
|
235
|
-
w > 0 && (T.propName = `${U}${w + 1}`), w++;
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
), f.forEach((v) => {
|
|
240
|
-
delete v._parentPath;
|
|
241
|
-
});
|
|
242
|
-
}), N.length > 0) {
|
|
243
|
-
const $ = (N[0].name || "").toLowerCase();
|
|
244
|
-
m = m.filter((A) => {
|
|
245
|
-
if (A.type === "component:image") return !0;
|
|
246
|
-
if (A.type === "component:color") {
|
|
247
|
-
const x = (A.name || "").toLowerCase();
|
|
248
|
-
if ($.includes(x) || x.includes("image"))
|
|
249
|
-
return !1;
|
|
250
|
-
}
|
|
251
|
-
return !0;
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
i.arrayContainer = {
|
|
255
|
-
id: y.id,
|
|
256
|
-
name: y.name || "Item",
|
|
257
|
-
propName: M(y.name || "items"),
|
|
258
|
-
components: m
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
l.push(i);
|
|
262
|
-
}
|
|
263
|
-
e.body && Array.isArray(e.body) && e.body.forEach((n) => o(n, [...p, "body"])), e.containers && Array.isArray(e.containers) && e.containers.forEach(
|
|
264
|
-
(n) => o(n, [...p, "containers"])
|
|
265
|
-
), e.components && Array.isArray(e.components) && e.components.forEach(
|
|
266
|
-
(n) => o(n, [...p, "components"])
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
const d = h.data?.body || h.body || h.data?.body || [];
|
|
271
|
-
return Array.isArray(d) && d.length > 0 && d.forEach((e) => o(e)), l;
|
|
272
|
-
}
|
|
273
|
-
function pe(h) {
|
|
274
|
-
const l = [], o = /* @__PURE__ */ new Set();
|
|
275
|
-
function d(i) {
|
|
276
|
-
!i || typeof i != "object" || (i.type === "container:slider" && o.add(i.id), i.body && Array.isArray(i.body) && i.body.forEach(d), i.containers && Array.isArray(i.containers) && i.containers.forEach(d));
|
|
277
|
-
}
|
|
278
|
-
function e(i, g, c = []) {
|
|
279
|
-
if (!i || typeof i != "object" || g && o.has(g)) return;
|
|
280
|
-
if (Array.isArray(i.tags) && (i.tags.includes("encore:data") || i.tags.includes("bravo:data")) && (i.type === "component:text" || i.type === "component:image")) {
|
|
281
|
-
const N = M(i.name || "item"), r = J(i.type, i.name);
|
|
282
|
-
l.push({
|
|
283
|
-
id: i.id,
|
|
284
|
-
name: i.name || "Unnamed",
|
|
285
|
-
type: i.type,
|
|
286
|
-
tags: i.tags || [],
|
|
287
|
-
propName: N,
|
|
288
|
-
// Will be qualified later if needed
|
|
289
|
-
propType: r,
|
|
290
|
-
// Store parent path for later qualification
|
|
291
|
-
_parentPath: [...c]
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
const y = [...c];
|
|
295
|
-
if (i.name && (i.type?.startsWith("container:") || i.type?.startsWith("component:"))) {
|
|
296
|
-
const N = i.name.trim(), r = /^frame\s*\d*$/i.test(N) || N.toUpperCase() === "FRAME";
|
|
297
|
-
N && !r && y.push(i.name);
|
|
298
|
-
}
|
|
299
|
-
const m = i.id;
|
|
300
|
-
i.body && Array.isArray(i.body) && i.body.forEach(
|
|
301
|
-
(N) => e(N, m, y)
|
|
302
|
-
), i.containers && Array.isArray(i.containers) && i.containers.forEach(
|
|
303
|
-
(N) => e(N, m, y)
|
|
304
|
-
), i.components && Array.isArray(i.components) && i.components.forEach(
|
|
305
|
-
(N) => e(N, m, y)
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
const p = h.data?.body || h.body || h.data?.body || [];
|
|
309
|
-
Array.isArray(p) && p.length > 0 && (p.forEach(d), p.forEach((i) => e(i)));
|
|
310
|
-
const n = /* @__PURE__ */ new Map();
|
|
311
|
-
return l.forEach((i) => {
|
|
312
|
-
const g = i, c = i.propName;
|
|
313
|
-
n.has(c) || n.set(c, []), n.get(c).push(g);
|
|
314
|
-
}), n.forEach((i, g) => {
|
|
315
|
-
if (i.length === 1)
|
|
316
|
-
return;
|
|
317
|
-
i.forEach((r) => {
|
|
318
|
-
const C = i.filter(($) => $.id !== r.id).map(($) => $._parentPath || []), f = z(
|
|
319
|
-
r._parentPath || [],
|
|
320
|
-
C
|
|
321
|
-
);
|
|
322
|
-
r.propName = L(
|
|
323
|
-
r.name || "item",
|
|
324
|
-
f
|
|
325
|
-
);
|
|
326
|
-
});
|
|
327
|
-
let c = !0, y = 0;
|
|
328
|
-
const m = 10;
|
|
329
|
-
for (; c && y < m; ) {
|
|
330
|
-
y++;
|
|
331
|
-
const r = /* @__PURE__ */ new Map();
|
|
332
|
-
i.forEach((C) => {
|
|
333
|
-
r.has(C.propName) || r.set(C.propName, []), r.get(C.propName).push(C);
|
|
334
|
-
}), c = !1, r.forEach((C, f) => {
|
|
335
|
-
C.length > 1 && (c = !0, C.forEach(($) => {
|
|
336
|
-
const A = $._parentPath || [], x = C.filter((j) => j.id !== $.id).map((j) => j._parentPath || []);
|
|
337
|
-
let _ = 0;
|
|
338
|
-
const S = Math.min(
|
|
339
|
-
A.length,
|
|
340
|
-
...x.map((j) => j.length)
|
|
341
|
-
);
|
|
342
|
-
for (let j = 0; j < S; j++) {
|
|
343
|
-
const w = A[j];
|
|
344
|
-
if (x.every((a) => a[j] === w))
|
|
345
|
-
_++;
|
|
346
|
-
else
|
|
347
|
-
break;
|
|
348
|
-
}
|
|
349
|
-
const v = A.slice(_);
|
|
350
|
-
let U = !1;
|
|
351
|
-
for (let j = 1; j <= v.length; j++) {
|
|
352
|
-
const w = v.slice(0, j), T = L(
|
|
353
|
-
$.name || "item",
|
|
354
|
-
w
|
|
355
|
-
);
|
|
356
|
-
if (l.every((b) => {
|
|
357
|
-
if (b.id === $.id) return !0;
|
|
358
|
-
if (C.some((D) => D.id === b.id)) {
|
|
359
|
-
const D = b._parentPath || [], s = Math.min(
|
|
360
|
-
_,
|
|
361
|
-
D.length
|
|
362
|
-
), t = D.slice(
|
|
363
|
-
s
|
|
364
|
-
).slice(
|
|
365
|
-
0,
|
|
366
|
-
j
|
|
367
|
-
), u = L(
|
|
368
|
-
b.name || "item",
|
|
369
|
-
t
|
|
370
|
-
);
|
|
371
|
-
return T !== u;
|
|
372
|
-
}
|
|
373
|
-
return T !== b.propName;
|
|
374
|
-
})) {
|
|
375
|
-
$.propName = T, U = !0;
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
U || ($.propName = L(
|
|
380
|
-
$.name || "item",
|
|
381
|
-
A
|
|
382
|
-
));
|
|
383
|
-
}));
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
const N = /* @__PURE__ */ new Map();
|
|
387
|
-
i.forEach((r) => {
|
|
388
|
-
N.has(r.propName) || N.set(r.propName, []), N.get(r.propName).push(r);
|
|
389
|
-
}), N.forEach((r, C) => {
|
|
390
|
-
if (r.length > 1 && r.every(($) => {
|
|
391
|
-
const A = $._parentPath || [];
|
|
392
|
-
return r.every((x) => {
|
|
393
|
-
if (x.id === $.id) return !0;
|
|
394
|
-
const _ = x._parentPath || [];
|
|
395
|
-
return Q(A, _);
|
|
396
|
-
});
|
|
397
|
-
})) {
|
|
398
|
-
let $ = 0;
|
|
399
|
-
r.forEach((A) => {
|
|
400
|
-
$ > 0 && (A.propName = `${C}${$ + 1}`), $++;
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
}), i.forEach((r) => {
|
|
404
|
-
delete r._parentPath;
|
|
405
|
-
});
|
|
406
|
-
}), l;
|
|
407
|
-
}
|
|
408
|
-
function ce(h) {
|
|
409
|
-
const l = /* @__PURE__ */ new Map();
|
|
410
|
-
function o(e) {
|
|
411
|
-
if (!(!e || typeof e != "object")) {
|
|
412
|
-
if (e.type === "component:input-stateful-set" && Array.isArray(e.tags)) {
|
|
413
|
-
const p = e.tags.find(
|
|
414
|
-
(n) => n.startsWith("input-group:")
|
|
415
|
-
);
|
|
416
|
-
if (p) {
|
|
417
|
-
const n = p.split(":");
|
|
418
|
-
if (n.length >= 3) {
|
|
419
|
-
const i = n[1], g = n[2];
|
|
420
|
-
l.has(g) || l.set(g, {
|
|
421
|
-
groupName: g,
|
|
422
|
-
groupType: i,
|
|
423
|
-
elements: []
|
|
424
|
-
}), l.get(g).elements.push({
|
|
425
|
-
id: e.id,
|
|
426
|
-
name: e.name || "Unnamed"
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
e.body && Array.isArray(e.body) && e.body.forEach(o), e.containers && Array.isArray(e.containers) && e.containers.forEach(o), e.components && Array.isArray(e.components) && e.components.forEach(o);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
const d = h.data?.body || h.body || h.data?.body || [];
|
|
435
|
-
return Array.isArray(d) && d.length > 0 && d.forEach((e) => o(e)), Array.from(l.values());
|
|
436
|
-
}
|
|
437
|
-
function le(h) {
|
|
438
|
-
const l = [];
|
|
439
|
-
function o(e, p) {
|
|
440
|
-
if (!e || typeof e != "object") return;
|
|
441
|
-
const n = e.type?.startsWith("container:") || e.type === "container:default", i = e.name?.toLowerCase().includes("form") || Array.isArray(e.tags) && e.tags.includes("form");
|
|
442
|
-
let g = !1, c;
|
|
443
|
-
function y(m) {
|
|
444
|
-
if (!(!m || typeof m != "object")) {
|
|
445
|
-
if (Array.isArray(m.tags) && (m.tags.includes("action:submit") || m.tags.includes("submit"))) {
|
|
446
|
-
g = !0, c = m.id;
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
if (m.actions?.tap?.action === "submit") {
|
|
450
|
-
g = !0, c = m.id;
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
m.components && Array.isArray(m.components) && m.components.forEach(y), m.body && Array.isArray(m.body) && m.body.forEach(y);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
if (n && (i || p === void 0) && y(e), n && (g || i)) {
|
|
457
|
-
let m = function(r, C = []) {
|
|
458
|
-
if (!r || typeof r != "object") return;
|
|
459
|
-
if (r.type?.startsWith("component:input-") || r.type === "component:input-text" || r.type === "component:input-image" || r.type === "component:input-email" || r.type === "component:input-password" || r.type === "component:input-select") {
|
|
460
|
-
const $ = M(r.name || "Unnamed input");
|
|
461
|
-
N.push({
|
|
462
|
-
id: r.id,
|
|
463
|
-
name: r.name || "Unnamed input",
|
|
464
|
-
type: r.type,
|
|
465
|
-
propName: $,
|
|
466
|
-
// Will be qualified later if needed
|
|
467
|
-
_parentPath: [...C]
|
|
468
|
-
// Store parent path for qualification
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
const f = [...C];
|
|
472
|
-
if (r.name && (r.type?.startsWith("container:") || r.type?.startsWith("component:"))) {
|
|
473
|
-
const $ = r.name.trim(), A = /^frame\s*\d*$/i.test($) || $.toUpperCase() === "FRAME";
|
|
474
|
-
$ && !A && f.push(r.name);
|
|
475
|
-
}
|
|
476
|
-
r.components && Array.isArray(r.components) && r.components.forEach(
|
|
477
|
-
($) => m($, f)
|
|
478
|
-
), r.body && Array.isArray(r.body) && r.body.forEach(($) => m($, f));
|
|
479
|
-
};
|
|
480
|
-
const N = [];
|
|
481
|
-
m(e, []), N.length > 0 && l.push({
|
|
482
|
-
formId: e.id,
|
|
483
|
-
formName: e.name || "Form",
|
|
484
|
-
submitButtonId: c,
|
|
485
|
-
inputs: N
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
e.body && Array.isArray(e.body) && e.body.forEach(
|
|
489
|
-
(m) => o(m, n ? e : p)
|
|
490
|
-
), e.containers && Array.isArray(e.containers) && e.containers.forEach(
|
|
491
|
-
(m) => o(m, n ? e : p)
|
|
492
|
-
), e.components && Array.isArray(e.components) && e.components.forEach(
|
|
493
|
-
(m) => o(m, n ? e : p)
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
const d = h.data?.body || h.body || h.data?.body || [];
|
|
497
|
-
return Array.isArray(d) && d.length > 0 && d.forEach((e) => o(e)), l;
|
|
498
|
-
}
|
|
499
|
-
function he(h, l) {
|
|
500
|
-
const o = [], d = /* @__PURE__ */ new Set();
|
|
501
|
-
l.forEach((n) => {
|
|
502
|
-
n.inputs.forEach((i) => {
|
|
503
|
-
d.add(i.id);
|
|
504
|
-
});
|
|
505
|
-
});
|
|
506
|
-
function e(n, i = []) {
|
|
507
|
-
if (!n || typeof n != "object") return;
|
|
508
|
-
if (n.type === "component:input-select" && !d.has(n.id)) {
|
|
509
|
-
const c = M(n.name || "selectInput");
|
|
510
|
-
o.push({
|
|
511
|
-
id: n.id,
|
|
512
|
-
name: n.name || "Select Input",
|
|
513
|
-
propName: c,
|
|
514
|
-
_parentPath: [...i]
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
const g = [...i];
|
|
518
|
-
if (n.name && (n.type?.startsWith("container:") || n.type?.startsWith("component:"))) {
|
|
519
|
-
const c = n.name.trim(), y = /^frame\s*\d*$/i.test(c) || c.toUpperCase() === "FRAME";
|
|
520
|
-
c && !y && g.push(n.name);
|
|
521
|
-
}
|
|
522
|
-
n.body && Array.isArray(n.body) && n.body.forEach((c) => e(c, g)), n.containers && Array.isArray(n.containers) && n.containers.forEach(
|
|
523
|
-
(c) => e(c, g)
|
|
524
|
-
), n.components && Array.isArray(n.components) && n.components.forEach(
|
|
525
|
-
(c) => e(c, g)
|
|
18
|
+
`Failed to download ${o}: ${t.status} ${t.statusText}`
|
|
526
19
|
);
|
|
527
|
-
|
|
528
|
-
const p = h.data?.body || h.body || h.data?.body || [];
|
|
529
|
-
return Array.isArray(p) && p.length > 0 && p.forEach((n) => e(n)), me(o), o;
|
|
530
|
-
}
|
|
531
|
-
function me(h) {
|
|
532
|
-
const l = /* @__PURE__ */ new Map();
|
|
533
|
-
h.forEach((o) => {
|
|
534
|
-
const d = o, e = o.propName;
|
|
535
|
-
l.has(e) || l.set(e, []), l.get(e).push(d);
|
|
536
|
-
}), l.forEach((o, d) => {
|
|
537
|
-
if (o.length === 1) {
|
|
538
|
-
delete o[0]._parentPath;
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
o.forEach((e) => {
|
|
542
|
-
const p = o.filter((i) => i.id !== e.id).map((i) => i._parentPath || []), n = z(
|
|
543
|
-
e._parentPath || [],
|
|
544
|
-
p
|
|
545
|
-
);
|
|
546
|
-
e.propName = L(
|
|
547
|
-
e.name || "input",
|
|
548
|
-
n
|
|
549
|
-
);
|
|
550
|
-
}), o.forEach((e) => {
|
|
551
|
-
delete e._parentPath;
|
|
552
|
-
});
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
function fe(h) {
|
|
556
|
-
const l = [];
|
|
557
|
-
function o(e, p = []) {
|
|
558
|
-
if (!e || typeof e != "object") return;
|
|
559
|
-
const n = Array.isArray(e.tags) && e.tags.some((c) => c.startsWith("action:")), i = e.actions && typeof e.actions == "object";
|
|
560
|
-
if (n || i) {
|
|
561
|
-
let c = "tap";
|
|
562
|
-
if (Array.isArray(e.tags)) {
|
|
563
|
-
const m = e.tags.find(
|
|
564
|
-
(N) => N.startsWith("action:")
|
|
565
|
-
);
|
|
566
|
-
m && (c = m.replace("action:", ""));
|
|
567
|
-
}
|
|
568
|
-
e.actions?.tap?.action && (c = e.actions.tap.action);
|
|
569
|
-
const y = M(e.name || "button");
|
|
570
|
-
l.push({
|
|
571
|
-
id: e.id,
|
|
572
|
-
name: e.name || "Button",
|
|
573
|
-
propName: y,
|
|
574
|
-
actionType: c,
|
|
575
|
-
_parentPath: [...p]
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
const g = [...p];
|
|
579
|
-
if (e.name && (e.type?.startsWith("container:") || e.type?.startsWith("component:"))) {
|
|
580
|
-
const c = e.name.trim(), y = /^frame\s*\d*$/i.test(c) || c.toUpperCase() === "FRAME";
|
|
581
|
-
c && !y && g.push(e.name);
|
|
582
|
-
}
|
|
583
|
-
e.body && Array.isArray(e.body) && e.body.forEach((c) => o(c, g)), e.containers && Array.isArray(e.containers) && e.containers.forEach(
|
|
584
|
-
(c) => o(c, g)
|
|
585
|
-
), e.components && Array.isArray(e.components) && e.components.forEach(
|
|
586
|
-
(c) => o(c, g)
|
|
587
|
-
);
|
|
588
|
-
}
|
|
589
|
-
const d = h.data?.body || h.body || h.data?.body || [];
|
|
590
|
-
return Array.isArray(d) && d.length > 0 && d.forEach((e) => o(e)), ue(l), l;
|
|
591
|
-
}
|
|
592
|
-
function ue(h) {
|
|
593
|
-
const l = /* @__PURE__ */ new Map();
|
|
594
|
-
h.forEach((o) => {
|
|
595
|
-
const d = o, e = o.propName;
|
|
596
|
-
l.has(e) || l.set(e, []), l.get(e).push(d);
|
|
597
|
-
}), l.forEach((o, d) => {
|
|
598
|
-
if (o.length === 1) {
|
|
599
|
-
delete o[0]._parentPath;
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
o.forEach((e) => {
|
|
603
|
-
const p = o.filter((i) => i.id !== e.id).map((i) => i._parentPath || []), n = z(
|
|
604
|
-
e._parentPath || [],
|
|
605
|
-
p
|
|
606
|
-
);
|
|
607
|
-
e.propName = L(
|
|
608
|
-
e.name || "button",
|
|
609
|
-
n
|
|
610
|
-
);
|
|
611
|
-
}), o.forEach((e) => {
|
|
612
|
-
delete e._parentPath;
|
|
613
|
-
});
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
function de(h) {
|
|
617
|
-
h.forEach((l) => {
|
|
618
|
-
const o = l.inputs, d = /* @__PURE__ */ new Map();
|
|
619
|
-
o.forEach((e) => {
|
|
620
|
-
const p = e, n = e.propName;
|
|
621
|
-
d.has(n) || d.set(n, []), d.get(n).push(p);
|
|
622
|
-
}), d.forEach((e, p) => {
|
|
623
|
-
if (e.length === 1) {
|
|
624
|
-
delete e[0]._parentPath;
|
|
625
|
-
return;
|
|
626
|
-
}
|
|
627
|
-
e.forEach((y) => {
|
|
628
|
-
const m = e.filter((r) => r.id !== y.id).map((r) => r._parentPath || []), N = z(
|
|
629
|
-
y._parentPath || [],
|
|
630
|
-
m
|
|
631
|
-
);
|
|
632
|
-
y.propName = L(
|
|
633
|
-
y.name || "input",
|
|
634
|
-
N
|
|
635
|
-
);
|
|
636
|
-
});
|
|
637
|
-
let n = !0, i = 0;
|
|
638
|
-
const g = 10;
|
|
639
|
-
for (; n && i < g; ) {
|
|
640
|
-
i++;
|
|
641
|
-
const y = /* @__PURE__ */ new Map();
|
|
642
|
-
e.forEach((m) => {
|
|
643
|
-
y.has(m.propName) || y.set(m.propName, []), y.get(m.propName).push(m);
|
|
644
|
-
}), n = !1, y.forEach((m, N) => {
|
|
645
|
-
m.length > 1 && (n = !0, m.forEach((r) => {
|
|
646
|
-
const C = r._parentPath || [], f = m.filter((S) => S.id !== r.id).map((S) => S._parentPath || []);
|
|
647
|
-
let $ = 0;
|
|
648
|
-
const A = Math.min(
|
|
649
|
-
C.length,
|
|
650
|
-
...f.map((S) => S.length)
|
|
651
|
-
);
|
|
652
|
-
for (let S = 0; S < A; S++) {
|
|
653
|
-
const v = C[S];
|
|
654
|
-
if (f.every((j) => j[S] === v))
|
|
655
|
-
$++;
|
|
656
|
-
else
|
|
657
|
-
break;
|
|
658
|
-
}
|
|
659
|
-
const x = C.slice($);
|
|
660
|
-
let _ = !1;
|
|
661
|
-
for (let S = 1; S <= x.length; S++) {
|
|
662
|
-
const v = x.slice(
|
|
663
|
-
0,
|
|
664
|
-
S
|
|
665
|
-
), U = L(
|
|
666
|
-
r.name || "input",
|
|
667
|
-
v
|
|
668
|
-
);
|
|
669
|
-
if (o.every((w) => {
|
|
670
|
-
if (w.id === r.id) return !0;
|
|
671
|
-
if (m.some((T) => T.id === w.id)) {
|
|
672
|
-
const T = w._parentPath || [], a = Math.min(
|
|
673
|
-
$,
|
|
674
|
-
T.length
|
|
675
|
-
), D = T.slice(
|
|
676
|
-
a
|
|
677
|
-
).slice(
|
|
678
|
-
0,
|
|
679
|
-
S
|
|
680
|
-
), s = L(
|
|
681
|
-
w.name || "input",
|
|
682
|
-
D
|
|
683
|
-
);
|
|
684
|
-
return U !== s;
|
|
685
|
-
}
|
|
686
|
-
return U !== w.propName;
|
|
687
|
-
})) {
|
|
688
|
-
r.propName = U, _ = !0;
|
|
689
|
-
break;
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
_ || (r.propName = L(
|
|
693
|
-
r.name || "input",
|
|
694
|
-
x.length > 0 ? x : []
|
|
695
|
-
));
|
|
696
|
-
}));
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
const c = /* @__PURE__ */ new Map();
|
|
700
|
-
e.forEach((y) => {
|
|
701
|
-
c.has(y.propName) || c.set(y.propName, []), c.get(y.propName).push(y);
|
|
702
|
-
}), c.forEach((y, m) => {
|
|
703
|
-
if (y.length > 1 && y.every((r) => {
|
|
704
|
-
const C = r._parentPath || [];
|
|
705
|
-
return y.every((f) => {
|
|
706
|
-
if (f.id === r.id) return !0;
|
|
707
|
-
const $ = f._parentPath || [];
|
|
708
|
-
return Q(C, $);
|
|
709
|
-
});
|
|
710
|
-
})) {
|
|
711
|
-
let r = 0;
|
|
712
|
-
y.forEach((C) => {
|
|
713
|
-
r > 0 && (C.propName = `${m}${r + 1}`), r++;
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
}), e.forEach((y) => {
|
|
717
|
-
delete y._parentPath;
|
|
718
|
-
});
|
|
719
|
-
});
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
function ge(h, l, o, d, e, p, n, i, g, c = !1) {
|
|
723
|
-
const y = [], m = [], N = [], r = [], C = [], f = [];
|
|
724
|
-
e.forEach((t) => {
|
|
725
|
-
y.push(` ${t.propName}?: ${t.propType};`);
|
|
726
|
-
}), p.forEach((t) => {
|
|
727
|
-
const u = M(t.groupName);
|
|
728
|
-
N.push(` ${u}?: string;`), N.push(
|
|
729
|
-
` on${u[0].toUpperCase()}${u.slice(
|
|
730
|
-
1
|
|
731
|
-
)}Change?: (value: string) => void;`
|
|
732
|
-
);
|
|
733
|
-
});
|
|
734
|
-
const $ = [];
|
|
735
|
-
n.forEach((t) => {
|
|
736
|
-
const u = M(t.formName), P = `${u[0].toUpperCase()}${u.slice(
|
|
737
|
-
1
|
|
738
|
-
)}FormData`, I = [];
|
|
739
|
-
t.inputs.forEach((F) => {
|
|
740
|
-
const O = F.propName, W = J(F.type, F.name);
|
|
741
|
-
I.push(` ${O}: ${W};`);
|
|
742
|
-
}), $.push(`export interface ${P} {
|
|
743
|
-
${I.join(`
|
|
744
|
-
`)}
|
|
745
|
-
}`), r.push(
|
|
746
|
-
` on${u[0].toUpperCase()}${u.slice(
|
|
747
|
-
1
|
|
748
|
-
)}Submit?: (formData: ${P}) => void;`
|
|
749
|
-
);
|
|
750
|
-
}), i.forEach((t) => {
|
|
751
|
-
const u = t.propName, P = u[0].toUpperCase() + u.slice(1);
|
|
752
|
-
C.push(` ${u}?: string;`), C.push(
|
|
753
|
-
` ${u}Options?: Array<string | { value: string; label: string }>;`
|
|
754
|
-
), C.push(
|
|
755
|
-
` on${P}Change?: (value: string) => void;`
|
|
756
|
-
);
|
|
757
|
-
}), g.forEach((t) => {
|
|
758
|
-
const u = t.propName, P = u[0].toUpperCase() + u.slice(1);
|
|
759
|
-
f.push(` on${P}Click?: () => void;`);
|
|
760
|
-
}), d.forEach((t) => {
|
|
761
|
-
if (t.arrayContainer && t.arrayContainer.components.length > 0) {
|
|
762
|
-
const P = t.arrayContainer, I = `${P.propName[0].toUpperCase()}${P.propName.slice(
|
|
763
|
-
1
|
|
764
|
-
)}Item`;
|
|
765
|
-
y.push(` ${P.propName}: ${I}[];`);
|
|
766
|
-
}
|
|
767
|
-
const u = M(t.name || "container");
|
|
768
|
-
m.push(` ${u}CurrentIndex?: number;`), m.push(
|
|
769
|
-
` on${u[0].toUpperCase()}${u.slice(
|
|
770
|
-
1
|
|
771
|
-
)}IndexChange?: (index: number) => void;`
|
|
772
|
-
);
|
|
773
|
-
});
|
|
774
|
-
const A = [
|
|
775
|
-
...y,
|
|
776
|
-
...m,
|
|
777
|
-
...N,
|
|
778
|
-
...r,
|
|
779
|
-
...C,
|
|
780
|
-
...f
|
|
781
|
-
], x = A.length > 0, _ = x ? `export interface ${o}Props {
|
|
782
|
-
${A.join(`
|
|
783
|
-
`)}
|
|
784
|
-
}` : "", S = d.filter((t) => t.arrayContainer && t.arrayContainer.components.length > 0).map((t) => {
|
|
785
|
-
const u = t.arrayContainer, P = `${u.propName[0].toUpperCase()}${u.propName.slice(
|
|
786
|
-
1
|
|
787
|
-
)}Item`, I = u.components.map((F) => ` ${F.propName}: ${F.propType};`).join(`
|
|
788
|
-
`);
|
|
789
|
-
return `export interface ${P} {
|
|
790
|
-
${I}
|
|
791
|
-
}`;
|
|
792
|
-
}).join(`
|
|
793
|
-
|
|
794
|
-
`), v = $.join(`
|
|
795
|
-
|
|
796
|
-
`), U = [], j = [];
|
|
797
|
-
e.forEach((t) => {
|
|
798
|
-
const u = Y(t.type);
|
|
799
|
-
U.push(` // ${t.name}
|
|
800
|
-
...(props.${t.propName} !== undefined && { "${t.id}": { ${u}: props.${t.propName} } as any }),`);
|
|
801
|
-
}), i.forEach((t) => {
|
|
802
|
-
U.push(` // ${t.name}
|
|
803
|
-
...((props.${t.propName} !== undefined || props.${t.propName}Options !== undefined) && {
|
|
804
|
-
"${t.id}": {
|
|
805
|
-
...(props.${t.propName} !== undefined && { value: props.${t.propName} }),
|
|
806
|
-
...(props.${t.propName}Options !== undefined && { options: props.${t.propName}Options }),
|
|
807
|
-
} as any
|
|
808
|
-
}),`);
|
|
809
|
-
}), d.forEach((t) => {
|
|
810
|
-
if (t.arrayContainer && t.arrayContainer.components.length > 0) {
|
|
811
|
-
const F = t.arrayContainer, O = F.components.map((W) => {
|
|
812
|
-
const K = Y(W.type);
|
|
813
|
-
return ` // ${W.name}
|
|
814
|
-
"${W.id}": {
|
|
815
|
-
${K}: item.${W.propName},
|
|
816
|
-
}`;
|
|
817
|
-
}).join(`,
|
|
818
|
-
`);
|
|
819
|
-
U.push(` // ${F.name}
|
|
820
|
-
"${F.id}": props.${F.propName}.map((item) => ({
|
|
821
|
-
${O}
|
|
822
|
-
})),`);
|
|
823
|
-
}
|
|
824
|
-
const u = M(t.name || "container"), P = `${u[0].toUpperCase()}${u.slice(
|
|
825
|
-
1
|
|
826
|
-
)}IndexChange`, I = [];
|
|
827
|
-
t.id && (I.push(` // ${t.name}`), I.push(` "${t.id}": {`), I.push(
|
|
828
|
-
` currentIndex: props.${u}CurrentIndex,`
|
|
829
|
-
), I.push(` onIndexChange: props.on${P},`), I.push(" }")), I.length > 0 && j.push(I.join(`
|
|
830
|
-
`));
|
|
831
|
-
});
|
|
832
|
-
const w = j.length > 0 ? `
|
|
833
|
-
repeatingContainerControls={{
|
|
834
|
-
${j.join(`,
|
|
835
|
-
`)}
|
|
836
|
-
}}` : "", T = [], a = [];
|
|
837
|
-
(p.length > 0 || n.length > 0 || i.length > 0 || g.length > 0) && (a.push(" const handleAction = (payload: any) => {"), a.push(" const { action } = payload?.bravo || {};"), a.push(""), i.length > 0 && (a.push(" // Handle select input changes"), a.push(
|
|
838
|
-
' if (action?.action === "input-change" || action?.action === "select-change") {'
|
|
839
|
-
), a.push(" const nodeId = action?.nodeId;"), a.push(" const value = action?.params?.value;"), a.push(""), i.forEach((t) => {
|
|
840
|
-
const u = t.propName, I = `on${u[0].toUpperCase() + u.slice(1)}Change`;
|
|
841
|
-
a.push(` // ${t.name}`), a.push(
|
|
842
|
-
` if (nodeId === "${t.id}" && props.${I}) {`
|
|
843
|
-
), a.push(` props.${I}(value);`), a.push(" return;"), a.push(" }");
|
|
844
|
-
}), a.push(" }"), a.push("")), g.length > 0 && (a.push(" // Handle button clicks"), a.push(
|
|
845
|
-
' if (action?.action === "remote" || action?.action === "tap" || action?.action === "link") {'
|
|
846
|
-
), a.push(" const nodeId = action?.nodeId;"), a.push(""), g.forEach((t) => {
|
|
847
|
-
const u = t.propName, I = `on${u[0].toUpperCase() + u.slice(1)}Click`;
|
|
848
|
-
a.push(` // ${t.name}`), a.push(
|
|
849
|
-
` if (nodeId === "${t.id}" && props.${I}) {`
|
|
850
|
-
), a.push(` props.${I}();`), a.push(" return;"), a.push(" }");
|
|
851
|
-
}), a.push(" }"), a.push("")), p.length > 0 && (a.push(
|
|
852
|
-
' if (action?.action === "input-group-change") {'
|
|
853
|
-
), a.push(
|
|
854
|
-
" const { groupName, value } = action.params;"
|
|
855
|
-
), p.forEach((t) => {
|
|
856
|
-
const u = M(t.groupName), P = `on${u[0].toUpperCase()}${u.slice(
|
|
857
|
-
1
|
|
858
|
-
)}Change`;
|
|
859
|
-
a.push(
|
|
860
|
-
` if (groupName === "${t.groupName}" && props.${P}) {`
|
|
861
|
-
), a.push(` props.${P}(value);`), a.push(" return;"), a.push(" }");
|
|
862
|
-
}), a.push(" }"), a.push("")), n.length > 0 && (a.push(' if (action?.action === "submit") {'), a.push(" // Get form inputs from Encore state"), a.push(
|
|
863
|
-
` const formInputs = useEncoreState.getState().formInputs["${l}"] || {};`
|
|
864
|
-
), a.push(" const submitNodeId = action?.nodeId;"), a.push(""), n.forEach((t, u) => {
|
|
865
|
-
const P = M(t.formName), I = `on${P[0].toUpperCase()}${P.slice(
|
|
866
|
-
1
|
|
867
|
-
)}Submit`;
|
|
868
|
-
u > 0 && a.push(""), a.push(
|
|
869
|
-
` // Form: ${t.formName} (${t.formId})`
|
|
870
|
-
), t.submitButtonId ? a.push(
|
|
871
|
-
` if (submitNodeId === "${t.submitButtonId}" && props.${I}) {`
|
|
872
|
-
) : n.length === 1 ? a.push(` if (props.${I}) {`) : a.push(` if (props.${I}) {`), a.push(" // Extract form inputs for this form");
|
|
873
|
-
const F = `${P[0].toUpperCase()}${P.slice(
|
|
874
|
-
1
|
|
875
|
-
)}FormData`;
|
|
876
|
-
a.push(
|
|
877
|
-
` const formData: ${F} = {`
|
|
878
|
-
);
|
|
879
|
-
const O = [];
|
|
880
|
-
t.inputs.forEach((W) => {
|
|
881
|
-
const K = W.propName;
|
|
882
|
-
O.push(
|
|
883
|
-
` ${K}: formInputs["${W.id}"]`
|
|
884
|
-
);
|
|
885
|
-
}), a.push(O.join(`,
|
|
886
|
-
`)), a.push(" };"), a.push(` props.${I}(formData);`), a.push(
|
|
887
|
-
" // Note: Default form submission will still proceed after callback"
|
|
888
|
-
), a.push(" }");
|
|
889
|
-
}), a.push(" }")), a.push(" };")), p.forEach((t) => {
|
|
890
|
-
const u = M(t.groupName);
|
|
891
|
-
T.push(
|
|
892
|
-
` ...(props.${u} !== undefined && { ${u}: props.${u} }),`
|
|
893
|
-
);
|
|
894
|
-
});
|
|
895
|
-
const b = T.length > 0 ? `
|
|
896
|
-
inputGroups={{
|
|
897
|
-
${T.join(`
|
|
898
|
-
`)}
|
|
899
|
-
}}` : "", D = a.length > 0 ? `
|
|
900
|
-
onAction={handleAction}` : "", s = x ? `props: ${o}Props` : "", E = _ ? `${_}
|
|
901
|
-
|
|
902
|
-
` : "";
|
|
903
|
-
return `/**
|
|
904
|
-
* ${o}
|
|
905
|
-
*
|
|
906
|
-
* Wrapper component for Encore Studio app.
|
|
907
|
-
* See README.md for detailed documentation.
|
|
908
|
-
*/
|
|
909
|
-
|
|
910
|
-
import { EncoreApp${n.length > 0 ? ", useEncoreState" : ""} } from "@bravostudioai/react";
|
|
911
|
-
${c ? 'import productionData from "./data.json";' : ""}
|
|
912
|
-
|
|
913
|
-
${S ? `${S}
|
|
914
|
-
|
|
915
|
-
` : ""}${v ? `${v}
|
|
916
|
-
|
|
917
|
-
` : ""}${E}export function ${o}(${s}) {
|
|
918
|
-
${a.length > 0 ? a.join(`
|
|
919
|
-
`) : ""}
|
|
920
|
-
return (
|
|
921
|
-
<EncoreApp
|
|
922
|
-
appId="${h}"
|
|
923
|
-
pageId="${l}"
|
|
924
|
-
${c ? `appDefinition={productionData.app}
|
|
925
|
-
pageDefinition={productionData.page}
|
|
926
|
-
componentCode={productionData.componentCode}` : ""}
|
|
927
|
-
data={{
|
|
928
|
-
${U.join(`
|
|
929
|
-
`)}
|
|
930
|
-
}}${w}${b}${D}
|
|
931
|
-
/>
|
|
932
|
-
);
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
export default ${o};
|
|
936
|
-
`;
|
|
20
|
+
return await t.text();
|
|
937
21
|
}
|
|
938
|
-
function
|
|
939
|
-
const
|
|
940
|
-
n.forEach((a) => {
|
|
941
|
-
m.push(`### \`${a.propName}\` (${a.propType}, optional)
|
|
942
|
-
|
|
943
|
-
${a.name} (${a.type}) - Component ID: ${a.id}`);
|
|
944
|
-
}), p.forEach((a) => {
|
|
945
|
-
if (a.arrayContainer && a.arrayContainer.components.length > 0) {
|
|
946
|
-
const s = a.arrayContainer, E = s.components.map((t) => `- \`${t.propName}\` (${t.propType}): ${t.name} (${t.type}) - Component ID: ${t.id}`).join(`
|
|
947
|
-
`);
|
|
948
|
-
m.push(`### \`${s.propName}\` (${s.propName[0].toUpperCase()}${s.propName.slice(
|
|
949
|
-
1
|
|
950
|
-
)}Item[])
|
|
951
|
-
|
|
952
|
-
Array of items for "${s.name}" container (ID: ${s.id})
|
|
953
|
-
|
|
954
|
-
**Properties:**
|
|
955
|
-
|
|
956
|
-
${E}`);
|
|
957
|
-
}
|
|
958
|
-
const b = M(a.name || "container"), D = `${b[0].toUpperCase()}${b.slice(
|
|
959
|
-
1
|
|
960
|
-
)}IndexChange`;
|
|
961
|
-
N.push(`### \`${b}CurrentIndex\` (number, optional)
|
|
962
|
-
|
|
963
|
-
Controls the currently visible slide/index for the "${a.name}" container (ID: ${a.id}).
|
|
964
|
-
|
|
965
|
-
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.
|
|
966
|
-
|
|
967
|
-
### \`on${D}\` ((index: number) => void, optional)
|
|
968
|
-
|
|
969
|
-
Callback fired when the user navigates to a different slide. Called with the new slide index (0-based).
|
|
970
|
-
|
|
971
|
-
This event fires whenever the slide changes, whether by user interaction, automatic advancement, or programmatic control.`);
|
|
972
|
-
});
|
|
973
|
-
const f = m.length > 0 ? m.join(`
|
|
974
|
-
|
|
975
|
-
`) : "This component currently has no data-bound props.", $ = N.length > 0 ? `## Control Props
|
|
976
|
-
|
|
977
|
-
These props allow you to imperatively control repeating containers (sliders, lists, etc.) and receive notifications when the current index changes.
|
|
978
|
-
|
|
979
|
-
${N.join(`
|
|
980
|
-
|
|
981
|
-
`)}` : "", A = [];
|
|
982
|
-
i.forEach((a) => {
|
|
983
|
-
const b = M(a.groupName), D = `on${b[0].toUpperCase()}${b.slice(
|
|
984
|
-
1
|
|
985
|
-
)}Change`, s = a.elements.map((E) => `- "${E.name}"`).join(`
|
|
986
|
-
`);
|
|
987
|
-
A.push(`### \`${b}\` (string, optional)
|
|
988
|
-
|
|
989
|
-
Sets which element is active in the "${a.groupName}" input group (type: ${a.groupType}).
|
|
990
|
-
|
|
991
|
-
**Available elements:**
|
|
992
|
-
${s}
|
|
993
|
-
|
|
994
|
-
### \`${D}\` ((value: string) => void, optional)
|
|
995
|
-
|
|
996
|
-
Callback fired when the user selects a different element in the "${a.groupName}" input group. Called with the name of the selected element.`);
|
|
997
|
-
});
|
|
998
|
-
const x = A.length > 0 ? `## Input Group Props
|
|
999
|
-
|
|
1000
|
-
These props allow you to control input groups (radio button-like behavior) and receive notifications when the selection changes.
|
|
1001
|
-
|
|
1002
|
-
${A.join(`
|
|
1003
|
-
|
|
1004
|
-
`)}` : "", _ = [];
|
|
1005
|
-
g.forEach((a) => {
|
|
1006
|
-
const b = M(a.formName), D = `on${b[0].toUpperCase()}${b.slice(
|
|
1007
|
-
1
|
|
1008
|
-
)}Submit`, s = `${b[0].toUpperCase()}${b.slice(
|
|
1009
|
-
1
|
|
1010
|
-
)}FormData`, E = a.inputs.map((t) => {
|
|
1011
|
-
const u = t.propName, P = J(t.type, t.name);
|
|
1012
|
-
return `- \`${u}\` (${P}) - ${t.name}`;
|
|
1013
|
-
}).join(`
|
|
1014
|
-
`);
|
|
1015
|
-
_.push(`### \`${D}\` ((formData: ${s}) => void, optional)
|
|
1016
|
-
|
|
1017
|
-
Callback fired when the "${a.formName}" form is submitted. Called with a typed object containing all form input values with human-readable property names.
|
|
1018
|
-
|
|
1019
|
-
**Form data shape:**
|
|
1020
|
-
\`\`\`typescript
|
|
1021
|
-
interface ${s} {
|
|
1022
|
-
${a.inputs.map((t) => {
|
|
1023
|
-
const u = t.propName, P = J(t.type, t.name);
|
|
1024
|
-
return ` ${u}: ${P};`;
|
|
1025
|
-
}).join(`
|
|
1026
|
-
`)}
|
|
1027
|
-
}
|
|
1028
|
-
\`\`\`
|
|
1029
|
-
|
|
1030
|
-
**Form inputs:**
|
|
1031
|
-
${E}`);
|
|
1032
|
-
});
|
|
1033
|
-
const S = _.length > 0 ? `## Form Submission Props
|
|
1034
|
-
|
|
1035
|
-
These props allow you to handle form submissions and access form input values.
|
|
1036
|
-
|
|
1037
|
-
${_.join(`
|
|
1038
|
-
|
|
1039
|
-
`)}` : "";
|
|
1040
|
-
c.forEach((a) => {
|
|
1041
|
-
const b = a.propName, s = `on${b[0].toUpperCase() + b.slice(1)}Change`, E = `${b}Options`;
|
|
1042
|
-
r.push(`### \`${b}\` (string, optional)
|
|
1043
|
-
|
|
1044
|
-
Controls the selected value of the "${a.name}" dropdown (Component ID: ${a.id}).
|
|
1045
|
-
|
|
1046
|
-
When provided, the select input operates in controlled mode - the parent component controls the current value.
|
|
1047
|
-
|
|
1048
|
-
### \`${E}\` (Array<string | { value: string; label: string }>, optional)
|
|
1049
|
-
|
|
1050
|
-
Sets the available options for the "${a.name}" dropdown. Can be an array of strings (used as both value and label) or an array of objects with \`value\` and \`label\` properties.
|
|
1051
|
-
|
|
1052
|
-
**Example:**
|
|
1053
|
-
\`\`\`tsx
|
|
1054
|
-
// Simple string array
|
|
1055
|
-
${E}={["Option 1", "Option 2", "Option 3"]}
|
|
1056
|
-
|
|
1057
|
-
// Object array with separate values and labels
|
|
1058
|
-
${E}={[
|
|
1059
|
-
{ value: "opt1", label: "Option 1" },
|
|
1060
|
-
{ value: "opt2", label: "Option 2" },
|
|
1061
|
-
]}
|
|
1062
|
-
\`\`\`
|
|
1063
|
-
|
|
1064
|
-
### \`${s}\` ((value: string) => void, optional)
|
|
1065
|
-
|
|
1066
|
-
Callback fired when the user selects a different option in the "${a.name}" dropdown. Called with the selected value.`);
|
|
1067
|
-
});
|
|
1068
|
-
const v = r.length > 0 ? `## Select Input Props
|
|
1069
|
-
|
|
1070
|
-
These props allow you to control select/dropdown inputs and respond to value changes.
|
|
1071
|
-
|
|
1072
|
-
${r.join(`
|
|
1073
|
-
|
|
1074
|
-
`)}` : "";
|
|
1075
|
-
y.forEach((a) => {
|
|
1076
|
-
const b = a.propName, s = `on${b[0].toUpperCase() + b.slice(1)}Click`;
|
|
1077
|
-
C.push(`### \`${s}\` (() => void, optional)
|
|
1078
|
-
|
|
1079
|
-
Callback fired when the "${a.name}" button is clicked (Component ID: ${a.id}).
|
|
1080
|
-
|
|
1081
|
-
Action type: \`${a.actionType}\``);
|
|
1082
|
-
});
|
|
1083
|
-
const U = C.length > 0 ? `## Action Button Props
|
|
1084
|
-
|
|
1085
|
-
These props allow you to respond to button clicks and other user interactions.
|
|
1086
|
-
|
|
1087
|
-
${C.join(`
|
|
1088
|
-
|
|
1089
|
-
`)}` : "", j = `## Props
|
|
1090
|
-
|
|
1091
|
-
### Data Props
|
|
1092
|
-
|
|
1093
|
-
${f}
|
|
1094
|
-
|
|
1095
|
-
${$}
|
|
1096
|
-
|
|
1097
|
-
${x}
|
|
1098
|
-
|
|
1099
|
-
${S}
|
|
1100
|
-
|
|
1101
|
-
${v}
|
|
1102
|
-
|
|
1103
|
-
${U}`, w = p.length > 0 && p[0].arrayContainer ? `<${e}
|
|
1104
|
-
${p.map(
|
|
1105
|
-
(a) => a.arrayContainer ? `${a.arrayContainer.propName}={[
|
|
1106
|
-
{
|
|
1107
|
-
${a.arrayContainer?.components.map(
|
|
1108
|
-
(b) => `${b.propName}: "${b.type === "component:image" ? "https://example.com/image.jpg" : "Example value"}"`
|
|
1109
|
-
).join(`,
|
|
1110
|
-
`)}
|
|
1111
|
-
}
|
|
1112
|
-
]}` : ""
|
|
1113
|
-
).filter(Boolean).join(`
|
|
1114
|
-
`)}
|
|
1115
|
-
/>` : `<${e} />`;
|
|
1116
|
-
let T = "";
|
|
1117
|
-
if (p.length > 0 && p[0]) {
|
|
1118
|
-
const a = p[0], b = M(a.name || "container"), D = `${b[0].toUpperCase()}${b.slice(
|
|
1119
|
-
1
|
|
1120
|
-
)}IndexChange`;
|
|
1121
|
-
T = `## Controlling Slides
|
|
1122
|
-
|
|
1123
|
-
You can imperatively control which slide is displayed and listen for slide changes:
|
|
1124
|
-
|
|
1125
|
-
\`\`\`tsx
|
|
1126
|
-
import { useState } from "react";
|
|
1127
|
-
import { ${e} } from "./${e}";
|
|
1128
|
-
|
|
1129
|
-
function MyComponent() {
|
|
1130
|
-
const [currentSlide, setCurrentSlide] = useState(0);
|
|
1131
|
-
|
|
1132
|
-
return (
|
|
1133
|
-
<>
|
|
1134
|
-
<button onClick={() => setCurrentSlide((prev) => Math.max(0, prev - 1))}>
|
|
1135
|
-
Previous
|
|
1136
|
-
</button>
|
|
1137
|
-
<button onClick={() => setCurrentSlide((prev) => prev + 1)}>
|
|
1138
|
-
Next
|
|
1139
|
-
</button>
|
|
1140
|
-
<${e}
|
|
1141
|
-
${p.map(
|
|
1142
|
-
(s) => s.arrayContainer ? `${s.arrayContainer.propName}={[/* array of items */]}` : ""
|
|
1143
|
-
).filter(Boolean).join(`
|
|
1144
|
-
`)}
|
|
1145
|
-
${b}CurrentIndex={currentSlide}
|
|
1146
|
-
on${D}={(index) => setCurrentSlide(index)}
|
|
1147
|
-
/>
|
|
1148
|
-
</>
|
|
1149
|
-
);
|
|
1150
|
-
}
|
|
1151
|
-
\`\`\``;
|
|
1152
|
-
}
|
|
1153
|
-
return `# ${e}
|
|
1154
|
-
|
|
1155
|
-
Encore App Wrapper Component
|
|
1156
|
-
|
|
1157
|
-
This component wraps the Encore Studio app **"${o}"** (App ID: \`${h}\`) for the page **"${d}"** (Page ID: \`${l}\`).
|
|
1158
|
-
|
|
1159
|
-
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.
|
|
1160
|
-
|
|
1161
|
-
${j}
|
|
1162
|
-
|
|
1163
|
-
## Usage
|
|
1164
|
-
|
|
1165
|
-
\`\`\`tsx
|
|
1166
|
-
import { ${e} } from "./${e}";
|
|
1167
|
-
|
|
1168
|
-
function MyComponent() {
|
|
1169
|
-
return (
|
|
1170
|
-
<${e}
|
|
1171
|
-
${p.map(
|
|
1172
|
-
(a) => a.arrayContainer ? `${a.arrayContainer.propName}={[/* array of items */]}` : ""
|
|
1173
|
-
).filter(Boolean).join(`
|
|
1174
|
-
`)}
|
|
1175
|
-
/>
|
|
1176
|
-
);
|
|
1177
|
-
}
|
|
1178
|
-
\`\`\`
|
|
1179
|
-
|
|
1180
|
-
## Example
|
|
1181
|
-
|
|
1182
|
-
\`\`\`tsx
|
|
1183
|
-
${w}
|
|
1184
|
-
\`\`\`
|
|
1185
|
-
|
|
1186
|
-
${T}
|
|
1187
|
-
`;
|
|
1188
|
-
}
|
|
1189
|
-
function $e(h, l) {
|
|
1190
|
-
const o = M(h), d = M(l), e = o.charAt(0).toUpperCase() + o.slice(1), p = d.charAt(0).toUpperCase() + d.slice(1);
|
|
22
|
+
function se(o, n) {
|
|
23
|
+
const t = L(o), r = L(n), d = t.charAt(0).toUpperCase() + t.slice(1), p = r.charAt(0).toUpperCase() + r.slice(1);
|
|
1191
24
|
return {
|
|
1192
|
-
directoryPath:
|
|
25
|
+
directoryPath: c(d, p),
|
|
1193
26
|
componentName: p
|
|
1194
27
|
};
|
|
1195
28
|
}
|
|
1196
|
-
async function
|
|
1197
|
-
const
|
|
1198
|
-
console.log(`Fetching app data from ${
|
|
29
|
+
async function re(o) {
|
|
30
|
+
const n = `${S}/devices/apps/${o}`;
|
|
31
|
+
console.log(`Fetching app data from ${n}...`);
|
|
1199
32
|
try {
|
|
1200
|
-
const
|
|
1201
|
-
return { pages:
|
|
1202
|
-
} catch (
|
|
1203
|
-
throw console.error("Failed to fetch app data:",
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
async function
|
|
1207
|
-
appId:
|
|
1208
|
-
pageId:
|
|
1209
|
-
outputPath:
|
|
1210
|
-
cachedAppData:
|
|
1211
|
-
isProduction:
|
|
33
|
+
const t = await _(n), r = JSON.parse(t);
|
|
34
|
+
return { pages: r?.app?.data?.pages || [], appData: r };
|
|
35
|
+
} catch (t) {
|
|
36
|
+
throw console.error("Failed to fetch app data:", t), t;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function I({
|
|
40
|
+
appId: o,
|
|
41
|
+
pageId: n,
|
|
42
|
+
outputPath: t,
|
|
43
|
+
cachedAppData: r,
|
|
44
|
+
isProduction: d
|
|
1212
45
|
}) {
|
|
1213
|
-
console.log(`Generating wrapper for app: ${
|
|
1214
|
-
let p =
|
|
1215
|
-
const
|
|
1216
|
-
if (
|
|
1217
|
-
const { stat:
|
|
46
|
+
console.log(`Generating wrapper for app: ${o}, page: ${n}`);
|
|
47
|
+
let p = t, i = !1;
|
|
48
|
+
const m = t.split(".").pop()?.toLowerCase();
|
|
49
|
+
if (m !== "tsx" && m !== "ts" && m !== "jsx" && m !== "js") {
|
|
50
|
+
const { stat: e } = await import("fs/promises");
|
|
1218
51
|
try {
|
|
1219
|
-
(await
|
|
52
|
+
(await e(t)).isDirectory() && (i = !0);
|
|
1220
53
|
} catch {
|
|
1221
|
-
(!
|
|
54
|
+
(!m || t.endsWith("/")) && (i = !0);
|
|
1222
55
|
}
|
|
1223
56
|
}
|
|
1224
|
-
|
|
57
|
+
i && console.log(
|
|
1225
58
|
"Output path is a directory, will generate filename from app/page names"
|
|
1226
|
-
), console.log(`Output path: ${
|
|
1227
|
-
const
|
|
1228
|
-
|
|
1229
|
-
const
|
|
59
|
+
), console.log(`Output path: ${t}`);
|
|
60
|
+
const a = c(process.cwd(), ".temp-bravo", o, n);
|
|
61
|
+
R(a) || await T(a, { recursive: !0 });
|
|
62
|
+
const N = [
|
|
1230
63
|
{
|
|
1231
|
-
url: `${
|
|
64
|
+
url: `${S}/devices/apps/${o}`,
|
|
1232
65
|
filename: "app.json",
|
|
1233
66
|
skipIfCached: !0
|
|
1234
67
|
},
|
|
1235
68
|
{
|
|
1236
|
-
url: `${
|
|
69
|
+
url: `${S}/devices/apps/${o}/node/${n}`,
|
|
1237
70
|
filename: "page.json"
|
|
1238
71
|
},
|
|
1239
72
|
{
|
|
1240
|
-
url: `${
|
|
73
|
+
url: `${ae}/${o}/draft/components/${n}.js`,
|
|
1241
74
|
filename: "component.js"
|
|
1242
75
|
}
|
|
1243
76
|
];
|
|
1244
|
-
for (const
|
|
1245
|
-
if (
|
|
1246
|
-
console.log(`Using cached ${
|
|
1247
|
-
const
|
|
1248
|
-
await
|
|
1249
|
-
|
|
1250
|
-
JSON.stringify(
|
|
77
|
+
for (const e of N) {
|
|
78
|
+
if (e.skipIfCached && r) {
|
|
79
|
+
console.log(`Using cached ${e.filename} (skipping download)`);
|
|
80
|
+
const s = c(a, e.filename);
|
|
81
|
+
await C(
|
|
82
|
+
s,
|
|
83
|
+
JSON.stringify(r, null, 2),
|
|
1251
84
|
"utf-8"
|
|
1252
|
-
), console.log(`✓ Saved ${
|
|
85
|
+
), console.log(`✓ Saved ${e.filename} from cache`);
|
|
1253
86
|
continue;
|
|
1254
87
|
}
|
|
1255
88
|
try {
|
|
1256
|
-
console.log(`Downloading ${
|
|
1257
|
-
const
|
|
1258
|
-
await
|
|
1259
|
-
} catch (
|
|
1260
|
-
throw console.error(`✗ Failed to download ${
|
|
89
|
+
console.log(`Downloading ${e.filename} from ${e.url}...`);
|
|
90
|
+
const s = await _(e.url, e.headers), f = c(a, e.filename);
|
|
91
|
+
await C(f, s, "utf-8"), console.log(`✓ Saved ${e.filename}`);
|
|
92
|
+
} catch (s) {
|
|
93
|
+
throw console.error(`✗ Failed to download ${e.filename}:`, s), s;
|
|
1261
94
|
}
|
|
1262
95
|
}
|
|
1263
|
-
const
|
|
1264
|
-
let
|
|
1265
|
-
if (
|
|
96
|
+
const g = c(a, "page.json"), u = await $(g, "utf-8"), v = JSON.parse(u);
|
|
97
|
+
let l = v.data || v;
|
|
98
|
+
if (!l.body && !l.data?.body) {
|
|
1266
99
|
console.log("Page data doesn't have body, trying app.json...");
|
|
1267
100
|
try {
|
|
1268
|
-
let
|
|
1269
|
-
if (
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
const u = `${G}/devices/apps/${h}`, P = await V(u);
|
|
1273
|
-
s = JSON.parse(P);
|
|
1274
|
-
}
|
|
1275
|
-
console.log("App data keys:", Object.keys(s)), console.log(
|
|
1276
|
-
"App.app keys:",
|
|
1277
|
-
s?.app ? Object.keys(s.app) : "N/A"
|
|
1278
|
-
), console.log(
|
|
1279
|
-
"App.app.data keys:",
|
|
1280
|
-
s?.app?.data ? Object.keys(s.app.data) : "N/A"
|
|
1281
|
-
);
|
|
1282
|
-
const E = s?.app?.data?.pages || [];
|
|
1283
|
-
console.log(`Found ${E.length} pages in app.json`), E.length > 0 && console.log("First page ID:", E[0]?.id);
|
|
1284
|
-
const t = E.find((u) => u.id === l);
|
|
1285
|
-
if (t)
|
|
1286
|
-
r = t, console.log("✓ Found page data in app.json"), console.log("Page from app.json has body?", !!r.body), console.log(
|
|
1287
|
-
"Page body length:",
|
|
1288
|
-
Array.isArray(r.body) ? r.body.length : "N/A"
|
|
1289
|
-
);
|
|
1290
|
-
else {
|
|
1291
|
-
console.warn(`Page ${l} not found in app.json`), console.warn(
|
|
1292
|
-
"Available page IDs:",
|
|
1293
|
-
E.map((P) => P.id)
|
|
1294
|
-
);
|
|
1295
|
-
const u = k(
|
|
1296
|
-
process.cwd(),
|
|
1297
|
-
"saved-apps",
|
|
1298
|
-
h,
|
|
1299
|
-
`page-${l}.json`
|
|
1300
|
-
);
|
|
1301
|
-
if (B(u)) {
|
|
1302
|
-
console.log("Trying saved-apps page file...");
|
|
1303
|
-
try {
|
|
1304
|
-
const P = await R(u, "utf-8"), I = JSON.parse(P), F = I.data || I;
|
|
1305
|
-
F.body && (r = F, console.log("✓ Found page data in saved-apps"), console.log(
|
|
1306
|
-
"Page body length:",
|
|
1307
|
-
Array.isArray(r.body) ? r.body.length : "N/A"
|
|
1308
|
-
));
|
|
1309
|
-
} catch (P) {
|
|
1310
|
-
console.warn("Could not load saved-apps page:", P);
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
} catch (s) {
|
|
1315
|
-
console.warn("Could not load app.json:", s);
|
|
1316
|
-
const E = k(
|
|
1317
|
-
process.cwd(),
|
|
1318
|
-
"saved-apps",
|
|
1319
|
-
h,
|
|
1320
|
-
`page-${l}.json`
|
|
1321
|
-
);
|
|
1322
|
-
if (B(E)) {
|
|
1323
|
-
console.log("Trying saved-apps page file...");
|
|
1324
|
-
try {
|
|
1325
|
-
const t = await R(E, "utf-8"), u = JSON.parse(t), P = u.data || u;
|
|
1326
|
-
P.body && (r = P, console.log("✓ Found page data in saved-apps"), console.log(
|
|
1327
|
-
"Page body length:",
|
|
1328
|
-
Array.isArray(r.body) ? r.body.length : "N/A"
|
|
1329
|
-
));
|
|
1330
|
-
} catch (t) {
|
|
1331
|
-
console.warn("Could not load saved-apps page:", t);
|
|
1332
|
-
}
|
|
101
|
+
let e = r;
|
|
102
|
+
if (!e) {
|
|
103
|
+
const h = `${S}/devices/apps/${o}`, w = await _(h);
|
|
104
|
+
e = JSON.parse(w);
|
|
1333
105
|
}
|
|
106
|
+
const f = (e?.app?.data?.pages || []).find((h) => h.id === n);
|
|
107
|
+
f && (l = f, console.log("✓ Found page data in app.json"));
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.warn("Could not load app.json:", e);
|
|
1334
110
|
}
|
|
1335
111
|
}
|
|
1336
|
-
const
|
|
1337
|
-
|
|
112
|
+
const x = z(l), A = X(l), O = Z(l), P = H(l);
|
|
113
|
+
Q(P);
|
|
114
|
+
const U = ee(l, P), j = te(l);
|
|
115
|
+
let E = "Encore App", y = "Page";
|
|
1338
116
|
try {
|
|
1339
|
-
let
|
|
1340
|
-
if (!
|
|
1341
|
-
const
|
|
1342
|
-
if (
|
|
1343
|
-
const
|
|
1344
|
-
|
|
117
|
+
let e = r;
|
|
118
|
+
if (!e) {
|
|
119
|
+
const s = c(a, "app.json");
|
|
120
|
+
if (R(s)) {
|
|
121
|
+
const f = await $(s, "utf-8");
|
|
122
|
+
e = JSON.parse(f);
|
|
1345
123
|
}
|
|
1346
124
|
}
|
|
1347
|
-
|
|
125
|
+
e && (E = e?.app?.store?.name || E);
|
|
1348
126
|
} catch {
|
|
1349
127
|
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
` Array Container: ${s.arrayContainer.name} (${s.arrayContainer.id})`
|
|
1355
|
-
), console.log(" Components:"), s.arrayContainer.components.forEach((t) => {
|
|
1356
|
-
console.log(
|
|
1357
|
-
` - ${t.name} (${t.id}): ${t.type} -> prop: ${t.propName}: ${t.propType}`
|
|
1358
|
-
);
|
|
1359
|
-
})) : console.log(" No array container found");
|
|
1360
|
-
}), console.log(
|
|
1361
|
-
`
|
|
1362
|
-
Found ${f.length} standalone component(s):`
|
|
1363
|
-
), f.forEach((s) => {
|
|
1364
|
-
console.log(
|
|
1365
|
-
` - ${s.name} (${s.id}): ${s.type} -> prop: ${s.propName}: ${s.propType}`
|
|
1366
|
-
);
|
|
1367
|
-
});
|
|
1368
|
-
const x = ce(r);
|
|
1369
|
-
console.log(`
|
|
1370
|
-
Found ${x.length} input group(s):`), x.forEach((s, E) => {
|
|
1371
|
-
console.log(`
|
|
1372
|
-
Input Group ${E + 1}:`), console.log(` Name: ${s.groupName}`), console.log(` Type: ${s.groupType}`), console.log(" Elements:"), s.elements.forEach((t) => {
|
|
1373
|
-
console.log(` - ${t.name} (${t.id})`);
|
|
1374
|
-
});
|
|
1375
|
-
});
|
|
1376
|
-
const _ = le(r);
|
|
1377
|
-
de(_), console.log(`
|
|
1378
|
-
Found ${_.length} form(s):`), _.forEach((s, E) => {
|
|
1379
|
-
console.log(`
|
|
1380
|
-
Form ${E + 1}:`), console.log(` Name: ${s.formName}`), console.log(` ID: ${s.formId}`), s.submitButtonId && console.log(` Submit Button ID: ${s.submitButtonId}`), console.log(" Inputs:"), s.inputs.forEach((t) => {
|
|
1381
|
-
console.log(` - ${t.name} (${t.id}): ${t.type}`);
|
|
1382
|
-
});
|
|
1383
|
-
});
|
|
1384
|
-
const S = he(r, _);
|
|
1385
|
-
console.log(`
|
|
1386
|
-
Found ${S.length} standalone select input(s):`), S.forEach((s) => {
|
|
1387
|
-
console.log(
|
|
1388
|
-
` - ${s.name} (${s.id}) -> prop: ${s.propName}, on${s.propName[0].toUpperCase()}${s.propName.slice(1)}Change`
|
|
1389
|
-
);
|
|
1390
|
-
});
|
|
1391
|
-
const v = fe(r);
|
|
1392
|
-
console.log(`
|
|
1393
|
-
Found ${v.length} action button(s):`), v.forEach((s) => {
|
|
1394
|
-
console.log(
|
|
1395
|
-
` - ${s.name} (${s.id}) -> on${s.propName[0].toUpperCase()}${s.propName.slice(
|
|
1396
|
-
1
|
|
1397
|
-
)}Click (action: ${s.actionType})`
|
|
1398
|
-
);
|
|
1399
|
-
}), C.length === 0 && f.length === 0 && x.length === 0 && _.length === 0 && S.length === 0 && v.length === 0 && console.warn(
|
|
1400
|
-
`
|
|
1401
|
-
⚠ No sliders, standalone components, input groups, forms, select inputs, or action buttons found. Generating empty wrapper.`
|
|
1402
|
-
);
|
|
1403
|
-
const { directoryPath: U, componentName: j } = $e($, A), w = U;
|
|
1404
|
-
if (n)
|
|
1405
|
-
p = k(o, w);
|
|
128
|
+
y = l.name || l.id || y;
|
|
129
|
+
const { directoryPath: G, componentName: D } = se(E, y), F = G;
|
|
130
|
+
if (i)
|
|
131
|
+
p = c(t, F);
|
|
1406
132
|
else {
|
|
1407
|
-
const
|
|
1408
|
-
p =
|
|
133
|
+
const e = k(p);
|
|
134
|
+
p = c(e, F);
|
|
1409
135
|
}
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
j,
|
|
1415
|
-
C,
|
|
1416
|
-
f,
|
|
136
|
+
const K = oe(
|
|
137
|
+
o,
|
|
138
|
+
n,
|
|
139
|
+
D,
|
|
1417
140
|
x,
|
|
1418
|
-
_,
|
|
1419
|
-
S,
|
|
1420
|
-
v,
|
|
1421
|
-
!!e
|
|
1422
|
-
), a = ye(
|
|
1423
|
-
h,
|
|
1424
|
-
l,
|
|
1425
|
-
$,
|
|
1426
141
|
A,
|
|
142
|
+
O,
|
|
143
|
+
P,
|
|
144
|
+
U,
|
|
1427
145
|
j,
|
|
1428
|
-
|
|
1429
|
-
|
|
146
|
+
!!d
|
|
147
|
+
), V = ne(
|
|
148
|
+
o,
|
|
149
|
+
n,
|
|
150
|
+
E,
|
|
151
|
+
y,
|
|
152
|
+
D,
|
|
1430
153
|
x,
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
154
|
+
A,
|
|
155
|
+
O,
|
|
156
|
+
P,
|
|
157
|
+
U,
|
|
158
|
+
j
|
|
1434
159
|
);
|
|
1435
|
-
if (
|
|
1436
|
-
const
|
|
1437
|
-
let
|
|
160
|
+
if (R(p) || await T(p, { recursive: !0 }), d) {
|
|
161
|
+
const e = c(a, "component.js");
|
|
162
|
+
let s = "";
|
|
1438
163
|
try {
|
|
1439
|
-
|
|
1440
|
-
} catch
|
|
1441
|
-
console.warn("Could not read component.js for production build", P);
|
|
164
|
+
s = await $(e, "utf-8");
|
|
165
|
+
} catch {
|
|
1442
166
|
}
|
|
1443
|
-
let
|
|
1444
|
-
if (!
|
|
167
|
+
let f = r;
|
|
168
|
+
if (!f)
|
|
1445
169
|
try {
|
|
1446
|
-
const
|
|
1447
|
-
|
|
1448
|
-
} catch
|
|
1449
|
-
console.warn("Could not read app.json for production build", P);
|
|
170
|
+
const w = c(a, "app.json"), B = await $(w, "utf-8");
|
|
171
|
+
f = JSON.parse(B);
|
|
172
|
+
} catch {
|
|
1450
173
|
}
|
|
1451
|
-
const
|
|
1452
|
-
app:
|
|
1453
|
-
page:
|
|
1454
|
-
componentCode:
|
|
174
|
+
const h = {
|
|
175
|
+
app: f,
|
|
176
|
+
page: l,
|
|
177
|
+
componentCode: s
|
|
1455
178
|
};
|
|
1456
|
-
await
|
|
179
|
+
await C(
|
|
180
|
+
c(p, "data.json"),
|
|
181
|
+
JSON.stringify(h, null, 2),
|
|
182
|
+
"utf-8"
|
|
183
|
+
);
|
|
1457
184
|
}
|
|
1458
|
-
const
|
|
1459
|
-
await
|
|
1460
|
-
✓ Generated wrapper component at: ${b}`), console.log(`✓ Generated documentation at: ${D}`);
|
|
185
|
+
const J = c(p, "index.tsx"), b = c(p, "README.md");
|
|
186
|
+
await C(J, K, "utf-8"), await C(b, V, "utf-8"), console.log(`✓ Generated wrapper component at: ${J}`);
|
|
1461
187
|
}
|
|
1462
|
-
function
|
|
188
|
+
function pe() {
|
|
1463
189
|
console.log(`
|
|
1464
190
|
Usage: generate-wrapper.ts <appId> [pageId] <outputPath>
|
|
1465
191
|
|
|
@@ -1473,54 +199,51 @@ Environment variables:
|
|
|
1473
199
|
|
|
1474
200
|
Example:
|
|
1475
201
|
generate-wrapper.ts 01KA964B1T6KCKSKCNMYSTKRKZ 01KA964B2F42MN4WGCYDTG1Y70 ./src/components/MyEncoreApp.tsx
|
|
1476
|
-
generate-wrapper.ts 01KA964B1T6KCKSKCNMYSTKRKZ ./src/components/ (Generates all pages)
|
|
1477
202
|
`);
|
|
1478
203
|
}
|
|
1479
|
-
async function
|
|
1480
|
-
const
|
|
1481
|
-
if ((
|
|
1482
|
-
|
|
204
|
+
async function ge(o) {
|
|
205
|
+
const n = o.includes("--production"), t = o.filter((i) => i !== "--production");
|
|
206
|
+
if ((t.length < 2 || t.includes("--help") || t.includes("-h")) && (pe(), process.exit(
|
|
207
|
+
t.includes("--help") || t.includes("-h") ? 0 : 1
|
|
208
|
+
)), t.length === 2) {
|
|
209
|
+
const [i, m] = t;
|
|
1483
210
|
try {
|
|
1484
|
-
const { pages:
|
|
1485
|
-
if (
|
|
211
|
+
const { pages: a, appData: N } = await re(i);
|
|
212
|
+
if (a.length === 0) {
|
|
1486
213
|
console.warn("No pages found for this app.");
|
|
1487
214
|
return;
|
|
1488
215
|
}
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
);
|
|
1492
|
-
for (const y of g)
|
|
1493
|
-
if (y.id) {
|
|
1494
|
-
console.log(`
|
|
1495
|
-
----------------------------------------`), console.log(`Processing page: ${y.name || "Unnamed"} (${y.id})`), console.log("----------------------------------------");
|
|
216
|
+
for (const g of a)
|
|
217
|
+
if (g.id)
|
|
1496
218
|
try {
|
|
1497
|
-
await
|
|
1498
|
-
appId:
|
|
1499
|
-
pageId:
|
|
1500
|
-
outputPath:
|
|
1501
|
-
cachedAppData:
|
|
1502
|
-
isProduction:
|
|
219
|
+
await I({
|
|
220
|
+
appId: i,
|
|
221
|
+
pageId: g.id,
|
|
222
|
+
outputPath: m,
|
|
223
|
+
cachedAppData: N,
|
|
224
|
+
isProduction: n
|
|
1503
225
|
});
|
|
1504
|
-
} catch (
|
|
1505
|
-
console.warn(
|
|
226
|
+
} catch (u) {
|
|
227
|
+
console.warn(
|
|
228
|
+
`Error with page ${g.id}:`,
|
|
229
|
+
u instanceof Error ? u.message : u
|
|
230
|
+
);
|
|
1506
231
|
}
|
|
1507
|
-
|
|
1508
|
-
} catch (g) {
|
|
232
|
+
} catch (a) {
|
|
1509
233
|
console.error(`
|
|
1510
|
-
Error:`,
|
|
234
|
+
Error:`, a instanceof Error ? a.message : a), process.exit(1);
|
|
1511
235
|
}
|
|
1512
236
|
return;
|
|
1513
237
|
}
|
|
1514
|
-
const [
|
|
1515
|
-
(!d || !e || !p) && (console.error("Error: Missing required arguments"), X(), process.exit(1));
|
|
238
|
+
const [r, d, p] = t;
|
|
1516
239
|
try {
|
|
1517
|
-
await
|
|
1518
|
-
} catch (
|
|
240
|
+
await I({ appId: r, pageId: d, outputPath: p, isProduction: n });
|
|
241
|
+
} catch (i) {
|
|
1519
242
|
console.error(`
|
|
1520
|
-
Error:`,
|
|
243
|
+
Error:`, i instanceof Error ? i.message : i), process.exit(1);
|
|
1521
244
|
}
|
|
1522
245
|
}
|
|
1523
246
|
export {
|
|
1524
|
-
|
|
247
|
+
ge as runGenerate
|
|
1525
248
|
};
|
|
1526
249
|
//# sourceMappingURL=generate.js.map
|