@fragmentsx/runtime-react 0.2.0-dev-20260928114300 → 0.2.0-dev-20260928123417

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,33 +1,33 @@
1
- import { jsx as d, jsxs as te, Fragment as ne } from "react/jsx-runtime";
2
- import * as ae from "react";
3
- import { createContext as A, useContext as v, useMemo as N, useState as w, useEffect as y, useLayoutEffect as se, version as ue, Component as ce, Suspense as K, createElement as le, useCallback as _, useRef as H, useReducer as oe } from "react";
4
- import { FragmentsAreaError as de, toScopeClassName as ie, AREA_GLOBAL_CSS_KEY as fe, resolveStylesHref as me, fragmentCssKey as he, createSourceCache as Ee, sourceCallKey as j, sourceTransportKey as ve, resolveSourceRequest as ge, runSourceFetch as ye, createFragmentsClient as Se } from "@fragmentsx/fragments-client";
5
- import { FragmentsApiVersionError as Qe, FragmentsAreaError as We, FragmentsLoadError as Xe, createSourceCache as Ze } from "@fragmentsx/fragments-client";
6
- const k = A(
1
+ import { jsx as o, jsxs as ae, Fragment as se } from "react/jsx-runtime";
2
+ import * as ue from "react";
3
+ import { createContext as S, useContext as E, useMemo as w, useState as F, useEffect as g, useLayoutEffect as ce, version as le, Component as oe, Suspense as z, createElement as de, useCallback as x, useRef as G, useReducer as fe } from "react";
4
+ import { FragmentsAreaError as ie, toScopeClassName as me, AREA_GLOBAL_CSS_KEY as he, resolveStylesHref as Ee, fragmentCssKey as ve, createSourceCache as ge, sourceCallKey as L, sourceTransportKey as ye, resolveSourceRequest as Se, runSourceFetch as Ae, createFragmentsClient as ke } from "@fragmentsx/fragments-client";
5
+ import { FragmentsApiVersionError as Xe, FragmentsAreaError as Ze, FragmentsLoadError as er, createSourceCache as rr } from "@fragmentsx/fragments-client";
6
+ const A = S(
7
7
  null
8
8
  );
9
- k.displayName = "FragmentsClientContext";
10
- function Ae(r) {
11
- return /* @__PURE__ */ d(k.Provider, { value: r.value, children: r.children });
9
+ A.displayName = "FragmentsClientContext";
10
+ function Ce(r) {
11
+ return /* @__PURE__ */ o(A.Provider, { value: r.value, children: r.children });
12
12
  }
13
- function ke() {
14
- return v(k);
13
+ function Pe() {
14
+ return E(A);
15
15
  }
16
- const z = A(null);
17
- z.displayName = "InstanceIdContext";
18
- const F = A(
16
+ const Y = S(null);
17
+ Y.displayName = "InstanceIdContext";
18
+ const T = S(
19
19
  null
20
20
  );
21
- F.displayName = "ModulesMapContext";
22
- function Ce({
21
+ T.displayName = "ModulesMapContext";
22
+ function Ne({
23
23
  value: r,
24
24
  children: e
25
25
  }) {
26
- return /* @__PURE__ */ d(F.Provider, { value: r, children: e });
26
+ return /* @__PURE__ */ o(T.Provider, { value: r, children: e });
27
27
  }
28
- function Ue() {
29
- const r = v(k);
30
- return N(
28
+ function pe() {
29
+ const r = E(A);
30
+ return w(
31
31
  () => ({
32
32
  reachGoal: (e) => {
33
33
  var t, n;
@@ -37,13 +37,13 @@ function Ue() {
37
37
  [r]
38
38
  );
39
39
  }
40
- function Pe(r) {
41
- const e = v(F);
40
+ function we(r) {
41
+ const e = E(T);
42
42
  if (!e)
43
43
  throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");
44
44
  return e.read(r);
45
45
  }
46
- const $ = typeof window < "u", L = Object.freeze({
46
+ const D = typeof window < "u", U = Object.freeze({
47
47
  rootFragmentId: 0,
48
48
  variantId: null,
49
49
  props: {},
@@ -56,72 +56,72 @@ const $ = typeof window < "u", L = Object.freeze({
56
56
  slots: {},
57
57
  sources: {}
58
58
  });
59
- function R(r) {
59
+ function _(r) {
60
60
  const e = r.$area;
61
61
  if (!(e != null && e.read))
62
62
  throw new Error("[useArea] $area plugin not mounted");
63
63
  return e;
64
64
  }
65
- function Ne(r, e) {
66
- const t = v(k);
65
+ function Fe(r, e) {
66
+ const t = E(A);
67
67
  if (!t)
68
68
  throw new Error("[useArea] No FragmentsClientProvider in tree");
69
- const n = (e == null ? void 0 : e.suspense) ?? !0, s = (e == null ? void 0 : e.pause) === !0 || !$ && (e == null ? void 0 : e.ssr) === !1, a = (e == null ? void 0 : e.timeout) != null ? { timeout: e.timeout } : void 0, [, i] = w(0);
70
- if (y(() => {
69
+ const n = (e == null ? void 0 : e.suspense) ?? !0, s = (e == null ? void 0 : e.pause) === !0 || !D && (e == null ? void 0 : e.ssr) === !1, a = (e == null ? void 0 : e.timeout) != null ? { timeout: e.timeout } : void 0, [, i] = F(0);
70
+ if (g(() => {
71
71
  if (n || s) return;
72
- const l = R(t);
73
- let u = !0;
74
- return Promise.resolve(l.resolve(r, a)).catch(() => {
72
+ const u = _(t);
73
+ let l = !0;
74
+ return Promise.resolve(u.resolve(r, a)).catch(() => {
75
75
  }).finally(() => {
76
- u && i((E) => E + 1);
76
+ l && i((d) => d + 1);
77
77
  }), () => {
78
- u = !1;
78
+ l = !1;
79
79
  };
80
80
  }, [r, n, e == null ? void 0 : e.pause, e == null ? void 0 : e.timeout, e == null ? void 0 : e.ssr]), n) {
81
81
  if (s)
82
- return L;
83
- const l = R(t);
84
- if (l.has(r) || Promise.resolve(l.resolve(r, a)).catch(() => {
85
- }), !$)
82
+ return U;
83
+ const u = _(t);
84
+ if (u.has(r) || Promise.resolve(u.resolve(r, a)).catch(() => {
85
+ }), !D)
86
86
  try {
87
- return l.read(r);
88
- } catch (u) {
89
- if (u != null && typeof u.then == "function")
90
- throw u;
87
+ return u.read(r);
88
+ } catch (l) {
89
+ if (l != null && typeof l.then == "function")
90
+ throw l;
91
91
  return process.env.NODE_ENV !== "production" && console.error(
92
92
  `[useArea] Area ${r} remained unresolved on the server because its cache reached a terminal state`,
93
- u
94
- ), L;
93
+ l
94
+ ), U;
95
95
  }
96
- return l.read(r);
96
+ return u.read(r);
97
97
  }
98
98
  if (s)
99
99
  return { status: "idle", data: null, error: null };
100
- const c = R(t);
101
- if (c.has(r))
100
+ const m = _(t);
101
+ if (m.has(r))
102
102
  try {
103
- return { status: "ready", data: c.read(r), error: null };
104
- } catch (l) {
103
+ return { status: "ready", data: m.read(r), error: null };
104
+ } catch (u) {
105
105
  return {
106
106
  status: "not-found",
107
107
  data: null,
108
- error: l instanceof Error ? l : new Error(String(l))
108
+ error: u instanceof Error ? u : new Error(String(u))
109
109
  };
110
110
  }
111
- return Promise.resolve(c.resolve(r, a)).catch(() => {
111
+ return Promise.resolve(m.resolve(r, a)).catch(() => {
112
112
  }), { status: "loading", data: null, error: null };
113
113
  }
114
- const G = typeof window < "u", we = 3e3, P = /* @__PURE__ */ new Map(), Y = (r, e) => {
115
- if (!G) {
114
+ const J = typeof window < "u", Te = 3e3, N = /* @__PURE__ */ new Map(), q = (r, e) => {
115
+ if (!J) {
116
116
  const h = () => {
117
117
  };
118
118
  return h.loaded = Promise.resolve(), h;
119
119
  }
120
- const t = P.get(e);
120
+ const t = N.get(e);
121
121
  if (t) {
122
122
  t.refCount += 1;
123
123
  const h = () => {
124
- t.refCount -= 1, t.refCount === 0 && (t.clearReadyTimer(), t.linkEl.remove(), P.delete(e));
124
+ t.refCount -= 1, t.refCount === 0 && (t.clearReadyTimer(), t.linkEl.remove(), N.delete(e));
125
125
  };
126
126
  return h.loaded = t.loaded, h;
127
127
  }
@@ -131,25 +131,25 @@ const G = typeof window < "u", we = 3e3, P = /* @__PURE__ */ new Map(), Y = (r,
131
131
  const a = new Promise((h) => {
132
132
  s = h;
133
133
  }), i = () => {
134
- l(), s();
135
- }, c = setTimeout(i, we), l = () => clearTimeout(c);
134
+ u(), s();
135
+ }, m = setTimeout(i, Te), u = () => clearTimeout(m);
136
136
  n.addEventListener("load", i), n.addEventListener("error", i), document.head.appendChild(n);
137
- const u = { refCount: 1, linkEl: n, loaded: a, clearReadyTimer: l };
138
- P.set(e, u);
139
- const E = () => {
140
- u.refCount -= 1, u.refCount === 0 && (u.clearReadyTimer(), u.linkEl.remove(), P.delete(e));
137
+ const l = { refCount: 1, linkEl: n, loaded: a, clearReadyTimer: u };
138
+ N.set(e, l);
139
+ const d = () => {
140
+ l.refCount -= 1, l.refCount === 0 && (l.clearReadyTimer(), l.linkEl.remove(), N.delete(e));
141
141
  };
142
- return E.loaded = a, E;
143
- }, Fe = G ? se : y;
144
- function Te(r, e) {
145
- Fe(() => Y(r, e), [r, e]);
142
+ return d.loaded = a, d;
143
+ }, Re = J ? ce : g;
144
+ function _e(r, e) {
145
+ Re(() => q(r, e), [r, e]);
146
146
  }
147
- const Re = parseInt(ue.split(".")[0], 10), _e = Re >= 19;
148
- function D({
147
+ const xe = parseInt(le.split(".")[0], 10), Oe = xe >= 19;
148
+ function V({
149
149
  href: r,
150
150
  fragmentKey: e
151
151
  }) {
152
- return _e ? /* @__PURE__ */ d(
152
+ return Oe ? /* @__PURE__ */ o(
153
153
  "link",
154
154
  {
155
155
  rel: "stylesheet",
@@ -157,48 +157,48 @@ function D({
157
157
  precedence: "default",
158
158
  "data-fragment-key": e
159
159
  }
160
- ) : (Te(r, e), null);
160
+ ) : (_e(r, e), null);
161
161
  }
162
- function pe(r) {
162
+ function Ke(r) {
163
163
  }
164
- const J = {}, x = A(null);
165
- x.displayName = "ProjectPropertiesContext";
166
- const q = Object.freeze({}), O = A(q);
167
- O.displayName = "SourceTransportsContext";
168
- const b = A("live");
169
- b.displayName = "SourceNetworkContext";
170
- function V(r) {
164
+ const Q = {}, O = S(null);
165
+ O.displayName = "ProjectPropertiesContext";
166
+ const W = Object.freeze({}), b = S(W);
167
+ b.displayName = "SourceTransportsContext";
168
+ const I = S("live");
169
+ I.displayName = "SourceNetworkContext";
170
+ function B(r) {
171
171
  const e = r instanceof Error ? r : new Error(String(r));
172
- if (!(e instanceof de))
172
+ if (!(e instanceof ie))
173
173
  return { kind: "failed", error: e };
174
174
  const { code: t } = e;
175
175
  return t === "NO_ACTIVE_VARIANT" ? { kind: "no-variant", code: t, error: e } : t === "AREA_NOT_FOUND" || t === "NO_PUBLISHED_SNAPSHOT" || t === "NESTED_SNAPSHOT_MISSING" ? { kind: "misconfigured", code: t, error: e } : { kind: "failed", code: t, error: e };
176
176
  }
177
- function Q(r, e, t) {
177
+ function X(r, e, t) {
178
178
  return typeof r == "function" ? r(e, t) : r ?? null;
179
179
  }
180
- const xe = () => {
180
+ const be = () => {
181
181
  };
182
- function U(r) {
182
+ function p(r) {
183
183
  return r instanceof Error ? r : new Error(String(r));
184
184
  }
185
- class W extends ce {
185
+ class Z extends oe {
186
186
  constructor() {
187
187
  super(...arguments), this.state = { hasError: !1, error: null };
188
188
  }
189
189
  static getDerivedStateFromError(e) {
190
- return { hasError: !0, error: U(e) };
190
+ return { hasError: !0, error: p(e) };
191
191
  }
192
192
  componentDidCatch(e, t) {
193
193
  var s, a;
194
- const n = U(e);
194
+ const n = p(e);
195
195
  process.env.NODE_ENV !== "production" && console.error("[fragments] Area error:", n, t.componentStack), (a = (s = this.props).onError) == null || a.call(s, n);
196
196
  }
197
197
  render() {
198
198
  if (this.state.hasError) {
199
199
  const e = { kind: "failed", error: this.state.error ?? new Error("Unknown Area error") };
200
200
  try {
201
- return Q(this.props.empty, e, this.props.retry ?? xe);
201
+ return X(this.props.empty, e, this.props.retry ?? be);
202
202
  } catch {
203
203
  return null;
204
204
  }
@@ -206,17 +206,17 @@ class W extends ce {
206
206
  return this.props.children;
207
207
  }
208
208
  }
209
- function X(r, e) {
209
+ function ee(r, e) {
210
210
  if (!r) return {};
211
211
  const t = {};
212
212
  for (const n of Object.keys(r))
213
- t[n] = Oe(r[n], e);
213
+ t[n] = Ie(r[n], e);
214
214
  return t;
215
215
  }
216
- function Oe(r, e) {
217
- return Array.isArray(r) ? r.map((t, n) => t === null ? null : p(t, e, n)) : p(r, e);
216
+ function Ie(r, e) {
217
+ return Array.isArray(r) ? r.map((t, n) => t === null ? null : K(t, e, n)) : K(r, e);
218
218
  }
219
- function p(r, e, t) {
219
+ function K(r, e, t) {
220
220
  let n;
221
221
  try {
222
222
  n = e(r.fragmentId);
@@ -225,169 +225,169 @@ function p(r, e, t) {
225
225
  throw a;
226
226
  return console.warn(`[FragmentRenderer] Slot fragment ${r.fragmentId} failed to load — rendering empty hole`, a), null;
227
227
  }
228
- const s = X(r.slots, e);
229
- return le(n, { key: t, ...r.props, ...s });
228
+ const s = ee(r.slots, e);
229
+ return de(n, { key: t, ...r.props, ...s });
230
230
  }
231
- const Z = ({
231
+ const re = ({
232
232
  fragmentId: r,
233
233
  props: e,
234
234
  globalCssUrl: t = null,
235
- projectProperties: n = J,
235
+ projectProperties: n = Q,
236
236
  fragments: s = [r],
237
237
  slots: a,
238
- sources: i = q,
239
- sourceNetwork: c = "live"
238
+ sources: i = W,
239
+ sourceNetwork: m = "live"
240
240
  }) => {
241
- const l = Pe(r), u = v(F);
242
- if (!u)
241
+ const u = we(r), l = E(T);
242
+ if (!l)
243
243
  throw new Error("[FragmentRendererInner] No ModulesMapProvider in tree");
244
- const E = X(a, u.read), h = { ...e ?? {}, ...E }, o = s.length > 0 ? s.map(ie).join(" ") : void 0;
245
- return /* @__PURE__ */ te(ne, { children: [
246
- t != null && /* @__PURE__ */ d(
247
- D,
244
+ const d = ee(a, l.read), h = { ...e ?? {}, ...d }, y = s.length > 0 ? s.map(me).join(" ") : void 0;
245
+ return /* @__PURE__ */ ae(se, { children: [
246
+ t != null && /* @__PURE__ */ o(
247
+ V,
248
248
  {
249
249
  href: t,
250
- fragmentKey: fe
250
+ fragmentKey: he
251
251
  }
252
252
  ),
253
- s.map((m) => {
254
- const g = me(m);
255
- return g ? /* @__PURE__ */ d(
256
- D,
253
+ s.map((c) => {
254
+ const v = Ee(c);
255
+ return v ? /* @__PURE__ */ o(
256
+ V,
257
257
  {
258
- href: g,
259
- fragmentKey: he(m)
258
+ href: v,
259
+ fragmentKey: ve(c)
260
260
  },
261
- m
261
+ c
262
262
  ) : null;
263
263
  }),
264
- /* @__PURE__ */ d(b.Provider, { value: c, children: /* @__PURE__ */ d(O.Provider, { value: i, children: /* @__PURE__ */ d(x.Provider, { value: n, children: /* @__PURE__ */ d(z.Provider, { value: null, children: /* @__PURE__ */ d(
264
+ /* @__PURE__ */ o(I.Provider, { value: m, children: /* @__PURE__ */ o(b.Provider, { value: i, children: /* @__PURE__ */ o(O.Provider, { value: n, children: /* @__PURE__ */ o(Y.Provider, { value: null, children: /* @__PURE__ */ o(
265
265
  "div",
266
266
  {
267
- className: o,
267
+ className: y,
268
268
  style: { display: "contents" },
269
- children: /* @__PURE__ */ d(l, { ...h })
269
+ children: /* @__PURE__ */ o(u, { ...h })
270
270
  }
271
271
  ) }) }) }) })
272
272
  ] });
273
- }, Be = ({ onError: r, ...e }) => /* @__PURE__ */ d(K, { fallback: null, children: /* @__PURE__ */ d(W, { onError: r, children: /* @__PURE__ */ d(Z, { ...e }) }) }), be = ({ areaCode: r, options: e, retry: t }) => {
274
- const n = Ne(r, {
273
+ }, He = ({ onError: r, ...e }) => /* @__PURE__ */ o(z, { fallback: null, children: /* @__PURE__ */ o(Z, { onError: r, children: /* @__PURE__ */ o(re, { ...e }) }) }), Me = ({ areaCode: r, options: e, retry: t }) => {
274
+ const n = Fe(r, {
275
275
  suspense: !1,
276
276
  ssr: !1,
277
277
  pause: e == null ? void 0 : e.pause,
278
278
  timeout: e == null ? void 0 : e.timeout
279
- }), s = H(null);
280
- if (y(() => {
281
- var S;
279
+ }), s = G(null);
280
+ if (g(() => {
281
+ var k;
282
282
  if (n.status !== "not-found" || !n.error) return;
283
- const m = V(n.error), g = JSON.stringify([r, m.kind, m.code, m.error.message]);
284
- s.current !== g && (s.current = g, (S = e == null ? void 0 : e.onError) == null || S.call(e, m.error), process.env.NODE_ENV !== "production" && m.kind !== "no-variant" && console.error(
285
- `[fragments] Area resolution ${m.kind}: areaCode=${r}, code=${m.code ?? "none"}`,
286
- m.error
283
+ const c = B(n.error), v = JSON.stringify([r, c.kind, c.code, c.error.message]);
284
+ s.current !== v && (s.current = v, (k = e == null ? void 0 : e.onError) == null || k.call(e, c.error), process.env.NODE_ENV !== "production" && c.kind !== "no-variant" && console.error(
285
+ `[fragments] Area resolution ${c.kind}: areaCode=${r}, code=${c.code ?? "none"}`,
286
+ c.error
287
287
  ));
288
288
  }, [r, e == null ? void 0 : e.onError, n.error, n.status]), (e == null ? void 0 : e.pause) === !0)
289
289
  return null;
290
290
  if (n.status === "idle")
291
291
  return (e == null ? void 0 : e.fallback) ?? null;
292
292
  if (n.status === "not-found")
293
- return Q(e == null ? void 0 : e.empty, V(n.error), t);
293
+ return X(e == null ? void 0 : e.empty, B(n.error), t);
294
294
  if (n.status === "loading" || !n.data)
295
295
  return (e == null ? void 0 : e.fallback) ?? null;
296
- const { rootFragmentId: a, props: i, projectProperties: c, globalCssUrl: l, fragments: u, slots: E, sources: h } = n.data, o = typeof (e == null ? void 0 : e.props) == "function" ? e.props(i) : e != null && e.props ? { ...i, ...e.props } : i;
297
- return /* @__PURE__ */ d(K, { fallback: (e == null ? void 0 : e.fallback) ?? null, children: /* @__PURE__ */ d(
298
- Z,
296
+ const { rootFragmentId: a, props: i, projectProperties: m, globalCssUrl: u, fragments: l, slots: d, sources: h } = n.data, y = typeof (e == null ? void 0 : e.props) == "function" ? e.props(i) : e != null && e.props ? { ...i, ...e.props } : i;
297
+ return /* @__PURE__ */ o(z, { fallback: (e == null ? void 0 : e.fallback) ?? null, children: /* @__PURE__ */ o(
298
+ re,
299
299
  {
300
300
  fragmentId: a,
301
- props: o,
302
- globalCssUrl: l,
303
- projectProperties: c,
304
- fragments: u,
305
- slots: E,
301
+ props: y,
302
+ globalCssUrl: u,
303
+ projectProperties: m,
304
+ fragments: l,
305
+ slots: d,
306
306
  sources: h
307
307
  }
308
308
  ) });
309
- }, Ke = ({ areaCode: r, options: e }) => {
310
- const t = v(k), [n, s] = w(0), a = t == null ? void 0 : t.$area;
311
- y(() => {
309
+ }, ze = ({ areaCode: r, options: e }) => {
310
+ const t = E(A), [n, s] = F(0), a = t == null ? void 0 : t.$area;
311
+ g(() => {
312
312
  (e == null ? void 0 : e.ssr) !== !0 || process.env.NODE_ENV === "production" || console.error(
313
313
  "[fragments] Area option `ssr` is reserved: server resolution has been removed from the runtime; existing `ssr: false` calls continue to work unchanged."
314
314
  );
315
315
  }, [e == null ? void 0 : e.ssr]);
316
- const i = _(() => {
316
+ const i = x(() => {
317
317
  a != null && a.resolve && (a.resolve(r).catch(() => {
318
- }), s((c) => c + 1));
318
+ }), s((m) => m + 1));
319
319
  }, [a, r]);
320
320
  return (
321
321
  // A retry remounts the boundary and AreaInner: a repeated failure is a new
322
322
  // telemetry event, so AreaInner intentionally calls options.onError again.
323
- /* @__PURE__ */ d(W, { onError: e == null ? void 0 : e.onError, empty: e == null ? void 0 : e.empty, retry: i, children: /* @__PURE__ */ d(be, { areaCode: r, options: e, retry: i }) }, n)
323
+ /* @__PURE__ */ o(Z, { onError: e == null ? void 0 : e.onError, empty: e == null ? void 0 : e.empty, retry: i, children: /* @__PURE__ */ o(Me, { areaCode: r, options: e, retry: i }) }, n)
324
324
  );
325
325
  };
326
- function He({ client: r, children: e }) {
327
- const t = N(
326
+ function Ge({ client: r, children: e }) {
327
+ const t = w(
328
328
  () => ({
329
329
  read: (n) => r.$fragments.read(n)
330
330
  }),
331
331
  [r]
332
332
  );
333
- return /* @__PURE__ */ d(Ae, { value: r, children: /* @__PURE__ */ d(Ce, { value: t, children: e }) });
333
+ return /* @__PURE__ */ o(Ce, { value: r, children: /* @__PURE__ */ o(Ne, { value: t, children: e }) });
334
334
  }
335
- function ze(r) {
336
- return (v(x) ?? J)[r];
335
+ function Ye(r) {
336
+ return (E(O) ?? Q)[r];
337
337
  }
338
- function Ie(r, e) {
339
- const [, t] = oe((a) => a + 1, 0), n = e(), s = H(n);
340
- return s.current = n, y(() => {
338
+ function je(r, e) {
339
+ const [, t] = fe((a) => a + 1, 0), n = e(), s = G(n);
340
+ return s.current = n, g(() => {
341
341
  const a = r(t);
342
342
  return Object.is(s.current, e()) || t(), a;
343
343
  }, [r, e]), n;
344
344
  }
345
- const B = ae.useSyncExternalStore, Me = B || ((r, e) => Ie(r, e)), ee = "offline", je = () => Promise.reject(new Error(ee));
346
- function $e(r, e) {
347
- var M;
348
- const t = ke(), [n] = w(Ee), s = (t == null ? void 0 : t.sourceCache) ?? n, a = (M = t == null ? void 0 : t.sourceFetchers) == null ? void 0 : M[r], i = a ? "host-fetch" : "network", c = t == null ? void 0 : t.env, l = j({ source: r, target: e.target, params: e.params }), u = N(() => ({ source: r, target: e.target, params: e.params }), [l]), E = _((T) => s.subscribe(u, T), [s, u]), h = _(() => s.get(u), [s, u]), o = Me(E, h, h), m = v(b), g = v(O), S = ve(r, e.target), f = N(
349
- () => m === ee ? null : ge(g[S], u.params),
350
- [m, g, S, u]
351
- ), [C, I] = w(null);
352
- return y(() => {
353
- (o == null ? void 0 : o.status) === "ready" && C !== null && I(null);
354
- }, [o, C]), y(() => {
355
- f && !f.ok && o === void 0 && console.warn(`[useSource] ${S}: ${f.reason}`);
356
- }, [S, f == null ? void 0 : f.ok, f && !f.ok ? f.reason : void 0, o === void 0]), y(() => {
357
- if (f && !f.ok || (o == null ? void 0 : o.status) === "ready" || C === l) return;
358
- I(l);
359
- const T = f && f.ok ? () => ye({ url: f.url, init: f.init }, { fetcher: a, timeout: c == null ? void 0 : c.timeout }).then((re) => (c != null && c.debug && console.info(`[useSource] loaded ${j(u)} origin=${i}`), re)) : je;
360
- s.load(u, T, i);
361
- }, [s, u, l, o, C, f, a, i, c == null ? void 0 : c.timeout, c == null ? void 0 : c.debug]), (o == null ? void 0 : o.status) === "ready" ? { data: o.data ?? void 0, loading: !1 } : (o == null ? void 0 : o.status) === "pending" ? { data: void 0, loading: !0 } : f && !f.ok ? { data: void 0, loading: !1 } : { data: void 0, loading: C !== l };
345
+ const H = ue.useSyncExternalStore, $e = H || ((r, e) => je(r, e)), te = "offline", Le = () => Promise.reject(new Error(te));
346
+ function De(r, e) {
347
+ var j, $;
348
+ const t = Pe(), [n] = F(ge), s = (t == null ? void 0 : t.sourceCache) ?? n, a = (j = t == null ? void 0 : t.sourceFetchers) == null ? void 0 : j[r], i = ($ = t == null ? void 0 : t.sourceBaseUrls) == null ? void 0 : $[r], m = a ? "host-fetch" : "network", u = t == null ? void 0 : t.env, l = L({ source: r, target: e.target, params: e.params }), d = w(() => ({ source: r, target: e.target, params: e.params }), [l]), h = x((R) => s.subscribe(d, R), [s, d]), y = x(() => s.get(d), [s, d]), c = $e(h, y, y), v = E(I), k = E(b), P = ye(r, e.target), f = w(
349
+ () => v === te ? null : Se(k[P], d.params, i),
350
+ [v, k, P, d, i]
351
+ ), [C, M] = F(null);
352
+ return g(() => {
353
+ (c == null ? void 0 : c.status) === "ready" && C !== null && M(null);
354
+ }, [c, C]), g(() => {
355
+ f && !f.ok && c === void 0 && console.warn(`[useSource] ${P}: ${f.reason}`);
356
+ }, [P, f == null ? void 0 : f.ok, f && !f.ok ? f.reason : void 0, c === void 0]), g(() => {
357
+ if (f && !f.ok || (c == null ? void 0 : c.status) === "ready" || C === l) return;
358
+ M(l);
359
+ const R = f && f.ok ? () => Ae({ url: f.url, init: f.init }, { fetcher: a, timeout: u == null ? void 0 : u.timeout }).then((ne) => (u != null && u.debug && console.info(`[useSource] loaded ${L(d)} origin=${m}`), ne)) : Le;
360
+ s.load(d, R, m);
361
+ }, [s, d, l, c, C, f, a, m, u == null ? void 0 : u.timeout, u == null ? void 0 : u.debug]), (c == null ? void 0 : c.status) === "ready" ? { data: c.data ?? void 0, loading: !1 } : (c == null ? void 0 : c.status) === "pending" ? { data: void 0, loading: !0 } : f && !f.ok ? { data: void 0, loading: !1 } : { data: void 0, loading: C !== l };
362
362
  }
363
- const Ge = $e;
364
- function Ye(r) {
365
- return Se({ ...r, inject: Y });
363
+ const Je = De;
364
+ function qe(r) {
365
+ return ke({ ...r, inject: q });
366
366
  }
367
367
  export {
368
- L as AREA_UNRESOLVED,
369
- Ke as Area,
370
- Be as FragmentRenderer,
371
- D as FragmentStylesheet,
372
- Qe as FragmentsApiVersionError,
373
- We as FragmentsAreaError,
374
- k as FragmentsClientContext,
375
- Ae as FragmentsClientProvider,
376
- Xe as FragmentsLoadError,
377
- He as FragmentsProvider,
378
- z as InstanceIdContext,
379
- F as ModulesMapContext,
380
- Ce as ModulesMapProvider,
381
- x as ProjectPropertiesContext,
382
- Ye as createBrowserClient,
383
- Ze as createSourceCache,
384
- J as defaultProjectProperties,
385
- Y as injectStylesheet,
386
- Ne as useArea,
387
- pe as useCssChunk,
388
- Pe as useFragmentComponent,
389
- Ue as useFragmentMetrics,
390
- Te as useFragmentStylesheet,
391
- ze as useProjectProperty,
392
- Ge as useSource
368
+ U as AREA_UNRESOLVED,
369
+ ze as Area,
370
+ He as FragmentRenderer,
371
+ V as FragmentStylesheet,
372
+ Xe as FragmentsApiVersionError,
373
+ Ze as FragmentsAreaError,
374
+ A as FragmentsClientContext,
375
+ Ce as FragmentsClientProvider,
376
+ er as FragmentsLoadError,
377
+ Ge as FragmentsProvider,
378
+ Y as InstanceIdContext,
379
+ T as ModulesMapContext,
380
+ Ne as ModulesMapProvider,
381
+ O as ProjectPropertiesContext,
382
+ qe as createBrowserClient,
383
+ rr as createSourceCache,
384
+ Q as defaultProjectProperties,
385
+ q as injectStylesheet,
386
+ Fe as useArea,
387
+ Ke as useCssChunk,
388
+ we as useFragmentComponent,
389
+ pe as useFragmentMetrics,
390
+ _e as useFragmentStylesheet,
391
+ Ye as useProjectProperty,
392
+ Je as useSource
393
393
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(s,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("react/jsx-runtime"),require("react"),require("@fragmentsx/fragments-client")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@fragmentsx/fragments-client"],l):(s=typeof globalThis<"u"?globalThis:s||self,l(s.FragmentsRuntimeReact={},s.jsxRuntime,s.React,s.fragmentsClient))})(this,function(s,l,u,h){"use strict";function ee(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const re=ee(u),P=u.createContext(null);P.displayName="FragmentsClientContext";function $(r){return l.jsx(P.Provider,{value:r.value,children:r.children})}function te(){return u.useContext(P)}const N=u.createContext(null);N.displayName="InstanceIdContext";const A=u.createContext(null);A.displayName="ModulesMapContext";function D({value:r,children:e}){return l.jsx(A.Provider,{value:r,children:e})}function ne(){const r=u.useContext(P);return u.useMemo(()=>({reachGoal:e=>{var t,n;(n=(t=r==null?void 0:r.$metrics)==null?void 0:t.reachGoal)==null||n.call(t,e)}}),[r])}function L(r){const e=u.useContext(A);if(!e)throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");return e.read(r)}const V=typeof window<"u",O=Object.freeze({rootFragmentId:0,variantId:null,props:{},projectProperties:{},globalCssUrl:null,fragments:[],slots:{},sources:{}});function w(r){const e=r.$area;if(!(e!=null&&e.read))throw new Error("[useArea] $area plugin not mounted");return e}function U(r,e){const t=u.useContext(P);if(!t)throw new Error("[useArea] No FragmentsClientProvider in tree");const n=(e==null?void 0:e.suspense)??!0,c=(e==null?void 0:e.pause)===!0||!V&&(e==null?void 0:e.ssr)===!1,a=(e==null?void 0:e.timeout)!=null?{timeout:e.timeout}:void 0,[,m]=u.useState(0);if(u.useEffect(()=>{if(n||c)return;const f=w(t);let o=!0;return Promise.resolve(f.resolve(r,a)).catch(()=>{}).finally(()=>{o&&m(y=>y+1)}),()=>{o=!1}},[r,n,e==null?void 0:e.pause,e==null?void 0:e.timeout,e==null?void 0:e.ssr]),n){if(c)return O;const f=w(t);if(f.has(r)||Promise.resolve(f.resolve(r,a)).catch(()=>{}),!V)try{return f.read(r)}catch(o){if(o!=null&&typeof o.then=="function")throw o;return process.env.NODE_ENV!=="production"&&console.error(`[useArea] Area ${r} remained unresolved on the server because its cache reached a terminal state`,o),O}return f.read(r)}if(c)return{status:"idle",data:null,error:null};const d=w(t);if(d.has(r))try{return{status:"ready",data:d.read(r),error:null}}catch(f){return{status:"not-found",data:null,error:f instanceof Error?f:new Error(String(f))}}return Promise.resolve(d.resolve(r,a)).catch(()=>{}),{status:"loading",data:null,error:null}}const B=typeof window<"u",ue=3e3,k=new Map,T=(r,e)=>{if(!B){const v=()=>{};return v.loaded=Promise.resolve(),v}const t=k.get(e);if(t){t.refCount+=1;const v=()=>{t.refCount-=1,t.refCount===0&&(t.clearReadyTimer(),t.linkEl.remove(),k.delete(e))};return v.loaded=t.loaded,v}const n=document.createElement("link");n.rel="stylesheet",n.href=r,n.setAttribute("data-fragment-key",e);let c;const a=new Promise(v=>{c=v}),m=()=>{f(),c()},d=setTimeout(m,ue),f=()=>clearTimeout(d);n.addEventListener("load",m),n.addEventListener("error",m),document.head.appendChild(n);const o={refCount:1,linkEl:n,loaded:a,clearReadyTimer:f};k.set(e,o);const y=()=>{o.refCount-=1,o.refCount===0&&(o.clearReadyTimer(),o.linkEl.remove(),k.delete(e))};return y.loaded=a,y},se=B?u.useLayoutEffect:u.useEffect;function K(r,e){se(()=>T(r,e),[r,e])}const ae=parseInt(u.version.split(".")[0],10)>=19;function M({href:r,fragmentKey:e}){return ae?l.jsx("link",{rel:"stylesheet",href:r,precedence:"default","data-fragment-key":e}):(K(r,e),null)}function ce(r){}const _={},b=u.createContext(null);b.displayName="ProjectPropertiesContext";const z=Object.freeze({}),j=u.createContext(z);j.displayName="SourceTransportsContext";const I=u.createContext("live");I.displayName="SourceNetworkContext";function H(r){const e=r instanceof Error?r:new Error(String(r));if(!(e instanceof h.FragmentsAreaError))return{kind:"failed",error:e};const{code:t}=e;return t==="NO_ACTIVE_VARIANT"?{kind:"no-variant",code:t,error:e}:t==="AREA_NOT_FOUND"||t==="NO_PUBLISHED_SNAPSHOT"||t==="NESTED_SNAPSHOT_MISSING"?{kind:"misconfigured",code:t,error:e}:{kind:"failed",code:t,error:e}}function G(r,e,t){return typeof r=="function"?r(e,t):r??null}const oe=()=>{};function Y(r){return r instanceof Error?r:new Error(String(r))}class q extends u.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:Y(e)}}componentDidCatch(e,t){var c,a;const n=Y(e);process.env.NODE_ENV!=="production"&&console.error("[fragments] Area error:",n,t.componentStack),(a=(c=this.props).onError)==null||a.call(c,n)}render(){if(this.state.hasError){const e={kind:"failed",error:this.state.error??new Error("Unknown Area error")};try{return G(this.props.empty,e,this.props.retry??oe)}catch{return null}}return this.props.children}}function J(r,e){if(!r)return{};const t={};for(const n of Object.keys(r))t[n]=le(r[n],e);return t}function le(r,e){return Array.isArray(r)?r.map((t,n)=>t===null?null:p(t,e,n)):p(r,e)}function p(r,e,t){let n;try{n=e(r.fragmentId)}catch(a){if(a!=null&&typeof a.then=="function")throw a;return console.warn(`[FragmentRenderer] Slot fragment ${r.fragmentId} failed to load — rendering empty hole`,a),null}const c=J(r.slots,e);return u.createElement(n,{key:t,...r.props,...c})}const Q=({fragmentId:r,props:e,globalCssUrl:t=null,projectProperties:n=_,fragments:c=[r],slots:a,sources:m=z,sourceNetwork:d="live"})=>{const f=L(r),o=u.useContext(A);if(!o)throw new Error("[FragmentRendererInner] No ModulesMapProvider in tree");const y=J(a,o.read),v={...e??{},...y},i=c.length>0?c.map(h.toScopeClassName).join(" "):void 0;return l.jsxs(l.Fragment,{children:[t!=null&&l.jsx(M,{href:t,fragmentKey:h.AREA_GLOBAL_CSS_KEY}),c.map(g=>{const S=h.resolveStylesHref(g);return S?l.jsx(M,{href:S,fragmentKey:h.fragmentCssKey(g)},g):null}),l.jsx(I.Provider,{value:d,children:l.jsx(j.Provider,{value:m,children:l.jsx(b.Provider,{value:n,children:l.jsx(N.Provider,{value:null,children:l.jsx("div",{className:i,style:{display:"contents"},children:l.jsx(f,{...v})})})})})})]})},de=({onError:r,...e})=>l.jsx(u.Suspense,{fallback:null,children:l.jsx(q,{onError:r,children:l.jsx(Q,{...e})})}),fe=({areaCode:r,options:e,retry:t})=>{const n=U(r,{suspense:!1,ssr:!1,pause:e==null?void 0:e.pause,timeout:e==null?void 0:e.timeout}),c=u.useRef(null);if(u.useEffect(()=>{var C;if(n.status!=="not-found"||!n.error)return;const g=H(n.error),S=JSON.stringify([r,g.kind,g.code,g.error.message]);c.current!==S&&(c.current=S,(C=e==null?void 0:e.onError)==null||C.call(e,g.error),process.env.NODE_ENV!=="production"&&g.kind!=="no-variant"&&console.error(`[fragments] Area resolution ${g.kind}: areaCode=${r}, code=${g.code??"none"}`,g.error))},[r,e==null?void 0:e.onError,n.error,n.status]),(e==null?void 0:e.pause)===!0)return null;if(n.status==="idle")return(e==null?void 0:e.fallback)??null;if(n.status==="not-found")return G(e==null?void 0:e.empty,H(n.error),t);if(n.status==="loading"||!n.data)return(e==null?void 0:e.fallback)??null;const{rootFragmentId:a,props:m,projectProperties:d,globalCssUrl:f,fragments:o,slots:y,sources:v}=n.data,i=typeof(e==null?void 0:e.props)=="function"?e.props(m):e!=null&&e.props?{...m,...e.props}:m;return l.jsx(u.Suspense,{fallback:(e==null?void 0:e.fallback)??null,children:l.jsx(Q,{fragmentId:a,props:i,globalCssUrl:f,projectProperties:d,fragments:o,slots:y,sources:v})})},ie=({areaCode:r,options:e})=>{const t=u.useContext(P),[n,c]=u.useState(0),a=t==null?void 0:t.$area;u.useEffect(()=>{(e==null?void 0:e.ssr)!==!0||process.env.NODE_ENV==="production"||console.error("[fragments] Area option `ssr` is reserved: server resolution has been removed from the runtime; existing `ssr: false` calls continue to work unchanged.")},[e==null?void 0:e.ssr]);const m=u.useCallback(()=>{a!=null&&a.resolve&&(a.resolve(r).catch(()=>{}),c(d=>d+1))},[a,r]);return l.jsx(q,{onError:e==null?void 0:e.onError,empty:e==null?void 0:e.empty,retry:m,children:l.jsx(fe,{areaCode:r,options:e,retry:m})},n)};function me({client:r,children:e}){const t=u.useMemo(()=>({read:n=>r.$fragments.read(n)}),[r]);return l.jsx($,{value:r,children:l.jsx(D,{value:t,children:e})})}function Ee(r){return(u.useContext(b)??_)[r]}function he(r,e){const[,t]=u.useReducer(a=>a+1,0),n=e(),c=u.useRef(n);return c.current=n,u.useEffect(()=>{const a=r(t);return Object.is(c.current,e())||t(),a},[r,e]),n}const W=re.useSyncExternalStore,ge=W||((r,e)=>he(r,e)),X="offline",ve=()=>Promise.reject(new Error(X));function ye(r,e){var R;const t=te(),[n]=u.useState(h.createSourceCache),c=(t==null?void 0:t.sourceCache)??n,a=(R=t==null?void 0:t.sourceFetchers)==null?void 0:R[r],m=a?"host-fetch":"network",d=t==null?void 0:t.env,f=h.sourceCallKey({source:r,target:e.target,params:e.params}),o=u.useMemo(()=>({source:r,target:e.target,params:e.params}),[f]),y=u.useCallback(x=>c.subscribe(o,x),[c,o]),v=u.useCallback(()=>c.get(o),[c,o]),i=ge(y,v,v),g=u.useContext(I),S=u.useContext(j),C=h.sourceTransportKey(r,e.target),E=u.useMemo(()=>g===X?null:h.resolveSourceRequest(S[C],o.params),[g,S,C,o]),[F,Z]=u.useState(null);return u.useEffect(()=>{(i==null?void 0:i.status)==="ready"&&F!==null&&Z(null)},[i,F]),u.useEffect(()=>{E&&!E.ok&&i===void 0&&console.warn(`[useSource] ${C}: ${E.reason}`)},[C,E==null?void 0:E.ok,E&&!E.ok?E.reason:void 0,i===void 0]),u.useEffect(()=>{if(E&&!E.ok||(i==null?void 0:i.status)==="ready"||F===f)return;Z(f);const x=E&&E.ok?()=>h.runSourceFetch({url:E.url,init:E.init},{fetcher:a,timeout:d==null?void 0:d.timeout}).then(Ce=>(d!=null&&d.debug&&console.info(`[useSource] loaded ${h.sourceCallKey(o)} origin=${m}`),Ce)):ve;c.load(o,x,m)},[c,o,f,i,F,E,a,m,d==null?void 0:d.timeout,d==null?void 0:d.debug]),(i==null?void 0:i.status)==="ready"?{data:i.data??void 0,loading:!1}:(i==null?void 0:i.status)==="pending"?{data:void 0,loading:!0}:E&&!E.ok?{data:void 0,loading:!1}:{data:void 0,loading:F!==f}}const Se=ye;function Pe(r){return h.createFragmentsClient({...r,inject:T})}Object.defineProperty(s,"FragmentsApiVersionError",{enumerable:!0,get:()=>h.FragmentsApiVersionError}),Object.defineProperty(s,"FragmentsAreaError",{enumerable:!0,get:()=>h.FragmentsAreaError}),Object.defineProperty(s,"FragmentsLoadError",{enumerable:!0,get:()=>h.FragmentsLoadError}),Object.defineProperty(s,"createSourceCache",{enumerable:!0,get:()=>h.createSourceCache}),s.AREA_UNRESOLVED=O,s.Area=ie,s.FragmentRenderer=de,s.FragmentStylesheet=M,s.FragmentsClientContext=P,s.FragmentsClientProvider=$,s.FragmentsProvider=me,s.InstanceIdContext=N,s.ModulesMapContext=A,s.ModulesMapProvider=D,s.ProjectPropertiesContext=b,s.createBrowserClient=Pe,s.defaultProjectProperties=_,s.injectStylesheet=T,s.useArea=U,s.useCssChunk=ce,s.useFragmentComponent=L,s.useFragmentMetrics=ne,s.useFragmentStylesheet=K,s.useProjectProperty=Ee,s.useSource=Se,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react/jsx-runtime"),require("react"),require("@fragmentsx/fragments-client")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@fragmentsx/fragments-client"],d):(s=typeof globalThis<"u"?globalThis:s||self,d(s.FragmentsRuntimeReact={},s.jsxRuntime,s.React,s.fragmentsClient))})(this,function(s,d,u,h){"use strict";function te(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const ne=te(u),S=u.createContext(null);S.displayName="FragmentsClientContext";function D(r){return d.jsx(S.Provider,{value:r.value,children:r.children})}function ue(){return u.useContext(S)}const O=u.createContext(null);O.displayName="InstanceIdContext";const C=u.createContext(null);C.displayName="ModulesMapContext";function L({value:r,children:e}){return d.jsx(C.Provider,{value:r,children:e})}function se(){const r=u.useContext(S);return u.useMemo(()=>({reachGoal:e=>{var t,n;(n=(t=r==null?void 0:r.$metrics)==null?void 0:t.reachGoal)==null||n.call(t,e)}}),[r])}function U(r){const e=u.useContext(C);if(!e)throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");return e.read(r)}const V=typeof window<"u",w=Object.freeze({rootFragmentId:0,variantId:null,props:{},projectProperties:{},globalCssUrl:null,fragments:[],slots:{},sources:{}});function T(r){const e=r.$area;if(!(e!=null&&e.read))throw new Error("[useArea] $area plugin not mounted");return e}function B(r,e){const t=u.useContext(S);if(!t)throw new Error("[useArea] No FragmentsClientProvider in tree");const n=(e==null?void 0:e.suspense)??!0,c=(e==null?void 0:e.pause)===!0||!V&&(e==null?void 0:e.ssr)===!1,a=(e==null?void 0:e.timeout)!=null?{timeout:e.timeout}:void 0,[,E]=u.useState(0);if(u.useEffect(()=>{if(n||c)return;const o=T(t);let f=!0;return Promise.resolve(o.resolve(r,a)).catch(()=>{}).finally(()=>{f&&E(i=>i+1)}),()=>{f=!1}},[r,n,e==null?void 0:e.pause,e==null?void 0:e.timeout,e==null?void 0:e.ssr]),n){if(c)return w;const o=T(t);if(o.has(r)||Promise.resolve(o.resolve(r,a)).catch(()=>{}),!V)try{return o.read(r)}catch(f){if(f!=null&&typeof f.then=="function")throw f;return process.env.NODE_ENV!=="production"&&console.error(`[useArea] Area ${r} remained unresolved on the server because its cache reached a terminal state`,f),w}return o.read(r)}if(c)return{status:"idle",data:null,error:null};const g=T(t);if(g.has(r))try{return{status:"ready",data:g.read(r),error:null}}catch(o){return{status:"not-found",data:null,error:o instanceof Error?o:new Error(String(o))}}return Promise.resolve(g.resolve(r,a)).catch(()=>{}),{status:"loading",data:null,error:null}}const K=typeof window<"u",ae=3e3,k=new Map,M=(r,e)=>{if(!K){const v=()=>{};return v.loaded=Promise.resolve(),v}const t=k.get(e);if(t){t.refCount+=1;const v=()=>{t.refCount-=1,t.refCount===0&&(t.clearReadyTimer(),t.linkEl.remove(),k.delete(e))};return v.loaded=t.loaded,v}const n=document.createElement("link");n.rel="stylesheet",n.href=r,n.setAttribute("data-fragment-key",e);let c;const a=new Promise(v=>{c=v}),E=()=>{o(),c()},g=setTimeout(E,ae),o=()=>clearTimeout(g);n.addEventListener("load",E),n.addEventListener("error",E),document.head.appendChild(n);const f={refCount:1,linkEl:n,loaded:a,clearReadyTimer:o};k.set(e,f);const i=()=>{f.refCount-=1,f.refCount===0&&(f.clearReadyTimer(),f.linkEl.remove(),k.delete(e))};return i.loaded=a,i},ce=K?u.useLayoutEffect:u.useEffect;function z(r,e){ce(()=>M(r,e),[r,e])}const oe=parseInt(u.version.split(".")[0],10)>=19;function _({href:r,fragmentKey:e}){return oe?d.jsx("link",{rel:"stylesheet",href:r,precedence:"default","data-fragment-key":e}):(z(r,e),null)}function le(r){}const j={},b=u.createContext(null);b.displayName="ProjectPropertiesContext";const H=Object.freeze({}),I=u.createContext(H);I.displayName="SourceTransportsContext";const x=u.createContext("live");x.displayName="SourceNetworkContext";function G(r){const e=r instanceof Error?r:new Error(String(r));if(!(e instanceof h.FragmentsAreaError))return{kind:"failed",error:e};const{code:t}=e;return t==="NO_ACTIVE_VARIANT"?{kind:"no-variant",code:t,error:e}:t==="AREA_NOT_FOUND"||t==="NO_PUBLISHED_SNAPSHOT"||t==="NESTED_SNAPSHOT_MISSING"?{kind:"misconfigured",code:t,error:e}:{kind:"failed",code:t,error:e}}function Y(r,e,t){return typeof r=="function"?r(e,t):r??null}const de=()=>{};function q(r){return r instanceof Error?r:new Error(String(r))}class J extends u.Component{constructor(){super(...arguments),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:q(e)}}componentDidCatch(e,t){var c,a;const n=q(e);process.env.NODE_ENV!=="production"&&console.error("[fragments] Area error:",n,t.componentStack),(a=(c=this.props).onError)==null||a.call(c,n)}render(){if(this.state.hasError){const e={kind:"failed",error:this.state.error??new Error("Unknown Area error")};try{return Y(this.props.empty,e,this.props.retry??de)}catch{return null}}return this.props.children}}function p(r,e){if(!r)return{};const t={};for(const n of Object.keys(r))t[n]=fe(r[n],e);return t}function fe(r,e){return Array.isArray(r)?r.map((t,n)=>t===null?null:Q(t,e,n)):Q(r,e)}function Q(r,e,t){let n;try{n=e(r.fragmentId)}catch(a){if(a!=null&&typeof a.then=="function")throw a;return console.warn(`[FragmentRenderer] Slot fragment ${r.fragmentId} failed to load — rendering empty hole`,a),null}const c=p(r.slots,e);return u.createElement(n,{key:t,...r.props,...c})}const W=({fragmentId:r,props:e,globalCssUrl:t=null,projectProperties:n=j,fragments:c=[r],slots:a,sources:E=H,sourceNetwork:g="live"})=>{const o=U(r),f=u.useContext(C);if(!f)throw new Error("[FragmentRendererInner] No ModulesMapProvider in tree");const i=p(a,f.read),v={...e??{},...i},P=c.length>0?c.map(h.toScopeClassName).join(" "):void 0;return d.jsxs(d.Fragment,{children:[t!=null&&d.jsx(_,{href:t,fragmentKey:h.AREA_GLOBAL_CSS_KEY}),c.map(l=>{const y=h.resolveStylesHref(l);return y?d.jsx(_,{href:y,fragmentKey:h.fragmentCssKey(l)},l):null}),d.jsx(x.Provider,{value:g,children:d.jsx(I.Provider,{value:E,children:d.jsx(b.Provider,{value:n,children:d.jsx(O.Provider,{value:null,children:d.jsx("div",{className:P,style:{display:"contents"},children:d.jsx(o,{...v})})})})})})]})},ie=({onError:r,...e})=>d.jsx(u.Suspense,{fallback:null,children:d.jsx(J,{onError:r,children:d.jsx(W,{...e})})}),me=({areaCode:r,options:e,retry:t})=>{const n=B(r,{suspense:!1,ssr:!1,pause:e==null?void 0:e.pause,timeout:e==null?void 0:e.timeout}),c=u.useRef(null);if(u.useEffect(()=>{var A;if(n.status!=="not-found"||!n.error)return;const l=G(n.error),y=JSON.stringify([r,l.kind,l.code,l.error.message]);c.current!==y&&(c.current=y,(A=e==null?void 0:e.onError)==null||A.call(e,l.error),process.env.NODE_ENV!=="production"&&l.kind!=="no-variant"&&console.error(`[fragments] Area resolution ${l.kind}: areaCode=${r}, code=${l.code??"none"}`,l.error))},[r,e==null?void 0:e.onError,n.error,n.status]),(e==null?void 0:e.pause)===!0)return null;if(n.status==="idle")return(e==null?void 0:e.fallback)??null;if(n.status==="not-found")return Y(e==null?void 0:e.empty,G(n.error),t);if(n.status==="loading"||!n.data)return(e==null?void 0:e.fallback)??null;const{rootFragmentId:a,props:E,projectProperties:g,globalCssUrl:o,fragments:f,slots:i,sources:v}=n.data,P=typeof(e==null?void 0:e.props)=="function"?e.props(E):e!=null&&e.props?{...E,...e.props}:E;return d.jsx(u.Suspense,{fallback:(e==null?void 0:e.fallback)??null,children:d.jsx(W,{fragmentId:a,props:P,globalCssUrl:o,projectProperties:g,fragments:f,slots:i,sources:v})})},Ee=({areaCode:r,options:e})=>{const t=u.useContext(S),[n,c]=u.useState(0),a=t==null?void 0:t.$area;u.useEffect(()=>{(e==null?void 0:e.ssr)!==!0||process.env.NODE_ENV==="production"||console.error("[fragments] Area option `ssr` is reserved: server resolution has been removed from the runtime; existing `ssr: false` calls continue to work unchanged.")},[e==null?void 0:e.ssr]);const E=u.useCallback(()=>{a!=null&&a.resolve&&(a.resolve(r).catch(()=>{}),c(g=>g+1))},[a,r]);return d.jsx(J,{onError:e==null?void 0:e.onError,empty:e==null?void 0:e.empty,retry:E,children:d.jsx(me,{areaCode:r,options:e,retry:E})},n)};function he({client:r,children:e}){const t=u.useMemo(()=>({read:n=>r.$fragments.read(n)}),[r]);return d.jsx(D,{value:r,children:d.jsx(L,{value:t,children:e})})}function ge(r){return(u.useContext(b)??j)[r]}function ve(r,e){const[,t]=u.useReducer(a=>a+1,0),n=e(),c=u.useRef(n);return c.current=n,u.useEffect(()=>{const a=r(t);return Object.is(c.current,e())||t(),a},[r,e]),n}const X=ne.useSyncExternalStore,ye=X||((r,e)=>ve(r,e)),Z="offline",Se=()=>Promise.reject(new Error(Z));function Pe(r,e){var ee,re;const t=ue(),[n]=u.useState(h.createSourceCache),c=(t==null?void 0:t.sourceCache)??n,a=(ee=t==null?void 0:t.sourceFetchers)==null?void 0:ee[r],E=(re=t==null?void 0:t.sourceBaseUrls)==null?void 0:re[r],g=a?"host-fetch":"network",o=t==null?void 0:t.env,f=h.sourceCallKey({source:r,target:e.target,params:e.params}),i=u.useMemo(()=>({source:r,target:e.target,params:e.params}),[f]),v=u.useCallback($=>c.subscribe(i,$),[c,i]),P=u.useCallback(()=>c.get(i),[c,i]),l=ye(v,P,P),y=u.useContext(x),A=u.useContext(I),N=h.sourceTransportKey(r,e.target),m=u.useMemo(()=>y===Z?null:h.resolveSourceRequest(A[N],i.params,E),[y,A,N,i,E]),[F,R]=u.useState(null);return u.useEffect(()=>{(l==null?void 0:l.status)==="ready"&&F!==null&&R(null)},[l,F]),u.useEffect(()=>{m&&!m.ok&&l===void 0&&console.warn(`[useSource] ${N}: ${m.reason}`)},[N,m==null?void 0:m.ok,m&&!m.ok?m.reason:void 0,l===void 0]),u.useEffect(()=>{if(m&&!m.ok||(l==null?void 0:l.status)==="ready"||F===f)return;R(f);const $=m&&m.ok?()=>h.runSourceFetch({url:m.url,init:m.init},{fetcher:a,timeout:o==null?void 0:o.timeout}).then(Fe=>(o!=null&&o.debug&&console.info(`[useSource] loaded ${h.sourceCallKey(i)} origin=${g}`),Fe)):Se;c.load(i,$,g)},[c,i,f,l,F,m,a,g,o==null?void 0:o.timeout,o==null?void 0:o.debug]),(l==null?void 0:l.status)==="ready"?{data:l.data??void 0,loading:!1}:(l==null?void 0:l.status)==="pending"?{data:void 0,loading:!0}:m&&!m.ok?{data:void 0,loading:!1}:{data:void 0,loading:F!==f}}const Ce=Pe;function Ae(r){return h.createFragmentsClient({...r,inject:M})}Object.defineProperty(s,"FragmentsApiVersionError",{enumerable:!0,get:()=>h.FragmentsApiVersionError}),Object.defineProperty(s,"FragmentsAreaError",{enumerable:!0,get:()=>h.FragmentsAreaError}),Object.defineProperty(s,"FragmentsLoadError",{enumerable:!0,get:()=>h.FragmentsLoadError}),Object.defineProperty(s,"createSourceCache",{enumerable:!0,get:()=>h.createSourceCache}),s.AREA_UNRESOLVED=w,s.Area=Ee,s.FragmentRenderer=ie,s.FragmentStylesheet=_,s.FragmentsClientContext=S,s.FragmentsClientProvider=D,s.FragmentsProvider=he,s.InstanceIdContext=O,s.ModulesMapContext=C,s.ModulesMapProvider=L,s.ProjectPropertiesContext=b,s.createBrowserClient=Ae,s.defaultProjectProperties=j,s.injectStylesheet=M,s.useArea=B,s.useCssChunk=le,s.useFragmentComponent=U,s.useFragmentMetrics=se,s.useFragmentStylesheet=z,s.useProjectProperty=ge,s.useSource=Ce,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fragmentsx/runtime-react",
3
3
  "private": false,
4
- "version": "0.2.0-dev-20260928114300",
4
+ "version": "0.2.0-dev-20260928123417",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@graph-state/core": "^0.13.3",
35
- "@fragmentsx/fragments-client": "0.2.0-dev-20260928114300"
35
+ "@fragmentsx/fragments-client": "0.2.0-dev-20260928123417"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@testing-library/jest-dom": "^6.6.3",