@bravostudioai/react 0.1.8 → 0.1.10

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