@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.
Files changed (48) hide show
  1. package/dist/_virtual/main.js +3 -2
  2. package/dist/cli/commands/generate.js +161 -1438
  3. package/dist/cli/commands/generate.js.map +1 -1
  4. package/dist/codegen/generator.js +473 -0
  5. package/dist/codegen/generator.js.map +1 -0
  6. package/dist/codegen/parser.js +720 -0
  7. package/dist/codegen/parser.js.map +1 -0
  8. package/dist/components/EncoreApp.js +197 -162
  9. package/dist/components/EncoreApp.js.map +1 -1
  10. package/dist/contexts/EncoreRouterContext.js +13 -0
  11. package/dist/contexts/EncoreRouterContext.js.map +1 -0
  12. package/dist/hooks/usePusherUpdates.js +4 -2
  13. package/dist/hooks/usePusherUpdates.js.map +1 -1
  14. package/dist/lib/dynamicModules.js +75 -85
  15. package/dist/lib/dynamicModules.js.map +1 -1
  16. package/dist/lib/moduleRegistry.js +20 -0
  17. package/dist/lib/moduleRegistry.js.map +1 -0
  18. package/dist/lib/packages.js +1 -3
  19. package/dist/lib/packages.js.map +1 -1
  20. package/dist/src/cli/commands/generate.d.ts.map +1 -1
  21. package/dist/src/codegen/generator.d.ts +10 -0
  22. package/dist/src/codegen/generator.d.ts.map +1 -0
  23. package/dist/src/codegen/index.d.ts +4 -0
  24. package/dist/src/codegen/index.d.ts.map +1 -0
  25. package/dist/src/codegen/parser.d.ts +37 -0
  26. package/dist/src/codegen/parser.d.ts.map +1 -0
  27. package/dist/src/codegen/types.d.ts +53 -0
  28. package/dist/src/codegen/types.d.ts.map +1 -0
  29. package/dist/src/components/EncoreApp.d.ts +5 -1
  30. package/dist/src/components/EncoreApp.d.ts.map +1 -1
  31. package/dist/src/contexts/EncoreRouterContext.d.ts +10 -0
  32. package/dist/src/contexts/EncoreRouterContext.d.ts.map +1 -0
  33. package/dist/src/hooks/useAuthRedirect.d.ts.map +1 -1
  34. package/dist/src/lib/dynamicModules.d.ts +1 -5
  35. package/dist/src/lib/dynamicModules.d.ts.map +1 -1
  36. package/dist/src/lib/moduleRegistry.d.ts +9 -0
  37. package/dist/src/lib/moduleRegistry.d.ts.map +1 -0
  38. package/dist/src/lib/packages.d.ts.map +1 -1
  39. package/package.json +1 -1
  40. package/src/cli/commands/generate.ts +88 -2723
  41. package/src/codegen/generator.ts +877 -0
  42. package/src/codegen/index.ts +3 -0
  43. package/src/codegen/parser.ts +1614 -0
  44. package/src/codegen/types.ts +58 -0
  45. package/src/components/EncoreApp.tsx +75 -22
  46. package/src/contexts/EncoreRouterContext.ts +28 -0
  47. package/src/hooks/useAuthRedirect.ts +56 -55
  48. package/src/lib/packages.ts +8 -15
@@ -1,61 +1,91 @@
1
- import { jsx as a } from "react/jsx-runtime";
2
- import K from "swr";
3
- import Z from "../lib/fetcher.js";
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import Y from "swr";
3
+ import _ from "../lib/fetcher.js";
4
4
  import d from "../stores/useEncoreState.js";
5
- import st, { useRef as ct, useState as S, useCallback as h, useEffect as i, useMemo as at, Suspense as it } from "react";
6
- import { setLocalModeOverride as M, isLocalMode as P } from "../lib/localMode.js";
7
- import lt from "../contexts/EncoreBindingContext.js";
8
- import dt from "../contexts/EncoreComponentIdContext.js";
9
- import ut from "../contexts/EncoreActionContext.js";
10
- import ft from "../contexts/EncoreRepeatingContainerContext.js";
11
- import ht from "./DynamicComponent.js";
12
- import { Link as mt } from "react-router-dom";
13
- import { usePusherUpdates as pt } from "../hooks/usePusherUpdates.js";
14
- const yt = (n) => n.setApp, gt = (n) => n.setAppId, wt = (n) => n.setPageId, xt = (n) => n.assetsById, Ft = ({
5
+ import lt, { useRef as q, useEffect as a, useState as O, useCallback as m, useMemo as at, Suspense as dt } from "react";
6
+ import { setLocalModeOverride as B, isLocalMode as $ } from "../lib/localMode.js";
7
+ import ut from "../contexts/EncoreBindingContext.js";
8
+ import ft from "../contexts/EncoreComponentIdContext.js";
9
+ import ht from "../contexts/EncoreActionContext.js";
10
+ import mt from "../contexts/EncoreRepeatingContainerContext.js";
11
+ import pt from "./DynamicComponent.js";
12
+ import { useEncoreRouter as yt } from "../contexts/EncoreRouterContext.js";
13
+ import { usePusherUpdates as gt } from "../hooks/usePusherUpdates.js";
14
+ const wt = ({ to: n, children: l, style: b, ...w }) => {
15
+ const { navigate: u } = yt();
16
+ return /* @__PURE__ */ i(
17
+ "a",
18
+ {
19
+ href: n,
20
+ onClick: (p) => {
21
+ p.preventDefault(), u(n);
22
+ },
23
+ style: { cursor: "pointer", ...b },
24
+ ...w,
25
+ children: l
26
+ }
27
+ );
28
+ }, vt = (n) => n.setApp, Et = (n) => n.setAppId, Rt = (n) => n.setPageId, xt = (n) => n.assetsById, Dt = ({
15
29
  appId: n,
16
30
  pageId: l,
17
- componentId: G,
18
- fallback: C,
19
- onSizeChange: y,
20
- onAction: Y,
21
- data: g,
22
- source: u,
23
- repeatingContainerControls: m,
24
- inputGroups: R,
25
- baseURL: v,
26
- appDefinition: w,
27
- pageDefinition: A,
28
- componentCode: _
31
+ componentId: b,
32
+ fallback: w,
33
+ onSizeChange: u,
34
+ onContentSizeChange: p,
35
+ onAction: J,
36
+ data: v,
37
+ source: f,
38
+ repeatingContainerControls: y,
39
+ inputGroups: A,
40
+ baseURL: M,
41
+ appDefinition: E,
42
+ pageDefinition: P,
43
+ componentCode: Q
29
44
  }) => {
30
- console.log("Render: EncoreApp"), console.log("🔥 ENCORE-LIB SOURCE CODE IS ACTIVE 🔥"), console.log("✨ ENCORE-LIB UPDATED - TEST MESSAGE ✨"), v && d.getState().baseURL !== v && d.getState().setBaseURL(v), u && M(u === "local" ? "local" : "remote");
31
- const q = !1, B = d(yt), O = d(gt), $ = d(wt), p = d(xt), L = ct(null), [J, Q] = S(0), X = h(() => {
32
- Q((e) => typeof e == "number" ? e + 1 : Date.now());
45
+ console.log("Render: EncoreApp"), console.log("🔥 ENCORE-LIB SOURCE CODE IS ACTIVE 🔥"), console.log("✨ ENCORE-LIB UPDATED - TEST MESSAGE ✨"), M && d.getState().baseURL !== M && d.getState().setBaseURL(M), f && B(f === "local" ? "local" : "remote");
46
+ const X = !1, C = d(vt), L = d(Et), I = d(Rt), g = d(xt), F = q(null), k = q(null);
47
+ a(() => {
48
+ if (!p) return;
49
+ const t = k.current;
50
+ if (!t) return;
51
+ const r = () => {
52
+ p({
53
+ width: t.scrollWidth,
54
+ height: t.scrollHeight
55
+ });
56
+ }, e = new ResizeObserver(() => {
57
+ r();
58
+ });
59
+ return r(), e.observe(t), () => e.disconnect();
60
+ }, [p]);
61
+ const [tt, et] = O(0), rt = m(() => {
62
+ et((t) => typeof t == "number" ? t + 1 : Date.now());
33
63
  }, []);
34
- pt({
64
+ gt({
35
65
  appId: n,
36
66
  pageId: l || void 0,
37
- enabled: !P() && !w,
38
- onUpdate: X
67
+ enabled: !$() && !E,
68
+ onUpdate: rt
39
69
  });
40
- const I = u === "local" || P(), F = w ? null : n && `/devices/apps/${n}${I ? "?useLocal=1" : ""}`, tt = K(F, Z, {
41
- suspense: !!F
70
+ const W = f === "local" || $(), D = E ? null : n && `/devices/apps/${n}${W ? "?useLocal=1" : ""}`, ot = Y(D, _, {
71
+ suspense: !!D
42
72
  // Only use suspense if we are fetching
43
- }), f = w ? { data: w } : tt;
44
- i(() => {
45
- B(f.data);
46
- }, [f.data, B]), i(() => {
47
- const e = f?.data?.app?.fonts ?? [];
48
- !e || e.length === 0 || typeof window > "u" || !("FontFace" in window) || e.forEach((o) => {
73
+ }), h = E ? { data: E } : ot;
74
+ a(() => {
75
+ C(h.data);
76
+ }, [h.data, C]), a(() => {
77
+ const t = h?.data?.app?.fonts ?? [];
78
+ !t || t.length === 0 || typeof window > "u" || !("FontFace" in window) || t.forEach((r) => {
49
79
  try {
50
- const t = o?.fontName?.family, r = o?.url, s = o?.fontName?.postScriptName;
51
- if (!t || !r) return;
80
+ const e = r?.fontName?.family, o = r?.url, s = r?.fontName?.postScriptName;
81
+ if (!e || !o) return;
52
82
  let c;
53
83
  if (s) {
54
- const E = s.match(
84
+ const x = s.match(
55
85
  /(?:^|-)(Thin|ExtraLight|Light|Regular|Medium|SemiBold|Bold|ExtraBold|Black)(?:-|$)/i
56
86
  );
57
- if (E) {
58
- const nt = E[1].toLowerCase();
87
+ if (x) {
88
+ const it = x[1].toLowerCase();
59
89
  c = {
60
90
  thin: 100,
61
91
  extralight: 200,
@@ -66,194 +96,199 @@ const yt = (n) => n.setApp, gt = (n) => n.setAppId, wt = (n) => n.setPageId, xt
66
96
  bold: 700,
67
97
  extrabold: 800,
68
98
  black: 900
69
- }[nt] || 400;
99
+ }[it] || 400;
70
100
  }
71
101
  }
72
- (c !== void 0 ? new FontFace(t, `url(${r})`, { weight: c.toString() }) : new FontFace(t, `url(${r})`)).load().then((E) => {
73
- document.fonts.add(E);
102
+ (c !== void 0 ? new FontFace(e, `url(${o})`, { weight: c.toString() }) : new FontFace(e, `url(${o})`)).load().then((x) => {
103
+ document.fonts.add(x);
74
104
  }).catch(() => {
75
105
  });
76
106
  } catch {
77
107
  }
78
108
  });
79
- }, [f?.data]), i(() => {
80
- O(n);
81
- }, [n, O]), i(() => {
82
- l && $(l);
83
- }, [l, $]), i(() => {
84
- Object.keys(p).length !== 0 && (async () => await Promise.allSettled(
85
- Object.keys(p).map((e) => p[e].url ? new Promise((o) => {
86
- const t = new Image();
87
- t.onload = o, t.onerror = o, t.src = p[e].url;
109
+ }, [h?.data]), a(() => {
110
+ L(n);
111
+ }, [n, L]), a(() => {
112
+ l && I(l);
113
+ }, [l, I]), a(() => {
114
+ Object.keys(g).length !== 0 && (async () => await Promise.allSettled(
115
+ Object.keys(g).map((t) => g[t].url ? new Promise((r) => {
116
+ const e = new Image();
117
+ e.onload = r, e.onerror = r, e.src = g[t].url;
88
118
  }) : Promise.resolve())
89
119
  ))();
90
- }, [p]);
91
- const k = A ? null : n && l && `/devices/apps/${n}/node/${l}${I ? "?useLocal=1" : ""}`, et = K(k, Z, { suspense: !!k }), N = A ? { data: A } : et, ot = at(() => {
92
- let e = N.data?.clientData;
93
- const o = (t) => {
94
- if (!(!t || typeof t != "object")) {
95
- if (t.children && Array.isArray(t.children) && t.children.length > 1) {
96
- let r = 0, s = 0;
97
- t.children.forEach((b) => {
98
- b.style?.width && (r += b.style.width, s++);
99
- }), (Math.abs(r - 100) < 1 || Math.abs(r - 375) < 5) && s >= 2 && (t.style || (t.style = {}), t.style.layout || (t.style.layout = {}), t.style.layout.mode || (console.log(
100
- `[PATCH] Forcing HORIZONTAL layout for node ${t.id} (${s} children, widths sum: ${r})`
101
- ), t.style.layout.mode = "HORIZONTAL", t.style.layout.primaryAxisAlignItems = "flex-start", t.style.layout.counterAxisAlignItems = "flex-start"));
120
+ }, [g]);
121
+ const N = P ? null : n && l && `/devices/apps/${n}/node/${l}${W ? "?useLocal=1" : ""}`, nt = Y(N, _, { suspense: !!N }), U = P ? { data: P } : nt, st = at(() => {
122
+ let t = U.data?.clientData;
123
+ const r = (e) => {
124
+ if (!(!e || typeof e != "object")) {
125
+ if (e.children && Array.isArray(e.children) && e.children.length > 1) {
126
+ let o = 0, s = 0;
127
+ e.children.forEach((S) => {
128
+ S.style?.width && (o += S.style.width, s++);
129
+ }), (Math.abs(o - 100) < 1 || Math.abs(o - 375) < 5) && s >= 2 && (e.style || (e.style = {}), e.style.layout || (e.style.layout = {}), e.style.layout.mode || (console.log(
130
+ `[PATCH] Forcing HORIZONTAL layout for node ${e.id} (${s} children, widths sum: ${o})`
131
+ ), e.style.layout.mode = "HORIZONTAL", e.style.layout.primaryAxisAlignItems = "flex-start", e.style.layout.counterAxisAlignItems = "flex-start"));
102
132
  }
103
- t.children && (Array.isArray(t.children) ? t.children.forEach(o) : o(t.children));
133
+ e.children && (Array.isArray(e.children) ? e.children.forEach(r) : r(e.children));
104
134
  }
105
135
  };
106
- return e && o(e), {
136
+ return t && r(t), {
107
137
  nodeData: void 0,
108
138
  // Allow overriding specific values by element id.
109
139
  // For now, this is used to override TextComponent content when the node has the PROP:TEXT_VAR tag.
110
- textOverridesById: g,
140
+ textOverridesById: v,
111
141
  // Support for encore:data:array tags - provide array data by component ID
112
- arrayDataById: g,
142
+ arrayDataById: v,
113
143
  // Support for standalone component data binding (encore:data tags at root level)
114
- rootData: g
144
+ rootData: v
115
145
  };
116
- }, [N.data?.clientData, g]), [U, j] = S(/* @__PURE__ */ new Map()), [x, D] = S(/* @__PURE__ */ new Map());
117
- i(() => {
118
- m && D((e) => {
119
- let o = !1;
120
- if (e.size !== Object.keys(m).length)
121
- o = !0;
146
+ }, [U.data?.clientData, v]), [j, T] = O(/* @__PURE__ */ new Map()), [R, H] = O(/* @__PURE__ */ new Map());
147
+ a(() => {
148
+ y && H((t) => {
149
+ let r = !1;
150
+ if (t.size !== Object.keys(y).length)
151
+ r = !0;
122
152
  else
123
- for (const [r, s] of Object.entries(
124
- m
153
+ for (const [o, s] of Object.entries(
154
+ y
125
155
  )) {
126
- const c = e.get(r);
156
+ const c = t.get(o);
127
157
  if (!c) {
128
- o = !0;
158
+ r = !0;
129
159
  break;
130
160
  }
131
161
  if (c.currentIndex !== s.currentIndex || c.onIndexChange !== s.onIndexChange) {
132
- o = !0;
162
+ r = !0;
133
163
  break;
134
164
  }
135
165
  }
136
- if (!o) return e;
137
- const t = /* @__PURE__ */ new Map();
138
- return Object.entries(m).forEach(([r, s]) => {
139
- t.set(r, s);
140
- }), t;
166
+ if (!r) return t;
167
+ const e = /* @__PURE__ */ new Map();
168
+ return Object.entries(y).forEach(([o, s]) => {
169
+ e.set(o, s);
170
+ }), e;
141
171
  });
142
- }, [m]), i(() => {
143
- if (R) {
144
- const e = d.getState().setInputGroupValue;
145
- Object.entries(R).forEach(([o, t]) => {
146
- e(o, t);
172
+ }, [y]), a(() => {
173
+ if (A) {
174
+ const t = d.getState().setInputGroupValue;
175
+ Object.entries(A).forEach(([r, e]) => {
176
+ t(r, e);
147
177
  });
148
178
  }
149
- }, [R]);
150
- const T = h(
151
- (e, o) => {
152
- j((t) => {
153
- const r = new Map(t);
154
- return r.set(e, o), r;
179
+ }, [A]);
180
+ const V = m(
181
+ (t, r) => {
182
+ T((e) => {
183
+ const o = new Map(e);
184
+ return o.set(t, r), o;
155
185
  });
156
186
  },
157
187
  []
158
- ), W = h((e) => {
159
- j((o) => {
160
- const t = new Map(o);
161
- return t.delete(e), t;
188
+ ), K = m((t) => {
189
+ T((r) => {
190
+ const e = new Map(r);
191
+ return e.delete(t), e;
162
192
  });
163
- }, []), V = h(
164
- (e) => U.get(e),
165
- [U]
166
- ), H = h(
167
- (e, o) => {
168
- D((t) => {
169
- const r = new Map(t), s = r.get(e) || {}, c = typeof o == "function" ? o(s) : o;
170
- return r.set(e, c), r;
193
+ }, []), Z = m(
194
+ (t) => j.get(t),
195
+ [j]
196
+ ), z = m(
197
+ (t, r) => {
198
+ H((e) => {
199
+ const o = new Map(e), s = o.get(t) || {}, c = typeof r == "function" ? r(s) : r;
200
+ return o.set(t, c), o;
171
201
  });
172
202
  },
173
203
  []
174
- ), z = h(
175
- (e) => x.get(e),
176
- [x]
177
- ), rt = st.useMemo(
204
+ ), G = m(
205
+ (t) => R.get(t),
206
+ [R]
207
+ ), ct = lt.useMemo(
178
208
  () => ({
179
- registerContainer: T,
180
- unregisterContainer: W,
181
- getControl: V,
182
- setControlProps: H,
183
- getControlProps: z,
209
+ registerContainer: V,
210
+ unregisterContainer: K,
211
+ getControl: Z,
212
+ setControlProps: z,
213
+ getControlProps: G,
184
214
  // Include controlPropsMap size in the value to trigger re-renders when it changes
185
- _propsVersion: x.size
215
+ _propsVersion: R.size
186
216
  }),
187
217
  [
188
- T,
189
- W,
190
218
  V,
191
- H,
219
+ K,
220
+ Z,
192
221
  z,
193
- x.size
222
+ G,
223
+ R.size
194
224
  ]
195
225
  );
196
- return i(() => {
197
- if (!y) return;
198
- const e = L.current;
199
- if (!e) return;
200
- const o = (s) => {
226
+ return a(() => {
227
+ if (!u) return;
228
+ const t = F.current;
229
+ if (!t) return;
230
+ const r = (s) => {
201
231
  const c = s.contentRect;
202
- y({ width: c.width, height: c.height });
203
- }, t = new ResizeObserver((s) => {
232
+ u({ width: c.width, height: c.height });
233
+ }, e = new ResizeObserver((s) => {
204
234
  for (const c of s)
205
- o(c);
206
- }), r = e.getBoundingClientRect();
207
- return y({ width: r.width, height: r.height }), t.observe(e), () => {
208
- t.disconnect();
235
+ r(c);
236
+ }), o = t.getBoundingClientRect();
237
+ return u({ width: o.width, height: o.height }), e.observe(t), () => {
238
+ e.disconnect();
209
239
  };
210
- }, [y]), i(() => {
211
- if (u)
212
- return M(u === "local" ? "local" : "remote"), () => {
213
- M(null);
240
+ }, [u]), a(() => {
241
+ if (f)
242
+ return B(f === "local" ? "local" : "remote"), () => {
243
+ B(null);
214
244
  };
215
- }, [u]), l ? /* @__PURE__ */ a(
245
+ }, [f]), l ? /* @__PURE__ */ i(
216
246
  "div",
217
247
  {
218
- ref: L,
219
- style: { width: "100%", height: "100%", position: "relative" },
220
- children: /* @__PURE__ */ a(it, { fallback: C || /* @__PURE__ */ a("div", {}), children: /* @__PURE__ */ a(dt.Provider, { value: { componentId: G }, children: /* @__PURE__ */ a(ut.Provider, { value: { onAction: Y }, children: /* @__PURE__ */ a(
221
- ft.Provider,
248
+ ref: F,
249
+ style: {
250
+ width: "100%",
251
+ height: "100%",
252
+ position: "relative",
253
+ overflow: "hidden"
254
+ },
255
+ children: /* @__PURE__ */ i("div", { ref: k, style: { width: "100%", minHeight: "100%" }, children: /* @__PURE__ */ i(dt, { fallback: w || /* @__PURE__ */ i("div", {}), children: /* @__PURE__ */ i(ft.Provider, { value: { componentId: b }, children: /* @__PURE__ */ i(ht.Provider, { value: { onAction: J }, children: /* @__PURE__ */ i(
256
+ mt.Provider,
222
257
  {
223
- value: rt,
224
- children: /* @__PURE__ */ a(lt.Provider, { value: ot, children: /* @__PURE__ */ a(
225
- ht,
258
+ value: ct,
259
+ children: /* @__PURE__ */ i(ut.Provider, { value: st, children: /* @__PURE__ */ i(
260
+ pt,
226
261
  {
227
262
  name: `${n}/draft/components/${l}`,
228
- fallback: C,
229
- reloadKey: J,
230
- componentCode: _,
263
+ fallback: w,
264
+ reloadKey: tt,
265
+ componentCode: Q,
231
266
  children: " "
232
267
  }
233
268
  ) })
234
269
  }
235
- ) }) }) })
270
+ ) }) }) }) })
236
271
  }
237
- ) : /* @__PURE__ */ a("div", { style: { padding: "30px" }, children: /* @__PURE__ */ a("div", { style: { overflowY: "auto" }, children: (P() ? (
272
+ ) : /* @__PURE__ */ i("div", { style: { padding: "30px" }, children: /* @__PURE__ */ i("div", { style: { overflowY: "auto" }, children: ($() ? (
238
273
  // Local mode: app.json provides pages under app.data.pages
239
- (f?.data?.app?.data?.pages || []).map(
240
- (e) => e?.id
274
+ (h?.data?.app?.data?.pages || []).map(
275
+ (t) => t?.id
241
276
  )
242
- ) : f?.data?.app.pageIds || []).map((e) => /* @__PURE__ */ a(
243
- mt,
277
+ ) : h?.data?.app.pageIds || []).map((t) => /* @__PURE__ */ i(
278
+ wt,
244
279
  {
245
- to: `/apps/${n}/pages/${e}?noRedirect=${q}`,
280
+ to: `/apps/${n}/pages/${t}?noRedirect=${X}`,
246
281
  style: {
247
282
  fontSize: 20,
248
283
  display: "block",
249
284
  marginBottom: "10px"
250
285
  },
251
- children: e
286
+ children: t
252
287
  },
253
- e
288
+ t
254
289
  )) }) });
255
290
  };
256
291
  export {
257
- Ft as default
292
+ Dt as default
258
293
  };
259
294
  //# sourceMappingURL=EncoreApp.js.map