@fragmentsx/runtime-react 0.2.0-dev-20260910143938 → 0.2.0-dev-20260922090625
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 +65 -3
- package/dist/index.es.js +153 -125
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { FragmentsLoadError } from '@fragmentsx/fragments-client';
|
|
|
9
9
|
import { GraphState } from '@graph-state/core';
|
|
10
10
|
import { ReactElement } from 'react';
|
|
11
11
|
import { ReactNode } from 'react';
|
|
12
|
+
import { ResolvedSlotPosition } from '@fragmentsx/fragments-client';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Area — публичный компонент для рендеринга compiled fragment в consumer app.
|
|
@@ -114,6 +115,8 @@ declare type ArtifactSchemaFieldAtDepth<D extends number> = D extends 0 ? never
|
|
|
114
115
|
readonly type: "Array";
|
|
115
116
|
readonly defaultValue?: readonly unknown[];
|
|
116
117
|
readonly definition?: ArtifactSchemaFieldAtDepth<PrevDepth<D>>;
|
|
118
|
+
}) | (ArtifactSchemaFieldCommon & {
|
|
119
|
+
readonly type: typeof NODE_SCHEMA_TYPE;
|
|
117
120
|
});
|
|
118
121
|
|
|
119
122
|
/**
|
|
@@ -138,7 +141,13 @@ declare type ArtifactSchemaFieldAtDepth<D extends number> = D extends 0 ? never
|
|
|
138
141
|
* Зарезервированные типы словаря (`Event`, `Goal`, `ComponentInstance`,
|
|
139
142
|
* `Date`, `'fragment'`) в объединение НЕ входят — этим `ArtifactSchema`
|
|
140
143
|
* отличается от `SchemaFieldDescriptor` (`propsFromSchema.ts`), у которого
|
|
141
|
-
* `type: VariableType` принимает любой тип словаря.
|
|
144
|
+
* `type: VariableType` принимает любой тип словаря. Десятый вариант — `Node`
|
|
145
|
+
* (Phase 106, SLOT-01): дырка, содержимое которой кладёт не автор шаблона.
|
|
146
|
+
* `Node` живёт ТОЛЬКО здесь и в литеральной valibot-схеме гейта — в словарь
|
|
147
|
+
* `variableType` он не заводится (переменной типа «узел» не бывает, С-05), и
|
|
148
|
+
* поэтому не является ни разрешённым, ни зарезервированным типом словаря; у
|
|
149
|
+
* него нет `defaultValue` — значение по умолчанию пришлось бы сериализовать в
|
|
150
|
+
* схему, а узел не сериализуется. Ключи `RESERVED_SCHEMA_KEYS`
|
|
142
151
|
* (`__proto__`/`constructor`/`prototype`/`_id`/`_type`/`parent`/`$ref`) типом
|
|
143
152
|
* не выражаются и остаются структурным кодом `SCHEMA_RESERVED_KEY` в гейте —
|
|
144
153
|
* TypeScript не умеет запретить конкретные строковые ключи объекта общим
|
|
@@ -264,7 +273,7 @@ declare type FieldRequired<F extends SchemaFieldDescriptor, ConsiderDefault exte
|
|
|
264
273
|
* индексированного доступа вне условного типа, который резолвился бы по
|
|
265
274
|
* ограничению.
|
|
266
275
|
*/
|
|
267
|
-
declare type FieldValueType<F extends SchemaFieldDescriptor, D extends number> = F["type"] extends "Enum" ? EnumFieldType<F> : F["type"] extends "Object" ? ObjectFieldType<F, D> : F["type"] extends "Array" ? ArrayFieldType<F, D> : ValueOfVariableType<F["type"]
|
|
276
|
+
declare type FieldValueType<F extends SchemaFieldDescriptor, D extends number> = F["type"] extends "Enum" ? EnumFieldType<F> : F["type"] extends "Object" ? ObjectFieldType<F, D> : F["type"] extends "Array" ? ArrayFieldType<F, D> : F["type"] extends typeof NODE_SCHEMA_TYPE ? ValueOfNodeType : ValueOfVariableType<Extract<F["type"], VariableType>>;
|
|
268
277
|
|
|
269
278
|
export declare interface FragmentMetrics {
|
|
270
279
|
reachGoal: (info: ReachGoalInfo) => void;
|
|
@@ -291,6 +300,21 @@ export declare interface FragmentRendererProps {
|
|
|
291
300
|
globalCssUrl?: string | null;
|
|
292
301
|
/** Словарь project-переменных площадки (манифест области или блок данных preview); ключ — имя переменной, значение — голое (D-72-02). */
|
|
293
302
|
projectProperties?: Record<string, unknown>;
|
|
303
|
+
/**
|
|
304
|
+
* Phase 105 план 105-05 (D-105-11): конус — список id (root + reachable),
|
|
305
|
+
* корень первым. Необязательное со значением по умолчанию «только
|
|
306
|
+
* собственный id» — так превью и любой прямой потребитель этого тела без
|
|
307
|
+
* настоящего конуса (до плана 105-08) продолжают работать без правки.
|
|
308
|
+
*/
|
|
309
|
+
fragments?: number[];
|
|
310
|
+
/**
|
|
311
|
+
* Phase 106 (D-106-01/SLOT-04/план 05): дырки шаблона (`type: 'Node'`),
|
|
312
|
+
* заполненные данными варианта — дерево ссылок `{fragmentId, props, slots}`
|
|
313
|
+
* либо список таких ссылок (`ResolvedSlotPosition`). Необязательное —
|
|
314
|
+
* превью и любой прямой потребитель без слотов продолжают работать без
|
|
315
|
+
* правки (дырка рисует пустоту, как и без пропа).
|
|
316
|
+
*/
|
|
317
|
+
slots?: Record<string, ResolvedSlotPosition>;
|
|
294
318
|
onError?: (error: Error) => void;
|
|
295
319
|
}
|
|
296
320
|
|
|
@@ -430,6 +454,27 @@ declare interface ModulesMapProviderProps {
|
|
|
430
454
|
children: ReactNode;
|
|
431
455
|
}
|
|
432
456
|
|
|
457
|
+
/**
|
|
458
|
+
* Третья таблица проекции типа (D-97-03: три таблицы — три домена), рядом с
|
|
459
|
+
* `VARIABLE_TYPE_TO_TS` (`variableTypeToTs.ts`). `Node` не входит в словарь
|
|
460
|
+
* `variableType` (`constants/index.ts`) — переменной этого типа не бывает по
|
|
461
|
+
* С-05, сервер её не развернёт; дырка объявляется ТОЛЬКО в литерале схемы
|
|
462
|
+
* артефакта. Сливать эту таблицу с `VARIABLE_TYPE_TO_TS` ЗАПРЕЩЕНО — тот же
|
|
463
|
+
* запрет, что охраняет разделение `VARIABLE_TYPE_TO_TS` от соседних реестров
|
|
464
|
+
* `VariableType → valibot-схема` (D-97-03).
|
|
465
|
+
*
|
|
466
|
+
* `value` несёт носитель типа `ReactNode` — импорт типовый, рантайм-импорта
|
|
467
|
+
* React в пакете `@fragmentsx/definition` не появляется.
|
|
468
|
+
*/
|
|
469
|
+
declare const NODE_SCHEMA_TYPE: "Node";
|
|
470
|
+
|
|
471
|
+
declare const NODE_TYPE_TO_TS: {
|
|
472
|
+
Node: {
|
|
473
|
+
ts: string;
|
|
474
|
+
value: ReactNode;
|
|
475
|
+
};
|
|
476
|
+
};
|
|
477
|
+
|
|
433
478
|
/**
|
|
434
479
|
* Тип поля `Object`. Вырожденный вердикт — литеральный `{}` (пустой
|
|
435
480
|
* объектный тип БЕЗ индексной сигнатуры), когда `fields` отсутствует или
|
|
@@ -534,7 +579,7 @@ export declare interface ReachGoalInfo {
|
|
|
534
579
|
* тип значения, которое мутируется в рантайме.
|
|
535
580
|
*/
|
|
536
581
|
export declare interface SchemaFieldDescriptor {
|
|
537
|
-
readonly type: VariableType;
|
|
582
|
+
readonly type: VariableType | typeof NODE_SCHEMA_TYPE;
|
|
538
583
|
readonly required?: boolean;
|
|
539
584
|
readonly defaultValue?: unknown;
|
|
540
585
|
/** `Enum` — варианты значения; `PropsFromSchema` сужает до `cases[].id`. */
|
|
@@ -648,6 +693,20 @@ export declare interface UseAreaResult {
|
|
|
648
693
|
* `null` — backend не отдал global reset; baseline применяться не будет.
|
|
649
694
|
*/
|
|
650
695
|
globalCssUrl: string | null;
|
|
696
|
+
/**
|
|
697
|
+
* Phase 105 план 105-05 (D-105-11): конус — список id (root + reachable),
|
|
698
|
+
* корень первым. `$area` уже нормализует отсутствие поля у backend'а в
|
|
699
|
+
* `[]` — потребитель (`Area`/`FragmentRenderer`) не делает optional-проверку.
|
|
700
|
+
*/
|
|
701
|
+
fragments: number[];
|
|
702
|
+
/**
|
|
703
|
+
* Phase 106 (D-106-01/SLOT-04/план 05): дырки шаблона (`type: 'Node'`),
|
|
704
|
+
* заполненные данными варианта — дерево ссылок `{fragmentId, props, slots}`
|
|
705
|
+
* либо список таких ссылок (`ResolvedSlotPosition`). `$area` уже
|
|
706
|
+
* нормализует отсутствие поля у backend'а в `{}` — потребитель
|
|
707
|
+
* (`Area`/`FragmentRenderer`) не делает optional-проверку.
|
|
708
|
+
*/
|
|
709
|
+
slots: Record<string, ResolvedSlotPosition>;
|
|
651
710
|
}
|
|
652
711
|
|
|
653
712
|
/**
|
|
@@ -713,6 +772,9 @@ export declare function useFragmentStylesheet(href: string, key: string): void;
|
|
|
713
772
|
|
|
714
773
|
export declare function useProjectProperty<K extends keyof ProjectProperties>(name: K): ProjectProperties[K];
|
|
715
774
|
|
|
775
|
+
/** Носитель типа поля `Node` — читает `value`-проекцию третьей таблицы `NODE_TYPE_TO_TS` (D-97-03: три таблицы, три домена, слияние с `VARIABLE_TYPE_TO_TS` запрещено). */
|
|
776
|
+
declare type ValueOfNodeType = (typeof NODE_TYPE_TO_TS)[typeof NODE_SCHEMA_TYPE]["value"];
|
|
777
|
+
|
|
716
778
|
/** Носитель типа поля-НЕ-Enum/Object/Array — читает `value`-проекцию таблицы `VARIABLE_TYPE_TO_TS` (носитель, значение не используется, только тип). */
|
|
717
779
|
declare type ValueOfVariableType<T extends VariableType> = (typeof VARIABLE_TYPE_TO_TS)[T]["value"];
|
|
718
780
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as v, useContext as f, useMemo as
|
|
3
|
-
import { AREA_GLOBAL_CSS_KEY as
|
|
4
|
-
import { FragmentsApiVersionError as
|
|
5
|
-
const
|
|
1
|
+
import { jsx as a, jsxs as _, Fragment as k } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as v, useContext as f, useMemo as A, useState as L, useEffect as S, useLayoutEffect as b, version as O, Component as B, Suspense as w, createElement as D } from "react";
|
|
3
|
+
import { toScopeClassName as $, AREA_GLOBAL_CSS_KEY as U, resolveStylesHref as V, fragmentCssKey as G, createFragmentsClient as K } from "@fragmentsx/fragments-client";
|
|
4
|
+
import { FragmentsApiVersionError as ve, FragmentsAreaError as Ee, FragmentsLoadError as ge } from "@fragmentsx/fragments-client";
|
|
5
|
+
const E = v(
|
|
6
6
|
null
|
|
7
7
|
);
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
return /* @__PURE__ */
|
|
8
|
+
E.displayName = "FragmentsClientContext";
|
|
9
|
+
function Y(r) {
|
|
10
|
+
return /* @__PURE__ */ a(E.Provider, { value: r.value, children: r.children });
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
const S = v(null);
|
|
16
|
-
S.displayName = "InstanceIdContext";
|
|
12
|
+
const M = v(null);
|
|
13
|
+
M.displayName = "InstanceIdContext";
|
|
17
14
|
const g = v(
|
|
18
15
|
null
|
|
19
16
|
);
|
|
20
17
|
g.displayName = "ModulesMapContext";
|
|
21
|
-
function
|
|
18
|
+
function H({
|
|
22
19
|
value: r,
|
|
23
20
|
children: e
|
|
24
21
|
}) {
|
|
25
|
-
return /* @__PURE__ */
|
|
22
|
+
return /* @__PURE__ */ a(g.Provider, { value: r, children: e });
|
|
26
23
|
}
|
|
27
|
-
function
|
|
28
|
-
const r = f(
|
|
29
|
-
return
|
|
24
|
+
function ue() {
|
|
25
|
+
const r = f(E);
|
|
26
|
+
return A(
|
|
30
27
|
() => ({
|
|
31
28
|
reachGoal: (e) => {
|
|
32
29
|
var n, t;
|
|
@@ -36,93 +33,98 @@ function re() {
|
|
|
36
33
|
[r]
|
|
37
34
|
);
|
|
38
35
|
}
|
|
39
|
-
function
|
|
36
|
+
function z(r) {
|
|
40
37
|
const e = f(g);
|
|
41
38
|
if (!e)
|
|
42
39
|
throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");
|
|
43
40
|
return e.read(r);
|
|
44
41
|
}
|
|
45
|
-
const
|
|
42
|
+
const J = typeof window < "u", x = Object.freeze({
|
|
46
43
|
rootFragmentId: 0,
|
|
47
44
|
variantId: null,
|
|
48
45
|
props: {},
|
|
49
46
|
projectProperties: {},
|
|
50
|
-
globalCssUrl: null
|
|
47
|
+
globalCssUrl: null,
|
|
48
|
+
// Phase 105 план 105-05: пустой конус — форма возврата хука не меняется,
|
|
49
|
+
// обёртка рендера (задача 3) остаётся без атрибута class на этом сентинеле.
|
|
50
|
+
fragments: [],
|
|
51
|
+
// Phase 106: пустой словарь слотов — сентинел не разворачивает ни одной ссылки.
|
|
52
|
+
slots: {}
|
|
51
53
|
});
|
|
52
|
-
function
|
|
53
|
-
const n = f(
|
|
54
|
+
function q(r, e) {
|
|
55
|
+
const n = f(E);
|
|
54
56
|
if (!n)
|
|
55
57
|
throw new Error("[useArea] No FragmentsClientProvider in tree");
|
|
56
58
|
const t = n.$area;
|
|
57
59
|
if (!(t != null && t.read))
|
|
58
60
|
throw new Error("[useArea] $area plugin not mounted");
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
if (
|
|
62
|
-
let
|
|
63
|
-
return Promise.resolve(t.resolve(r,
|
|
61
|
+
const l = (e == null ? void 0 : e.suspense) ?? !0, u = (e == null ? void 0 : e.pause) === !0 || !J && (e == null ? void 0 : e.ssr) === !1, c = (e == null ? void 0 : e.timeout) != null ? { timeout: e.timeout } : void 0, [, m] = L(0);
|
|
62
|
+
if (S(() => {
|
|
63
|
+
if (l || u) return;
|
|
64
|
+
let s = !0;
|
|
65
|
+
return Promise.resolve(t.resolve(r, c)).catch(() => {
|
|
64
66
|
}).finally(() => {
|
|
65
|
-
|
|
67
|
+
s && m((o) => o + 1);
|
|
66
68
|
}), () => {
|
|
67
|
-
|
|
69
|
+
s = !1;
|
|
68
70
|
};
|
|
69
|
-
}, [r,
|
|
70
|
-
return
|
|
71
|
+
}, [r, l, e == null ? void 0 : e.pause, e == null ? void 0 : e.timeout, e == null ? void 0 : e.ssr]), l)
|
|
72
|
+
return u ? x : (t.has(r) || Promise.resolve(t.resolve(r, c)).catch(() => {
|
|
71
73
|
}), t.read(r));
|
|
72
|
-
if (
|
|
74
|
+
if (u)
|
|
73
75
|
return { status: "idle", data: null, error: null };
|
|
74
76
|
if (t.has(r))
|
|
75
77
|
try {
|
|
76
78
|
return { status: "ready", data: t.read(r), error: null };
|
|
77
|
-
} catch (
|
|
79
|
+
} catch (s) {
|
|
78
80
|
return {
|
|
79
81
|
status: "not-found",
|
|
80
82
|
data: null,
|
|
81
|
-
error:
|
|
83
|
+
error: s instanceof Error ? s : new Error(String(s))
|
|
82
84
|
};
|
|
83
85
|
}
|
|
84
|
-
return Promise.resolve(t.resolve(r,
|
|
86
|
+
return Promise.resolve(t.resolve(r, c)).catch(() => {
|
|
85
87
|
}), { status: "loading", data: null, error: null };
|
|
86
88
|
}
|
|
87
|
-
const
|
|
88
|
-
if (!
|
|
89
|
-
const
|
|
89
|
+
const I = typeof window < "u", Q = 3e3, h = /* @__PURE__ */ new Map(), p = (r, e) => {
|
|
90
|
+
if (!I) {
|
|
91
|
+
const d = () => {
|
|
90
92
|
};
|
|
91
|
-
return
|
|
93
|
+
return d.loaded = Promise.resolve(), d;
|
|
92
94
|
}
|
|
93
95
|
const n = h.get(e);
|
|
94
96
|
if (n) {
|
|
95
97
|
n.refCount += 1;
|
|
96
|
-
const
|
|
98
|
+
const d = () => {
|
|
97
99
|
n.refCount -= 1, n.refCount === 0 && (n.clearReadyTimer(), n.linkEl.remove(), h.delete(e));
|
|
98
100
|
};
|
|
99
|
-
return
|
|
101
|
+
return d.loaded = n.loaded, d;
|
|
100
102
|
}
|
|
101
103
|
const t = document.createElement("link");
|
|
102
104
|
t.rel = "stylesheet", t.href = r, t.setAttribute("data-fragment-key", e);
|
|
103
|
-
let
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
}),
|
|
107
|
-
|
|
108
|
-
},
|
|
109
|
-
t.addEventListener("load",
|
|
110
|
-
const o = { refCount: 1, linkEl: t, loaded:
|
|
105
|
+
let l;
|
|
106
|
+
const u = new Promise((d) => {
|
|
107
|
+
l = d;
|
|
108
|
+
}), c = () => {
|
|
109
|
+
s(), l();
|
|
110
|
+
}, m = setTimeout(c, Q), s = () => clearTimeout(m);
|
|
111
|
+
t.addEventListener("load", c), t.addEventListener("error", c), document.head.appendChild(t);
|
|
112
|
+
const o = { refCount: 1, linkEl: t, loaded: u, clearReadyTimer: s };
|
|
111
113
|
h.set(e, o);
|
|
112
|
-
const
|
|
114
|
+
const i = () => {
|
|
113
115
|
o.refCount -= 1, o.refCount === 0 && (o.clearReadyTimer(), o.linkEl.remove(), h.delete(e));
|
|
114
116
|
};
|
|
115
|
-
return
|
|
116
|
-
},
|
|
117
|
-
function
|
|
118
|
-
|
|
117
|
+
return i.loaded = u, i;
|
|
118
|
+
}, W = I ? b : S;
|
|
119
|
+
function X(r, e) {
|
|
120
|
+
W(() => p(r, e), [r, e]);
|
|
119
121
|
}
|
|
120
|
-
const
|
|
121
|
-
function
|
|
122
|
+
const Z = parseInt(O.split(".")[0], 10), ee = Z >= 19;
|
|
123
|
+
function P({
|
|
122
124
|
href: r,
|
|
123
125
|
fragmentKey: e
|
|
124
126
|
}) {
|
|
125
|
-
return
|
|
127
|
+
return ee ? /* @__PURE__ */ a(
|
|
126
128
|
"link",
|
|
127
129
|
{
|
|
128
130
|
rel: "stylesheet",
|
|
@@ -130,13 +132,13 @@ function E({
|
|
|
130
132
|
precedence: "default",
|
|
131
133
|
"data-fragment-key": e
|
|
132
134
|
}
|
|
133
|
-
) : (
|
|
135
|
+
) : (X(r, e), null);
|
|
134
136
|
}
|
|
135
|
-
function
|
|
137
|
+
function se(r) {
|
|
136
138
|
}
|
|
137
|
-
const R = {},
|
|
138
|
-
|
|
139
|
-
class T extends
|
|
139
|
+
const R = {}, y = v(null);
|
|
140
|
+
y.displayName = "ProjectPropertiesContext";
|
|
141
|
+
class T extends B {
|
|
140
142
|
constructor() {
|
|
141
143
|
super(...arguments), this.state = { hasError: !1 };
|
|
142
144
|
}
|
|
@@ -144,108 +146,134 @@ class T extends b {
|
|
|
144
146
|
return { hasError: !0 };
|
|
145
147
|
}
|
|
146
148
|
componentDidCatch(e, n) {
|
|
147
|
-
var t,
|
|
148
|
-
process.env.NODE_ENV !== "production" && console.error("[fragments] Area error:", e, n.componentStack), (
|
|
149
|
+
var t, l;
|
|
150
|
+
process.env.NODE_ENV !== "production" && console.error("[fragments] Area error:", e, n.componentStack), (l = (t = this.props).onError) == null || l.call(t, e);
|
|
149
151
|
}
|
|
150
152
|
render() {
|
|
151
153
|
return this.state.hasError ? null : this.props.children;
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
|
-
|
|
156
|
+
function j(r, e) {
|
|
157
|
+
if (!r) return {};
|
|
158
|
+
const n = {};
|
|
159
|
+
for (const t of Object.keys(r))
|
|
160
|
+
n[t] = re(r[t], e);
|
|
161
|
+
return n;
|
|
162
|
+
}
|
|
163
|
+
function re(r, e) {
|
|
164
|
+
return Array.isArray(r) ? r.map((n, t) => n === null ? null : F(n, e, t)) : F(r, e);
|
|
165
|
+
}
|
|
166
|
+
function F(r, e, n) {
|
|
167
|
+
let t;
|
|
168
|
+
try {
|
|
169
|
+
t = e(r.fragmentId);
|
|
170
|
+
} catch (u) {
|
|
171
|
+
if (u != null && typeof u.then == "function")
|
|
172
|
+
throw u;
|
|
173
|
+
return console.warn(`[FragmentRenderer] Slot fragment ${r.fragmentId} failed to load — rendering empty hole`, u), null;
|
|
174
|
+
}
|
|
175
|
+
const l = j(r.slots, e);
|
|
176
|
+
return D(t, { key: n, ...r.props, ...l });
|
|
177
|
+
}
|
|
178
|
+
const N = ({
|
|
155
179
|
fragmentId: r,
|
|
156
180
|
props: e,
|
|
157
181
|
globalCssUrl: n = null,
|
|
158
|
-
projectProperties: t = R
|
|
182
|
+
projectProperties: t = R,
|
|
183
|
+
fragments: l = [r],
|
|
184
|
+
slots: u
|
|
159
185
|
}) => {
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
186
|
+
const c = z(r), m = f(g);
|
|
187
|
+
if (!m)
|
|
188
|
+
throw new Error("[FragmentRendererInner] No ModulesMapProvider in tree");
|
|
189
|
+
const s = j(u, m.read), o = { ...e ?? {}, ...s }, i = l.length > 0 ? l.map($).join(" ") : void 0;
|
|
190
|
+
return /* @__PURE__ */ _(k, { children: [
|
|
191
|
+
n != null && /* @__PURE__ */ a(
|
|
192
|
+
P,
|
|
164
193
|
{
|
|
165
194
|
href: n,
|
|
166
|
-
fragmentKey:
|
|
167
|
-
}
|
|
168
|
-
),
|
|
169
|
-
u && /* @__PURE__ */ l(
|
|
170
|
-
E,
|
|
171
|
-
{
|
|
172
|
-
href: u.cssUrl,
|
|
173
|
-
fragmentKey: O(r)
|
|
195
|
+
fragmentKey: U
|
|
174
196
|
}
|
|
175
197
|
),
|
|
176
|
-
(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
198
|
+
l.map((d) => {
|
|
199
|
+
const C = V(d);
|
|
200
|
+
return C ? /* @__PURE__ */ a(
|
|
201
|
+
P,
|
|
202
|
+
{
|
|
203
|
+
href: C,
|
|
204
|
+
fragmentKey: G(d)
|
|
205
|
+
},
|
|
206
|
+
d
|
|
207
|
+
) : null;
|
|
208
|
+
}),
|
|
209
|
+
/* @__PURE__ */ a(y.Provider, { value: t, children: /* @__PURE__ */ a(M.Provider, { value: null, children: /* @__PURE__ */ a(
|
|
184
210
|
"div",
|
|
185
211
|
{
|
|
186
|
-
className:
|
|
212
|
+
className: i,
|
|
187
213
|
style: { display: "contents" },
|
|
188
|
-
children: /* @__PURE__ */
|
|
214
|
+
children: /* @__PURE__ */ a(c, { ...o })
|
|
189
215
|
}
|
|
190
216
|
) }) })
|
|
191
217
|
] });
|
|
192
|
-
},
|
|
218
|
+
}, ce = ({ onError: r, ...e }) => /* @__PURE__ */ a(w, { fallback: null, children: /* @__PURE__ */ a(T, { onError: r, children: /* @__PURE__ */ a(N, { ...e }) }) }), te = ({ areaCode: r, options: e }) => {
|
|
193
219
|
if ((e == null ? void 0 : e.pause) === !0)
|
|
194
220
|
return null;
|
|
195
|
-
const n =
|
|
221
|
+
const n = q(r, {
|
|
196
222
|
timeout: e == null ? void 0 : e.timeout,
|
|
197
223
|
ssr: e == null ? void 0 : e.ssr
|
|
198
224
|
});
|
|
199
225
|
if (n === x)
|
|
200
226
|
return null;
|
|
201
|
-
const { rootFragmentId: t, props:
|
|
202
|
-
return /* @__PURE__ */
|
|
203
|
-
|
|
227
|
+
const { rootFragmentId: t, props: l, projectProperties: u, globalCssUrl: c, fragments: m, slots: s } = n, o = typeof (e == null ? void 0 : e.props) == "function" ? e.props(l) : e != null && e.props ? { ...l, ...e.props } : l;
|
|
228
|
+
return /* @__PURE__ */ a(
|
|
229
|
+
N,
|
|
204
230
|
{
|
|
205
231
|
fragmentId: t,
|
|
206
|
-
props:
|
|
207
|
-
globalCssUrl:
|
|
208
|
-
projectProperties:
|
|
232
|
+
props: o,
|
|
233
|
+
globalCssUrl: c,
|
|
234
|
+
projectProperties: u,
|
|
235
|
+
fragments: m,
|
|
236
|
+
slots: s
|
|
209
237
|
}
|
|
210
238
|
);
|
|
211
|
-
},
|
|
212
|
-
function
|
|
213
|
-
const n =
|
|
239
|
+
}, oe = ({ areaCode: r, options: e }) => /* @__PURE__ */ a(w, { fallback: (e == null ? void 0 : e.fallback) ?? null, children: /* @__PURE__ */ a(T, { onError: e == null ? void 0 : e.onError, children: /* @__PURE__ */ a(te, { areaCode: r, options: e }) }) });
|
|
240
|
+
function de({ client: r, children: e }) {
|
|
241
|
+
const n = A(
|
|
214
242
|
() => ({
|
|
215
243
|
read: (t) => r.$fragments.read(t)
|
|
216
244
|
}),
|
|
217
245
|
[r]
|
|
218
246
|
);
|
|
219
|
-
return /* @__PURE__ */
|
|
247
|
+
return /* @__PURE__ */ a(Y, { value: r, children: /* @__PURE__ */ a(H, { value: n, children: e }) });
|
|
220
248
|
}
|
|
221
|
-
function
|
|
222
|
-
return (f(
|
|
249
|
+
function me(r) {
|
|
250
|
+
return (f(y) ?? R)[r];
|
|
223
251
|
}
|
|
224
|
-
function
|
|
225
|
-
return
|
|
252
|
+
function fe(r) {
|
|
253
|
+
return K({ ...r, inject: p });
|
|
226
254
|
}
|
|
227
255
|
export {
|
|
228
256
|
x as AREA_UNRESOLVED,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
257
|
+
oe as Area,
|
|
258
|
+
ce as FragmentRenderer,
|
|
259
|
+
P as FragmentStylesheet,
|
|
260
|
+
ve as FragmentsApiVersionError,
|
|
261
|
+
Ee as FragmentsAreaError,
|
|
262
|
+
E as FragmentsClientContext,
|
|
263
|
+
Y as FragmentsClientProvider,
|
|
264
|
+
ge as FragmentsLoadError,
|
|
265
|
+
de as FragmentsProvider,
|
|
266
|
+
M as InstanceIdContext,
|
|
239
267
|
g as ModulesMapContext,
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
268
|
+
H as ModulesMapProvider,
|
|
269
|
+
y as ProjectPropertiesContext,
|
|
270
|
+
fe as createBrowserClient,
|
|
243
271
|
R as defaultProjectProperties,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
272
|
+
p as injectStylesheet,
|
|
273
|
+
q as useArea,
|
|
274
|
+
se as useCssChunk,
|
|
275
|
+
z as useFragmentComponent,
|
|
276
|
+
ue as useFragmentMetrics,
|
|
277
|
+
X as useFragmentStylesheet,
|
|
278
|
+
me as useProjectProperty
|
|
251
279
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(l,u){typeof exports=="object"&&typeof module<"u"?u(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"],u):(l=typeof globalThis<"u"?globalThis:l||self,u(l.FragmentsRuntimeReact={},l.jsxRuntime,l.React,l.fragmentsClient))})(this,function(l,u,a,m){"use strict";const g=a.createContext(null);g.displayName="FragmentsClientContext";function j(r){return u.jsx(g.Provider,{value:r.value,children:r.children})}const P=a.createContext(null);P.displayName="InstanceIdContext";const E=a.createContext(null);E.displayName="ModulesMapContext";function w({value:r,children:e}){return u.jsx(E.Provider,{value:r,children:e})}function p(){const r=a.useContext(g);return a.useMemo(()=>({reachGoal:e=>{var n,t;(t=(n=r==null?void 0:r.$metrics)==null?void 0:n.reachGoal)==null||t.call(n,e)}}),[r])}function I(r){const e=a.useContext(E);if(!e)throw new Error("[useFragmentComponent] No ModulesMapProvider in tree");return e.read(r)}const B=typeof window<"u",F=Object.freeze({rootFragmentId:0,variantId:null,props:{},projectProperties:{},globalCssUrl:null,fragments:[],slots:{}});function T(r,e){const n=a.useContext(g);if(!n)throw new Error("[useArea] No FragmentsClientProvider in tree");const t=n.$area;if(!(t!=null&&t.read))throw new Error("[useArea] $area plugin not mounted");const s=(e==null?void 0:e.suspense)??!0,c=(e==null?void 0:e.pause)===!0||!B&&(e==null?void 0:e.ssr)===!1,d=(e==null?void 0:e.timeout)!=null?{timeout:e.timeout}:void 0,[,h]=a.useState(0);if(a.useEffect(()=>{if(s||c)return;let o=!0;return Promise.resolve(t.resolve(r,d)).catch(()=>{}).finally(()=>{o&&h(f=>f+1)}),()=>{o=!1}},[r,s,e==null?void 0:e.pause,e==null?void 0:e.timeout,e==null?void 0:e.ssr]),s)return c?F:(t.has(r)||Promise.resolve(t.resolve(r,d)).catch(()=>{}),t.read(r));if(c)return{status:"idle",data:null,error:null};if(t.has(r))try{return{status:"ready",data:t.read(r),error:null}}catch(o){return{status:"not-found",data:null,error:o instanceof Error?o:new Error(String(o))}}return Promise.resolve(t.resolve(r,d)).catch(()=>{}),{status:"loading",data:null,error:null}}const _=typeof window<"u",D=3e3,v=new Map,A=(r,e)=>{if(!_){const i=()=>{};return i.loaded=Promise.resolve(),i}const n=v.get(e);if(n){n.refCount+=1;const i=()=>{n.refCount-=1,n.refCount===0&&(n.clearReadyTimer(),n.linkEl.remove(),v.delete(e))};return i.loaded=n.loaded,i}const t=document.createElement("link");t.rel="stylesheet",t.href=r,t.setAttribute("data-fragment-key",e);let s;const c=new Promise(i=>{s=i}),d=()=>{o(),s()},h=setTimeout(d,D),o=()=>clearTimeout(h);t.addEventListener("load",d),t.addEventListener("error",d),document.head.appendChild(t);const f={refCount:1,linkEl:t,loaded:c,clearReadyTimer:o};v.set(e,f);const C=()=>{f.refCount-=1,f.refCount===0&&(f.clearReadyTimer(),f.linkEl.remove(),v.delete(e))};return C.loaded=c,C},V=_?a.useLayoutEffect:a.useEffect;function b(r,e){V(()=>A(r,e),[r,e])}const R=parseInt(a.version.split(".")[0],10)>=19;function S({href:r,fragmentKey:e}){return R?u.jsx("link",{rel:"stylesheet",href:r,precedence:"default","data-fragment-key":e}):(b(r,e),null)}function U(r){}const M={},y=a.createContext(null);y.displayName="ProjectPropertiesContext";class N extends a.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,n){var t,s;process.env.NODE_ENV!=="production"&&console.error("[fragments] Area error:",e,n.componentStack),(s=(t=this.props).onError)==null||s.call(t,e)}render(){return this.state.hasError?null:this.props.children}}function O(r,e){if(!r)return{};const n={};for(const t of Object.keys(r))n[t]=$(r[t],e);return n}function $(r,e){return Array.isArray(r)?r.map((n,t)=>n===null?null:L(n,e,t)):L(r,e)}function L(r,e,n){let t;try{t=e(r.fragmentId)}catch(c){if(c!=null&&typeof c.then=="function")throw c;return console.warn(`[FragmentRenderer] Slot fragment ${r.fragmentId} failed to load — rendering empty hole`,c),null}const s=O(r.slots,e);return a.createElement(t,{key:n,...r.props,...s})}const k=({fragmentId:r,props:e,globalCssUrl:n=null,projectProperties:t=M,fragments:s=[r],slots:c})=>{const d=I(r),h=a.useContext(E);if(!h)throw new Error("[FragmentRendererInner] No ModulesMapProvider in tree");const o=O(c,h.read),f={...e??{},...o},C=s.length>0?s.map(m.toScopeClassName).join(" "):void 0;return u.jsxs(u.Fragment,{children:[n!=null&&u.jsx(S,{href:n,fragmentKey:m.AREA_GLOBAL_CSS_KEY}),s.map(i=>{const x=m.resolveStylesHref(i);return x?u.jsx(S,{href:x,fragmentKey:m.fragmentCssKey(i)},i):null}),u.jsx(y.Provider,{value:t,children:u.jsx(P.Provider,{value:null,children:u.jsx("div",{className:C,style:{display:"contents"},children:u.jsx(d,{...f})})})})]})},q=({onError:r,...e})=>u.jsx(a.Suspense,{fallback:null,children:u.jsx(N,{onError:r,children:u.jsx(k,{...e})})}),G=({areaCode:r,options:e})=>{if((e==null?void 0:e.pause)===!0)return null;const n=T(r,{timeout:e==null?void 0:e.timeout,ssr:e==null?void 0:e.ssr});if(n===F)return null;const{rootFragmentId:t,props:s,projectProperties:c,globalCssUrl:d,fragments:h,slots:o}=n,f=typeof(e==null?void 0:e.props)=="function"?e.props(s):e!=null&&e.props?{...s,...e.props}:s;return u.jsx(k,{fragmentId:t,props:f,globalCssUrl:d,projectProperties:c,fragments:h,slots:o})},K=({areaCode:r,options:e})=>u.jsx(a.Suspense,{fallback:(e==null?void 0:e.fallback)??null,children:u.jsx(N,{onError:e==null?void 0:e.onError,children:u.jsx(G,{areaCode:r,options:e})})});function Y({client:r,children:e}){const n=a.useMemo(()=>({read:t=>r.$fragments.read(t)}),[r]);return u.jsx(j,{value:r,children:u.jsx(w,{value:n,children:e})})}function H(r){return(a.useContext(y)??M)[r]}function J(r){return m.createFragmentsClient({...r,inject:A})}Object.defineProperty(l,"FragmentsApiVersionError",{enumerable:!0,get:()=>m.FragmentsApiVersionError}),Object.defineProperty(l,"FragmentsAreaError",{enumerable:!0,get:()=>m.FragmentsAreaError}),Object.defineProperty(l,"FragmentsLoadError",{enumerable:!0,get:()=>m.FragmentsLoadError}),l.AREA_UNRESOLVED=F,l.Area=K,l.FragmentRenderer=q,l.FragmentStylesheet=S,l.FragmentsClientContext=g,l.FragmentsClientProvider=j,l.FragmentsProvider=Y,l.InstanceIdContext=P,l.ModulesMapContext=E,l.ModulesMapProvider=w,l.ProjectPropertiesContext=y,l.createBrowserClient=J,l.defaultProjectProperties=M,l.injectStylesheet=A,l.useArea=T,l.useCssChunk=U,l.useFragmentComponent=I,l.useFragmentMetrics=p,l.useFragmentStylesheet=b,l.useProjectProperty=H,Object.defineProperty(l,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-20260922090625",
|
|
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-20260922090625"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@testing-library/jest-dom": "^6.6.3",
|