@bravostudioai/react 0.1.0

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.
Files changed (127) hide show
  1. package/bin/encore-lib.js +3 -0
  2. package/dist/_virtual/_commonjsHelpers.js +7 -0
  3. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  4. package/dist/_virtual/main.js +8 -0
  5. package/dist/_virtual/main.js.map +1 -0
  6. package/dist/_virtual/main2.js +5 -0
  7. package/dist/_virtual/main2.js.map +1 -0
  8. package/dist/app.js +9 -0
  9. package/dist/app.js.map +1 -0
  10. package/dist/cli/commands/download.js +82 -0
  11. package/dist/cli/commands/download.js.map +1 -0
  12. package/dist/cli/commands/generate.js +1526 -0
  13. package/dist/cli/commands/generate.js.map +1 -0
  14. package/dist/cli.js +25 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/components/DynamicComponent.js +24 -0
  17. package/dist/components/DynamicComponent.js.map +1 -0
  18. package/dist/components/EncoreApp.js +259 -0
  19. package/dist/components/EncoreApp.js.map +1 -0
  20. package/dist/components/EncoreErrorBoundary.js +33 -0
  21. package/dist/components/EncoreErrorBoundary.js.map +1 -0
  22. package/dist/components/EncoreLoadingFallback.js +20 -0
  23. package/dist/components/EncoreLoadingFallback.js.map +1 -0
  24. package/dist/components.js +1454 -0
  25. package/dist/components.js.map +1 -0
  26. package/dist/constants.d.ts +3 -0
  27. package/dist/constants.d.ts.map +1 -0
  28. package/dist/contexts/EncoreActionContext.js +6 -0
  29. package/dist/contexts/EncoreActionContext.js.map +1 -0
  30. package/dist/contexts/EncoreAppContext.js +9 -0
  31. package/dist/contexts/EncoreAppContext.js.map +1 -0
  32. package/dist/contexts/EncoreBindingContext.js +6 -0
  33. package/dist/contexts/EncoreBindingContext.js.map +1 -0
  34. package/dist/contexts/EncoreComponentIdContext.js +8 -0
  35. package/dist/contexts/EncoreComponentIdContext.js.map +1 -0
  36. package/dist/contexts/EncoreRepeatingContainerContext.js +6 -0
  37. package/dist/contexts/EncoreRepeatingContainerContext.js.map +1 -0
  38. package/dist/hooks/usePusherUpdates.js +60 -0
  39. package/dist/hooks/usePusherUpdates.js.map +1 -0
  40. package/dist/index.js +16 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/lib/dynamicModules.js +132 -0
  43. package/dist/lib/dynamicModules.js.map +1 -0
  44. package/dist/lib/fetcher.js +58 -0
  45. package/dist/lib/fetcher.js.map +1 -0
  46. package/dist/lib/localMode.js +21 -0
  47. package/dist/lib/localMode.js.map +1 -0
  48. package/dist/lib/packages.js +18 -0
  49. package/dist/lib/packages.js.map +1 -0
  50. package/dist/node_modules/dotenv/lib/main.js +198 -0
  51. package/dist/node_modules/dotenv/lib/main.js.map +1 -0
  52. package/dist/node_modules/dotenv/package.json.js +8 -0
  53. package/dist/node_modules/dotenv/package.json.js.map +1 -0
  54. package/dist/packages/encore-lib/constants.js +6 -0
  55. package/dist/packages/encore-lib/constants.js.map +1 -0
  56. package/dist/src/app.d.ts +5 -0
  57. package/dist/src/app.d.ts.map +1 -0
  58. package/dist/src/cli/commands/download.d.ts +2 -0
  59. package/dist/src/cli/commands/download.d.ts.map +1 -0
  60. package/dist/src/cli/commands/generate.d.ts +2 -0
  61. package/dist/src/cli/commands/generate.d.ts.map +1 -0
  62. package/dist/src/cli/index.d.ts +2 -0
  63. package/dist/src/cli/index.d.ts.map +1 -0
  64. package/dist/src/components/DynamicComponent.d.ts +12 -0
  65. package/dist/src/components/DynamicComponent.d.ts.map +1 -0
  66. package/dist/src/components/EncoreApp.d.ts +27 -0
  67. package/dist/src/components/EncoreApp.d.ts.map +1 -0
  68. package/dist/src/components/EncoreErrorBoundary.d.ts +17 -0
  69. package/dist/src/components/EncoreErrorBoundary.d.ts.map +1 -0
  70. package/dist/src/components/EncoreLoadingFallback.d.ts +4 -0
  71. package/dist/src/components/EncoreLoadingFallback.d.ts.map +1 -0
  72. package/dist/src/components.d.ts +4 -0
  73. package/dist/src/components.d.ts.map +1 -0
  74. package/dist/src/contexts/EncoreActionContext.d.ts +13 -0
  75. package/dist/src/contexts/EncoreActionContext.d.ts.map +1 -0
  76. package/dist/src/contexts/EncoreAppContext.d.ts +8 -0
  77. package/dist/src/contexts/EncoreAppContext.d.ts.map +1 -0
  78. package/dist/src/contexts/EncoreBindingContext.d.ts +5 -0
  79. package/dist/src/contexts/EncoreBindingContext.d.ts.map +1 -0
  80. package/dist/src/contexts/EncoreComponentIdContext.d.ts +8 -0
  81. package/dist/src/contexts/EncoreComponentIdContext.d.ts.map +1 -0
  82. package/dist/src/contexts/EncoreRepeatingContainerContext.d.ts +21 -0
  83. package/dist/src/contexts/EncoreRepeatingContainerContext.d.ts.map +1 -0
  84. package/dist/src/hooks/useAuthRedirect.d.ts +3 -0
  85. package/dist/src/hooks/useAuthRedirect.d.ts.map +1 -0
  86. package/dist/src/hooks/usePusherUpdates.d.ts +18 -0
  87. package/dist/src/hooks/usePusherUpdates.d.ts.map +1 -0
  88. package/dist/src/index.d.ts +8 -0
  89. package/dist/src/index.d.ts.map +1 -0
  90. package/dist/src/lib/dynamicModules.d.ts +8 -0
  91. package/dist/src/lib/dynamicModules.d.ts.map +1 -0
  92. package/dist/src/lib/fetcher.d.ts +5 -0
  93. package/dist/src/lib/fetcher.d.ts.map +1 -0
  94. package/dist/src/lib/localMode.d.ts +3 -0
  95. package/dist/src/lib/localMode.d.ts.map +1 -0
  96. package/dist/src/lib/packages.d.ts +6 -0
  97. package/dist/src/lib/packages.d.ts.map +1 -0
  98. package/dist/src/stores/useEncoreState.d.ts +33 -0
  99. package/dist/src/stores/useEncoreState.d.ts.map +1 -0
  100. package/dist/stores/useEncoreState.js +70 -0
  101. package/dist/stores/useEncoreState.js.map +1 -0
  102. package/package.json +60 -0
  103. package/src/AGENTS.md +161 -0
  104. package/src/README.md +110 -0
  105. package/src/app.ts +5 -0
  106. package/src/cli/commands/download.ts +133 -0
  107. package/src/cli/commands/generate.ts +3045 -0
  108. package/src/cli/index.ts +35 -0
  109. package/src/components/DynamicComponent.tsx +40 -0
  110. package/src/components/EncoreApp.tsx +759 -0
  111. package/src/components/EncoreErrorBoundary.tsx +49 -0
  112. package/src/components/EncoreLoadingFallback.tsx +25 -0
  113. package/src/components.tsx +3155 -0
  114. package/src/contexts/EncoreActionContext.ts +18 -0
  115. package/src/contexts/EncoreAppContext.ts +13 -0
  116. package/src/contexts/EncoreBindingContext.ts +6 -0
  117. package/src/contexts/EncoreComponentIdContext.ts +12 -0
  118. package/src/contexts/EncoreRepeatingContainerContext.ts +30 -0
  119. package/src/hooks/useAuthRedirect.ts +63 -0
  120. package/src/hooks/usePusherUpdates.ts +156 -0
  121. package/src/index.ts +16 -0
  122. package/src/lib/dynamicModules.ts +193 -0
  123. package/src/lib/fetcher.ts +108 -0
  124. package/src/lib/localMode.ts +30 -0
  125. package/src/lib/moduleRegistry.ts +24 -0
  126. package/src/lib/packages.ts +33 -0
  127. package/src/stores/useEncoreState.ts +121 -0
@@ -0,0 +1,1526 @@
1
+ import { mkdir as H, writeFile as q, readFile as R } from "fs/promises";
2
+ import { join as k, dirname as ae } from "path";
3
+ import { existsSync as B } from "fs";
4
+ import ne from "../../_virtual/main.js";
5
+ import { CONST_APPS_SERVICE_URL as oe, CONST_COMPONENTS_CDN_URL as re } from "../../packages/encore-lib/constants.js";
6
+ ne.config();
7
+ const G = process.env.APPS_SERVICE_URL || process.env.VITE_APPS_SERVICE_URL || oe;
8
+ console.log(`Using APPS_SERVICE_URL: ${G}`);
9
+ const se = re;
10
+ async function V(h, l) {
11
+ const o = await fetch(h, {
12
+ headers: l || {}
13
+ });
14
+ if (!o.ok)
15
+ throw new Error(
16
+ `Failed to download ${h}: ${o.status} ${o.statusText}`
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)
526
+ );
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
+ `;
937
+ }
938
+ function ye(h, l, o, d, e, p, n, i, g, c, y) {
939
+ const m = [], N = [], r = [], C = [];
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);
1191
+ return {
1192
+ directoryPath: k(e, p),
1193
+ componentName: p
1194
+ };
1195
+ }
1196
+ async function Pe(h) {
1197
+ const l = `${G}/devices/apps/${h}`;
1198
+ console.log(`Fetching app data from ${l}...`);
1199
+ try {
1200
+ const o = await V(l), d = JSON.parse(o);
1201
+ return { pages: d?.app?.data?.pages || [], appData: d };
1202
+ } catch (o) {
1203
+ throw console.error("Failed to fetch app data:", o), o;
1204
+ }
1205
+ }
1206
+ async function Z({
1207
+ appId: h,
1208
+ pageId: l,
1209
+ outputPath: o,
1210
+ cachedAppData: d,
1211
+ isProduction: e
1212
+ }) {
1213
+ console.log(`Generating wrapper for app: ${h}, page: ${l}`);
1214
+ let p = o, n = !1;
1215
+ const i = o.split(".").pop()?.toLowerCase();
1216
+ if (i !== "tsx" && i !== "ts" && i !== "jsx" && i !== "js") {
1217
+ const { stat: s } = await import("fs/promises");
1218
+ try {
1219
+ (await s(o)).isDirectory() && (n = !0);
1220
+ } catch {
1221
+ (!i || o.endsWith("/")) && (n = !0);
1222
+ }
1223
+ }
1224
+ n && console.log(
1225
+ "Output path is a directory, will generate filename from app/page names"
1226
+ ), console.log(`Output path: ${o}`);
1227
+ const g = k(process.cwd(), ".temp-bravo", h, l);
1228
+ B(g) || await H(g, { recursive: !0 });
1229
+ const c = [
1230
+ {
1231
+ url: `${G}/devices/apps/${h}`,
1232
+ filename: "app.json",
1233
+ skipIfCached: !0
1234
+ },
1235
+ {
1236
+ url: `${G}/devices/apps/${h}/node/${l}`,
1237
+ filename: "page.json"
1238
+ },
1239
+ {
1240
+ url: `${se}/${h}/draft/components/${l}.js`,
1241
+ filename: "component.js"
1242
+ }
1243
+ ];
1244
+ for (const s of c) {
1245
+ if (s.skipIfCached && d) {
1246
+ console.log(`Using cached ${s.filename} (skipping download)`);
1247
+ const E = k(g, s.filename);
1248
+ await q(
1249
+ E,
1250
+ JSON.stringify(d, null, 2),
1251
+ "utf-8"
1252
+ ), console.log(`✓ Saved ${s.filename} from cache`);
1253
+ continue;
1254
+ }
1255
+ try {
1256
+ console.log(`Downloading ${s.filename} from ${s.url}...`);
1257
+ const E = await V(s.url, s.headers), t = k(g, s.filename);
1258
+ await q(t, E, "utf-8"), console.log(`✓ Saved ${s.filename}`);
1259
+ } catch (E) {
1260
+ throw console.error(`✗ Failed to download ${s.filename}:`, E), E;
1261
+ }
1262
+ }
1263
+ const y = k(g, "page.json"), m = await R(y, "utf-8"), N = JSON.parse(m);
1264
+ let r = N.data || N;
1265
+ if (console.log("Page response keys:", Object.keys(N)), N.data && console.log("Page data keys:", Object.keys(N.data)), console.log("Has body?", !!r.body), console.log("Has data.body?", !!r.data?.body), !r.body && !r.data?.body) {
1266
+ console.log("Page data doesn't have body, trying app.json...");
1267
+ try {
1268
+ let s = d;
1269
+ if (s)
1270
+ console.log("Using cached app.json data");
1271
+ else {
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
+ }
1333
+ }
1334
+ }
1335
+ }
1336
+ const C = ie(r), f = pe(r);
1337
+ let $ = "Encore App", A = "Page";
1338
+ try {
1339
+ let s = d;
1340
+ if (!s) {
1341
+ const E = k(g, "app.json");
1342
+ if (B(E)) {
1343
+ const t = await R(E, "utf-8");
1344
+ s = JSON.parse(t);
1345
+ }
1346
+ }
1347
+ s && ($ = s?.app?.store?.name || $, console.log(`App name: ${$}`));
1348
+ } catch {
1349
+ }
1350
+ A = r.name || r.id || A, console.log(`Page name: ${A}`), console.log(`
1351
+ Found ${C.length} slider(s):`), C.forEach((s, E) => {
1352
+ console.log(`
1353
+ Slider ${E + 1}:`), console.log(` ID: ${s.id}`), console.log(` Name: ${s.name}`), s.arrayContainer ? (console.log(
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);
1406
+ else {
1407
+ const s = ae(p);
1408
+ p = k(s, w);
1409
+ }
1410
+ console.log(`Component directory: ${w}`);
1411
+ const T = ge(
1412
+ h,
1413
+ l,
1414
+ j,
1415
+ C,
1416
+ f,
1417
+ x,
1418
+ _,
1419
+ S,
1420
+ v,
1421
+ !!e
1422
+ ), a = ye(
1423
+ h,
1424
+ l,
1425
+ $,
1426
+ A,
1427
+ j,
1428
+ C,
1429
+ f,
1430
+ x,
1431
+ _,
1432
+ S,
1433
+ v
1434
+ );
1435
+ if (B(p) || await H(p, { recursive: !0 }), e) {
1436
+ const s = k(g, "component.js");
1437
+ let E = "";
1438
+ try {
1439
+ E = await R(s, "utf-8");
1440
+ } catch (P) {
1441
+ console.warn("Could not read component.js for production build", P);
1442
+ }
1443
+ let t = d;
1444
+ if (!t)
1445
+ try {
1446
+ const P = k(g, "app.json"), I = await R(P, "utf-8");
1447
+ t = JSON.parse(I);
1448
+ } catch (P) {
1449
+ console.warn("Could not read app.json for production build", P);
1450
+ }
1451
+ const u = {
1452
+ app: t,
1453
+ page: r,
1454
+ componentCode: E
1455
+ };
1456
+ await q(k(p, "data.json"), JSON.stringify(u, null, 2), "utf-8"), console.log("✓ Generated data.json for production mode");
1457
+ }
1458
+ const b = k(p, "index.tsx"), D = k(p, "README.md");
1459
+ await q(b, T, "utf-8"), await q(D, a, "utf-8"), console.log(`
1460
+ ✓ Generated wrapper component at: ${b}`), console.log(`✓ Generated documentation at: ${D}`);
1461
+ }
1462
+ function X() {
1463
+ console.log(`
1464
+ Usage: generate-wrapper.ts <appId> [pageId] <outputPath>
1465
+
1466
+ Arguments:
1467
+ appId The Encore app ID
1468
+ pageId The Encore page ID (optional - if omitted, generates wrappers for ALL pages)
1469
+ outputPath Path where the generated TSX file(s) should be saved
1470
+
1471
+ Environment variables:
1472
+ APPS_SERVICE_URL Base URL for the apps service (default: http://localhost:3000)
1473
+
1474
+ Example:
1475
+ generate-wrapper.ts 01KA964B1T6KCKSKCNMYSTKRKZ 01KA964B2F42MN4WGCYDTG1Y70 ./src/components/MyEncoreApp.tsx
1476
+ generate-wrapper.ts 01KA964B1T6KCKSKCNMYSTKRKZ ./src/components/ (Generates all pages)
1477
+ `);
1478
+ }
1479
+ async function ve(h) {
1480
+ const l = h.includes("--production"), o = h.filter((n) => n !== "--production");
1481
+ if ((o.length < 2 || o.includes("--help") || o.includes("-h")) && (X(), process.exit(o.includes("--help") || o.includes("-h") ? 0 : 1)), o.length === 2) {
1482
+ const [n, i] = o;
1483
+ try {
1484
+ const { pages: g, appData: c } = await Pe(n);
1485
+ if (console.log(`Found ${g.length} pages.`), g.length === 0) {
1486
+ console.warn("No pages found for this app.");
1487
+ return;
1488
+ }
1489
+ console.log(
1490
+ `Caching app.json data for reuse across ${g.length} page(s)...`
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("----------------------------------------");
1496
+ try {
1497
+ await Z({
1498
+ appId: n,
1499
+ pageId: y.id,
1500
+ outputPath: i,
1501
+ cachedAppData: c,
1502
+ isProduction: l
1503
+ });
1504
+ } catch (m) {
1505
+ console.warn("Error with page:", m instanceof Error ? m.message : m);
1506
+ }
1507
+ }
1508
+ } catch (g) {
1509
+ console.error(`
1510
+ Error:`, g instanceof Error ? g.message : g), process.exit(1);
1511
+ }
1512
+ return;
1513
+ }
1514
+ const [d, e, p] = o;
1515
+ (!d || !e || !p) && (console.error("Error: Missing required arguments"), X(), process.exit(1));
1516
+ try {
1517
+ await Z({ appId: d, pageId: e, outputPath: p, isProduction: l });
1518
+ } catch (n) {
1519
+ console.error(`
1520
+ Error:`, n instanceof Error ? n.message : n), process.exit(1);
1521
+ }
1522
+ }
1523
+ export {
1524
+ ve as runGenerate
1525
+ };
1526
+ //# sourceMappingURL=generate.js.map