@fragmentsx/runtime-react 0.2.0-dev-20260831061037 → 0.2.0-dev-20260901074721
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.d.ts +45 -2
- package/dist/index.es.js +129 -111
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -169,9 +169,10 @@ declare interface FragmentStylesheetProps {
|
|
|
169
169
|
*
|
|
170
170
|
* @param href - CDN URL стилевого файла
|
|
171
171
|
* @param key - уникальный ключ для dedup (например `chunk:201` или `fragment:42:abc`)
|
|
172
|
-
* @returns
|
|
172
|
+
* @returns handle — вызываемый cleanup (при refCount = 0 удаляет `<link>` из
|
|
173
|
+
* head) с дополнительным свойством `loaded: Promise<void>`
|
|
173
174
|
*/
|
|
174
|
-
export declare const injectStylesheet: (href: string, key: string) =>
|
|
175
|
+
export declare const injectStylesheet: (href: string, key: string) => StylesheetHandle;
|
|
175
176
|
|
|
176
177
|
export declare const InstanceIdContext: Context<string | null>;
|
|
177
178
|
|
|
@@ -226,6 +227,40 @@ export declare interface ReachGoalInfo {
|
|
|
226
227
|
campaignId?: number;
|
|
227
228
|
}
|
|
228
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Ref-counted `<link rel="stylesheet">` injector для compiled fragment CSS delivery (Req #11).
|
|
232
|
+
*
|
|
233
|
+
* **Single source of truth для ref-count dedup**: $cssChunks (client-core) делегирует
|
|
234
|
+
* DOM injection сюда через factory parameter (BLOCKER-4 architectural decision).
|
|
235
|
+
* Module-level registry гарантирует что за один bundle-scope один key = один <link>.
|
|
236
|
+
*
|
|
237
|
+
* Использование:
|
|
238
|
+
* ```ts
|
|
239
|
+
* const handle = injectStylesheet('https://cdn.example.com/chunk.css', 'chunk:201');
|
|
240
|
+
* await handle.loaded; // готовность CSS (load / error / таймаут — quick-260831-etq)
|
|
241
|
+
* // ... позже при unmount:
|
|
242
|
+
* handle();
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* Ref-count semantics:
|
|
246
|
+
* - Первый вызов с key → создаёт `<link>`, refCount = 1
|
|
247
|
+
* - Повторный вызов с тем же key → refCount++, новый `<link>` НЕ создаётся
|
|
248
|
+
* - Cleanup → refCount--; при refCount = 0 → `<link>` удаляется из head
|
|
249
|
+
*
|
|
250
|
+
* Канал готовности (quick-260831-etq, D-5/D-6): возвращаемый handle несёт
|
|
251
|
+
* `loaded: Promise<void>`, который резолвится по `load`, по `error` (сбой
|
|
252
|
+
* трактуется как «готово» — показать без стилей лучше, чем зависнуть) или по
|
|
253
|
+
* истечении `STYLESHEET_READY_TIMEOUT_MS`, если ни одно событие не пришло
|
|
254
|
+
* (недоступный/молчащий CDN). Промис никогда не отвергается.
|
|
255
|
+
*
|
|
256
|
+
* SSR safety: в Node (isBrowser === false) возвращает свежий noop-handle с уже
|
|
257
|
+
* разрешённым `loaded` — общий экспорт `noop` не мутируется.
|
|
258
|
+
*/
|
|
259
|
+
/** Канал готовности CSS у ref-counted injectStylesheet handle. */
|
|
260
|
+
declare type StylesheetHandle = (() => void) & {
|
|
261
|
+
loaded: Promise<void>;
|
|
262
|
+
};
|
|
263
|
+
|
|
229
264
|
/** Suspense-режим (по умолчанию либо явный `suspense: true`) — прежний throw-протокол. */
|
|
230
265
|
export declare function useArea(areaCode: string, options?: UseAreaOptions & {
|
|
231
266
|
suspense?: true;
|
|
@@ -259,6 +294,14 @@ export declare interface UseAreaOptions {
|
|
|
259
294
|
*/
|
|
260
295
|
export declare interface UseAreaResult {
|
|
261
296
|
rootFragmentId: number;
|
|
297
|
+
/**
|
|
298
|
+
* Quick 260831-dor (INT-10): id выбранного варианта — вход для атрибуции
|
|
299
|
+
* на стороне площадки-потребителя (префикс партнёрской ссылки трекера).
|
|
300
|
+
* `$area` уже нормализует отсутствие поля у backend'а в `null` (не `0` —
|
|
301
|
+
* `0` неотличим от настоящего id и молча испортил бы атрибуцию), поэтому
|
|
302
|
+
* поле обязательное и nullable, а не опциональное.
|
|
303
|
+
*/
|
|
304
|
+
variantId: number | null;
|
|
262
305
|
/**
|
|
263
306
|
* Phase 73, B-02/B-06: значения props корневого артефакта, разрешённые сервером
|
|
264
307
|
* (`resolveVariantProps`) — привязки `$ref` сюда не доезжают, только готовые значения.
|
package/dist/index.es.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { createFragmentsClient as
|
|
4
|
-
import { FragmentsApiVersionError as
|
|
5
|
-
const
|
|
1
|
+
import { jsx as l, jsxs as j, Fragment as I } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as v, useContext as f, useMemo as P, useState as L, useEffect as F, useLayoutEffect as N, version as k, Component as b, Suspense as A } from "react";
|
|
3
|
+
import { AREA_GLOBAL_CSS_KEY as p, fragmentCssKey as O, fragmentFontsKey as U, createFragmentsClient as B } from "@fragmentsx/fragments-client";
|
|
4
|
+
import { FragmentsApiVersionError as oe, FragmentsAreaError as ie, FragmentsLoadError as fe } from "@fragmentsx/fragments-client";
|
|
5
|
+
const m = v(
|
|
6
6
|
null
|
|
7
7
|
);
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
return /* @__PURE__ */
|
|
8
|
+
m.displayName = "FragmentsClientContext";
|
|
9
|
+
function D(r) {
|
|
10
|
+
return /* @__PURE__ */ l(m.Provider, { value: r.value, children: r.children });
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
return f(
|
|
12
|
+
function K() {
|
|
13
|
+
return f(m);
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
15
|
+
const S = v(null);
|
|
16
|
+
S.displayName = "InstanceIdContext";
|
|
17
|
+
const g = v(
|
|
18
18
|
null
|
|
19
19
|
);
|
|
20
|
-
|
|
21
|
-
function
|
|
20
|
+
g.displayName = "ModulesMapContext";
|
|
21
|
+
function V({
|
|
22
22
|
value: r,
|
|
23
23
|
children: e
|
|
24
24
|
}) {
|
|
25
|
-
return /* @__PURE__ */
|
|
25
|
+
return /* @__PURE__ */ l(g.Provider, { value: r, children: e });
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const r = f(
|
|
29
|
-
return
|
|
27
|
+
function re() {
|
|
28
|
+
const r = f(m);
|
|
29
|
+
return P(
|
|
30
30
|
() => ({
|
|
31
31
|
reachGoal: (e) => {
|
|
32
32
|
var n, t;
|
|
@@ -36,36 +36,39 @@ function W() {
|
|
|
36
36
|
[r]
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
const e = f(
|
|
39
|
+
function G(r) {
|
|
40
|
+
const e = f(g);
|
|
41
41
|
if (!e)
|
|
42
42
|
throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");
|
|
43
43
|
return e.read(r);
|
|
44
44
|
}
|
|
45
|
-
const
|
|
45
|
+
const Y = typeof window < "u", x = Object.freeze({
|
|
46
46
|
rootFragmentId: 0,
|
|
47
|
+
variantId: null,
|
|
47
48
|
props: {},
|
|
48
49
|
projectProperties: {},
|
|
49
50
|
globalCssUrl: null
|
|
50
51
|
});
|
|
51
|
-
function
|
|
52
|
-
const n = f(
|
|
52
|
+
function $(r, e) {
|
|
53
|
+
const n = f(m);
|
|
53
54
|
if (!n)
|
|
54
55
|
throw new Error("[useArea] No FragmentsClientProvider in tree");
|
|
55
56
|
const t = n.$area;
|
|
56
57
|
if (!(t != null && t.read))
|
|
57
58
|
throw new Error("[useArea] $area plugin not mounted");
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
if (
|
|
59
|
+
const s = (e == null ? void 0 : e.suspense) ?? !0, d = (e == null ? void 0 : e.pause) === !0 || !Y && (e == null ? void 0 : e.ssr) === !1, a = (e == null ? void 0 : e.timeout) != null ? { timeout: e.timeout } : void 0, [, u] = L(0);
|
|
60
|
+
if (F(() => {
|
|
61
|
+
if (s || d) return;
|
|
61
62
|
let c = !0;
|
|
62
|
-
return t.resolve(r,
|
|
63
|
-
|
|
63
|
+
return Promise.resolve(t.resolve(r, a)).catch(() => {
|
|
64
|
+
}).finally(() => {
|
|
65
|
+
c && u((o) => o + 1);
|
|
64
66
|
}), () => {
|
|
65
67
|
c = !1;
|
|
66
68
|
};
|
|
67
|
-
}, [r,
|
|
68
|
-
return d ? x : (t.has(r) || t.resolve(r,
|
|
69
|
+
}, [r, s, e == null ? void 0 : e.pause, e == null ? void 0 : e.timeout, e == null ? void 0 : e.ssr]), s)
|
|
70
|
+
return d ? x : (t.has(r) || Promise.resolve(t.resolve(r, a)).catch(() => {
|
|
71
|
+
}), t.read(r));
|
|
69
72
|
if (d)
|
|
70
73
|
return { status: "idle", data: null, error: null };
|
|
71
74
|
if (t.has(r))
|
|
@@ -78,30 +81,45 @@ function V(r, e) {
|
|
|
78
81
|
error: c instanceof Error ? c : new Error(String(c))
|
|
79
82
|
};
|
|
80
83
|
}
|
|
81
|
-
return t.resolve(r,
|
|
84
|
+
return Promise.resolve(t.resolve(r, a)).catch(() => {
|
|
85
|
+
}), { status: "loading", data: null, error: null };
|
|
82
86
|
}
|
|
83
|
-
const w = typeof window < "u",
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return $;
|
|
87
|
-
const n = i.get(e);
|
|
88
|
-
if (n)
|
|
89
|
-
return n.refCount += 1, () => {
|
|
90
|
-
n.refCount -= 1, n.refCount === 0 && (n.linkEl.remove(), i.delete(e));
|
|
87
|
+
const w = typeof window < "u", z = 3e3, h = /* @__PURE__ */ new Map(), M = (r, e) => {
|
|
88
|
+
if (!w) {
|
|
89
|
+
const i = () => {
|
|
91
90
|
};
|
|
91
|
+
return i.loaded = Promise.resolve(), i;
|
|
92
|
+
}
|
|
93
|
+
const n = h.get(e);
|
|
94
|
+
if (n) {
|
|
95
|
+
n.refCount += 1;
|
|
96
|
+
const i = () => {
|
|
97
|
+
n.refCount -= 1, n.refCount === 0 && (n.clearReadyTimer(), n.linkEl.remove(), h.delete(e));
|
|
98
|
+
};
|
|
99
|
+
return i.loaded = n.loaded, i;
|
|
100
|
+
}
|
|
92
101
|
const t = document.createElement("link");
|
|
93
|
-
t.rel = "stylesheet", t.href = r, t.setAttribute("data-fragment-key", e)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
t.rel = "stylesheet", t.href = r, t.setAttribute("data-fragment-key", e);
|
|
103
|
+
let s;
|
|
104
|
+
const d = new Promise((i) => {
|
|
105
|
+
s = i;
|
|
106
|
+
}), a = () => {
|
|
107
|
+
c(), s();
|
|
108
|
+
}, u = setTimeout(a, z), c = () => clearTimeout(u);
|
|
109
|
+
t.addEventListener("load", a), t.addEventListener("error", a), document.head.appendChild(t);
|
|
110
|
+
const o = { refCount: 1, linkEl: t, loaded: d, clearReadyTimer: c };
|
|
111
|
+
h.set(e, o);
|
|
112
|
+
const y = () => {
|
|
113
|
+
o.refCount -= 1, o.refCount === 0 && (o.clearReadyTimer(), o.linkEl.remove(), h.delete(e));
|
|
97
114
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
115
|
+
return y.loaded = d, y;
|
|
116
|
+
}, H = w ? N : F;
|
|
117
|
+
function J(r, e) {
|
|
118
|
+
H(() => M(r, e), [r, e]);
|
|
101
119
|
}
|
|
102
|
-
const
|
|
103
|
-
function
|
|
104
|
-
return
|
|
120
|
+
const q = parseInt(k.split(".")[0], 10), Q = q >= 19;
|
|
121
|
+
function E({ href: r, fragmentKey: e }) {
|
|
122
|
+
return Q ? /* @__PURE__ */ l(
|
|
105
123
|
"link",
|
|
106
124
|
{
|
|
107
125
|
rel: "stylesheet",
|
|
@@ -109,13 +127,13 @@ function g({ href: r, fragmentKey: e }) {
|
|
|
109
127
|
precedence: "default",
|
|
110
128
|
"data-fragment-key": e
|
|
111
129
|
}
|
|
112
|
-
) : (
|
|
130
|
+
) : (J(r, e), null);
|
|
113
131
|
}
|
|
114
|
-
function
|
|
132
|
+
function te(r) {
|
|
115
133
|
}
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
class
|
|
134
|
+
const R = {}, C = v(null);
|
|
135
|
+
C.displayName = "ProjectPropertiesContext";
|
|
136
|
+
class T extends b {
|
|
119
137
|
constructor() {
|
|
120
138
|
super(...arguments), this.state = { hasError: !1 };
|
|
121
139
|
}
|
|
@@ -123,108 +141,108 @@ class S extends p {
|
|
|
123
141
|
return { hasError: !0 };
|
|
124
142
|
}
|
|
125
143
|
componentDidCatch(e, n) {
|
|
126
|
-
var t,
|
|
127
|
-
process.env.NODE_ENV !== "production" && console.error("[fragments] Area error:", e, n.componentStack), (
|
|
144
|
+
var t, s;
|
|
145
|
+
process.env.NODE_ENV !== "production" && console.error("[fragments] Area error:", e, n.componentStack), (s = (t = this.props).onError) == null || s.call(t, e);
|
|
128
146
|
}
|
|
129
147
|
render() {
|
|
130
148
|
return this.state.hasError ? null : this.props.children;
|
|
131
149
|
}
|
|
132
150
|
}
|
|
133
|
-
const
|
|
151
|
+
const _ = ({
|
|
134
152
|
fragmentId: r,
|
|
135
153
|
props: e,
|
|
136
154
|
globalCssUrl: n = null,
|
|
137
|
-
projectProperties: t =
|
|
155
|
+
projectProperties: t = R
|
|
138
156
|
}) => {
|
|
139
|
-
const
|
|
140
|
-
return /* @__PURE__ */
|
|
141
|
-
n != null && /* @__PURE__ */
|
|
142
|
-
|
|
157
|
+
const s = G(r), a = K().$fragments, u = a == null ? void 0 : a.getRef(r), c = a == null ? void 0 : a.getScopeClass(r), o = e ?? {};
|
|
158
|
+
return /* @__PURE__ */ j(I, { children: [
|
|
159
|
+
n != null && /* @__PURE__ */ l(
|
|
160
|
+
E,
|
|
143
161
|
{
|
|
144
162
|
href: n,
|
|
145
|
-
fragmentKey:
|
|
163
|
+
fragmentKey: p
|
|
146
164
|
}
|
|
147
165
|
),
|
|
148
|
-
|
|
149
|
-
|
|
166
|
+
u && /* @__PURE__ */ l(
|
|
167
|
+
E,
|
|
150
168
|
{
|
|
151
|
-
href:
|
|
152
|
-
fragmentKey:
|
|
169
|
+
href: u.cssUrl,
|
|
170
|
+
fragmentKey: O(r)
|
|
153
171
|
}
|
|
154
172
|
),
|
|
155
|
-
(
|
|
156
|
-
|
|
173
|
+
(u == null ? void 0 : u.fontsUrl) != null && /* @__PURE__ */ l(
|
|
174
|
+
E,
|
|
157
175
|
{
|
|
158
|
-
href:
|
|
159
|
-
fragmentKey:
|
|
176
|
+
href: u.fontsUrl,
|
|
177
|
+
fragmentKey: U(r)
|
|
160
178
|
}
|
|
161
179
|
),
|
|
162
|
-
/* @__PURE__ */
|
|
180
|
+
/* @__PURE__ */ l(C.Provider, { value: t, children: /* @__PURE__ */ l(S.Provider, { value: null, children: /* @__PURE__ */ l(
|
|
163
181
|
"div",
|
|
164
182
|
{
|
|
165
183
|
className: c,
|
|
166
184
|
style: { display: "contents" },
|
|
167
|
-
children: /* @__PURE__ */
|
|
185
|
+
children: /* @__PURE__ */ l(s, { ...o })
|
|
168
186
|
}
|
|
169
187
|
) }) })
|
|
170
188
|
] });
|
|
171
|
-
},
|
|
189
|
+
}, ne = ({ onError: r, ...e }) => /* @__PURE__ */ l(A, { fallback: null, children: /* @__PURE__ */ l(T, { onError: r, children: /* @__PURE__ */ l(_, { ...e }) }) }), W = ({ areaCode: r, options: e }) => {
|
|
172
190
|
if ((e == null ? void 0 : e.pause) === !0)
|
|
173
191
|
return null;
|
|
174
|
-
const n =
|
|
192
|
+
const n = $(r, {
|
|
175
193
|
timeout: e == null ? void 0 : e.timeout,
|
|
176
194
|
ssr: e == null ? void 0 : e.ssr
|
|
177
195
|
});
|
|
178
196
|
if (n === x)
|
|
179
197
|
return null;
|
|
180
|
-
const { rootFragmentId: t, props:
|
|
181
|
-
return /* @__PURE__ */
|
|
182
|
-
|
|
198
|
+
const { rootFragmentId: t, props: s, projectProperties: d, globalCssUrl: a } = n, u = typeof (e == null ? void 0 : e.props) == "function" ? e.props(s) : e != null && e.props ? { ...s, ...e.props } : s;
|
|
199
|
+
return /* @__PURE__ */ l(
|
|
200
|
+
_,
|
|
183
201
|
{
|
|
184
202
|
fragmentId: t,
|
|
185
|
-
props:
|
|
186
|
-
globalCssUrl:
|
|
203
|
+
props: u,
|
|
204
|
+
globalCssUrl: a,
|
|
187
205
|
projectProperties: d
|
|
188
206
|
}
|
|
189
207
|
);
|
|
190
|
-
},
|
|
191
|
-
function
|
|
192
|
-
const n =
|
|
208
|
+
}, le = ({ areaCode: r, options: e }) => /* @__PURE__ */ l(A, { fallback: (e == null ? void 0 : e.fallback) ?? null, children: /* @__PURE__ */ l(T, { onError: e == null ? void 0 : e.onError, children: /* @__PURE__ */ l(W, { areaCode: r, options: e }) }) });
|
|
209
|
+
function ae({ client: r, children: e }) {
|
|
210
|
+
const n = P(
|
|
193
211
|
() => ({
|
|
194
212
|
read: (t) => r.$fragments.read(t)
|
|
195
213
|
}),
|
|
196
214
|
[r]
|
|
197
215
|
);
|
|
198
|
-
return /* @__PURE__ */
|
|
216
|
+
return /* @__PURE__ */ l(D, { value: r, children: /* @__PURE__ */ l(V, { value: n, children: e }) });
|
|
199
217
|
}
|
|
200
|
-
function
|
|
201
|
-
return (f(
|
|
218
|
+
function se(r) {
|
|
219
|
+
return (f(C) ?? R)[r];
|
|
202
220
|
}
|
|
203
|
-
function
|
|
204
|
-
return
|
|
221
|
+
function ue(r) {
|
|
222
|
+
return B({ ...r, inject: M });
|
|
205
223
|
}
|
|
206
224
|
export {
|
|
207
225
|
x as AREA_UNRESOLVED,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
le as Area,
|
|
227
|
+
ne as FragmentRenderer,
|
|
228
|
+
E as FragmentStylesheet,
|
|
229
|
+
oe as FragmentsApiVersionError,
|
|
230
|
+
ie as FragmentsAreaError,
|
|
231
|
+
m as FragmentsClientContext,
|
|
232
|
+
D as FragmentsClientProvider,
|
|
233
|
+
fe as FragmentsLoadError,
|
|
234
|
+
ae as FragmentsProvider,
|
|
235
|
+
S as InstanceIdContext,
|
|
236
|
+
g as ModulesMapContext,
|
|
237
|
+
V as ModulesMapProvider,
|
|
238
|
+
C as ProjectPropertiesContext,
|
|
239
|
+
ue as createBrowserClient,
|
|
240
|
+
R as defaultProjectProperties,
|
|
241
|
+
M as injectStylesheet,
|
|
242
|
+
$ as useArea,
|
|
243
|
+
te as useCssChunk,
|
|
244
|
+
G as useFragmentComponent,
|
|
245
|
+
re as useFragmentMetrics,
|
|
246
|
+
J as useFragmentStylesheet,
|
|
247
|
+
se as useProjectProperty
|
|
230
248
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,
|
|
1
|
+
(function(t,s){typeof exports=="object"&&typeof module<"u"?s(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"],s):(t=typeof globalThis<"u"?globalThis:t||self,s(t.FragmentsRuntimeReact={},t.jsxRuntime,t.React,t.fragmentsClient))})(this,function(t,s,u,m){"use strict";const g=u.createContext(null);g.displayName="FragmentsClientContext";function M(r){return s.jsx(g.Provider,{value:r.value,children:r.children})}function N(){return u.useContext(g)}const y=u.createContext(null);y.displayName="InstanceIdContext";const E=u.createContext(null);E.displayName="ModulesMapContext";function j({value:r,children:e}){return s.jsx(E.Provider,{value:r,children:e})}function k(){const r=u.useContext(g);return u.useMemo(()=>({reachGoal:e=>{var l,n;(n=(l=r==null?void 0:r.$metrics)==null?void 0:l.reachGoal)==null||n.call(l,e)}}),[r])}function w(r){const e=u.useContext(E);if(!e)throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");return e.read(r)}const x=typeof window<"u",F=Object.freeze({rootFragmentId:0,variantId:null,props:{},projectProperties:{},globalCssUrl:null});function T(r,e){const l=u.useContext(g);if(!l)throw new Error("[useArea] No FragmentsClientProvider in tree");const n=l.$area;if(!(n!=null&&n.read))throw new Error("[useArea] $area plugin not mounted");const c=(e==null?void 0:e.suspense)??!0,i=(e==null?void 0:e.pause)===!0||!x&&(e==null?void 0:e.ssr)===!1,a=(e==null?void 0:e.timeout)!=null?{timeout:e.timeout}:void 0,[,d]=u.useState(0);if(u.useEffect(()=>{if(c||i)return;let o=!0;return Promise.resolve(n.resolve(r,a)).catch(()=>{}).finally(()=>{o&&d(f=>f+1)}),()=>{o=!1}},[r,c,e==null?void 0:e.pause,e==null?void 0:e.timeout,e==null?void 0:e.ssr]),c)return i?F:(n.has(r)||Promise.resolve(n.resolve(r,a)).catch(()=>{}),n.read(r));if(i)return{status:"idle",data:null,error:null};if(n.has(r))try{return{status:"ready",data:n.read(r),error:null}}catch(o){return{status:"not-found",data:null,error:o instanceof Error?o:new Error(String(o))}}return Promise.resolve(n.resolve(r,a)).catch(()=>{}),{status:"loading",data:null,error:null}}const _=typeof window<"u",U=3e3,v=new Map,A=(r,e)=>{if(!_){const h=()=>{};return h.loaded=Promise.resolve(),h}const l=v.get(e);if(l){l.refCount+=1;const h=()=>{l.refCount-=1,l.refCount===0&&(l.clearReadyTimer(),l.linkEl.remove(),v.delete(e))};return h.loaded=l.loaded,h}const n=document.createElement("link");n.rel="stylesheet",n.href=r,n.setAttribute("data-fragment-key",e);let c;const i=new Promise(h=>{c=h}),a=()=>{o(),c()},d=setTimeout(a,U),o=()=>clearTimeout(d);n.addEventListener("load",a),n.addEventListener("error",a),document.head.appendChild(n);const f={refCount:1,linkEl:n,loaded:i,clearReadyTimer:o};v.set(e,f);const O=()=>{f.refCount-=1,f.refCount===0&&(f.clearReadyTimer(),f.linkEl.remove(),v.delete(e))};return O.loaded=i,O},B=_?u.useLayoutEffect:u.useEffect;function b(r,e){B(()=>A(r,e),[r,e])}const D=parseInt(u.version.split(".")[0],10)>=19;function C({href:r,fragmentKey:e}){return D?s.jsx("link",{rel:"stylesheet",href:r,precedence:"default","data-fragment-key":e}):(b(r,e),null)}function V(r){}const S={},P=u.createContext(null);P.displayName="ProjectPropertiesContext";class I extends u.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,l){var n,c;process.env.NODE_ENV!=="production"&&console.error("[fragments] Area error:",e,l.componentStack),(c=(n=this.props).onError)==null||c.call(n,e)}render(){return this.state.hasError?null:this.props.children}}const L=({fragmentId:r,props:e,globalCssUrl:l=null,projectProperties:n=S})=>{const c=w(r),a=N().$fragments,d=a==null?void 0:a.getRef(r),o=a==null?void 0:a.getScopeClass(r),f=e??{};return s.jsxs(s.Fragment,{children:[l!=null&&s.jsx(C,{href:l,fragmentKey:m.AREA_GLOBAL_CSS_KEY}),d&&s.jsx(C,{href:d.cssUrl,fragmentKey:m.fragmentCssKey(r)}),(d==null?void 0:d.fontsUrl)!=null&&s.jsx(C,{href:d.fontsUrl,fragmentKey:m.fragmentFontsKey(r)}),s.jsx(P.Provider,{value:n,children:s.jsx(y.Provider,{value:null,children:s.jsx("div",{className:o,style:{display:"contents"},children:s.jsx(c,{...f})})})})]})},K=({onError:r,...e})=>s.jsx(u.Suspense,{fallback:null,children:s.jsx(I,{onError:r,children:s.jsx(L,{...e})})}),q=({areaCode:r,options:e})=>{if((e==null?void 0:e.pause)===!0)return null;const l=T(r,{timeout:e==null?void 0:e.timeout,ssr:e==null?void 0:e.ssr});if(l===F)return null;const{rootFragmentId:n,props:c,projectProperties:i,globalCssUrl:a}=l,d=typeof(e==null?void 0:e.props)=="function"?e.props(c):e!=null&&e.props?{...c,...e.props}:c;return s.jsx(L,{fragmentId:n,props:d,globalCssUrl:a,projectProperties:i})},G=({areaCode:r,options:e})=>s.jsx(u.Suspense,{fallback:(e==null?void 0:e.fallback)??null,children:s.jsx(I,{onError:e==null?void 0:e.onError,children:s.jsx(q,{areaCode:r,options:e})})});function R({client:r,children:e}){const l=u.useMemo(()=>({read:n=>r.$fragments.read(n)}),[r]);return s.jsx(M,{value:r,children:s.jsx(j,{value:l,children:e})})}function Y(r){return(u.useContext(P)??S)[r]}function J(r){return m.createFragmentsClient({...r,inject:A})}Object.defineProperty(t,"FragmentsApiVersionError",{enumerable:!0,get:()=>m.FragmentsApiVersionError}),Object.defineProperty(t,"FragmentsAreaError",{enumerable:!0,get:()=>m.FragmentsAreaError}),Object.defineProperty(t,"FragmentsLoadError",{enumerable:!0,get:()=>m.FragmentsLoadError}),t.AREA_UNRESOLVED=F,t.Area=G,t.FragmentRenderer=K,t.FragmentStylesheet=C,t.FragmentsClientContext=g,t.FragmentsClientProvider=M,t.FragmentsProvider=R,t.InstanceIdContext=y,t.ModulesMapContext=E,t.ModulesMapProvider=j,t.ProjectPropertiesContext=P,t.createBrowserClient=J,t.defaultProjectProperties=S,t.injectStylesheet=A,t.useArea=T,t.useCssChunk=V,t.useFragmentComponent=w,t.useFragmentMetrics=k,t.useFragmentStylesheet=b,t.useProjectProperty=Y,Object.defineProperty(t,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-
|
|
4
|
+
"version": "0.2.0-dev-20260901074721",
|
|
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-
|
|
35
|
+
"@fragmentsx/fragments-client": "0.2.0-dev-20260901074721"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@testing-library/jest-dom": "^6.6.3",
|