@fulgurjs/federation 5.2.5 → 5.3.1
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/CHANGELOG.md +23 -0
- package/DESIGN.md +7 -0
- package/README.en.md +86 -4
- package/README.md +125 -3
- package/dist/bridge-app-react.cjs +185 -0
- package/dist/bridge-app-react.d.cts +37 -0
- package/dist/bridge-app-react.d.ts +37 -0
- package/dist/bridge-app-react.js +115 -0
- package/dist/bridge-app-vue.cjs +111 -0
- package/dist/bridge-app-vue.d.cts +34 -0
- package/dist/bridge-app-vue.d.ts +34 -0
- package/dist/bridge-app-vue.js +51 -0
- package/dist/bridge-core-6uLJiMVa.d.ts +42 -0
- package/dist/bridge-core.cjs +232 -0
- package/dist/bridge-core.d.cts +51 -0
- package/dist/bridge-core.d.ts +51 -0
- package/dist/bridge-core.js +21 -0
- package/dist/bridge-errors.cjs +114 -0
- package/dist/bridge-errors.d.cts +36 -0
- package/dist/bridge-errors.d.ts +36 -0
- package/dist/bridge-errors.js +15 -0
- package/dist/bridge-host-react-C55RmGll.d.ts +35 -0
- package/dist/bridge-host-react.cjs +400 -0
- package/dist/bridge-host-react.d.cts +45 -0
- package/dist/bridge-host-react.d.ts +45 -0
- package/dist/bridge-host-react.js +183 -0
- package/dist/bridge-host-vue-BAxDKqGH.d.ts +32 -0
- package/dist/bridge-host-vue.cjs +437 -0
- package/dist/bridge-host-vue.d.cts +39 -0
- package/dist/bridge-host-vue.d.ts +39 -0
- package/dist/bridge-host-vue.js +214 -0
- package/dist/bridge-react.d.ts +12 -0
- package/dist/bridge-react.js +3 -0
- package/dist/bridge-vue.d.ts +8 -0
- package/dist/bridge-vue.js +3 -0
- package/dist/bridge.d.ts +16 -0
- package/dist/bridge.js +5 -0
- package/dist/chunk-DH2QMM4Y.js +76 -0
- package/dist/chunk-LE2G23E7.js +122 -0
- package/dist/chunk-MMXKQN2H.js +210 -0
- package/dist/chunk-OF2JCXTZ.js +15 -0
- package/dist/chunk-TOT3P7AK.js +1229 -0
- package/dist/chunk-TSYLDY6H.js +64 -0
- package/dist/chunk-X4F2BHNM.js +179 -0
- package/dist/context.js +8 -64
- package/dist/index.cjs +139 -13
- package/dist/index.js +139 -13
- package/dist/react.d.ts +47 -2
- package/dist/react.js +2 -0
- package/dist/runtime-entry.d.ts +44 -2
- package/dist/runtime-entry.js +1 -1
- package/dist/runtime.js +19 -19
- package/dist/vue.js +2 -0
- package/docs/webpack-mf-/345/257/271/347/205/247/344/270/216/347/274/272/345/217/243.md +1 -1
- package/docs//350/277/201/347/247/273/346/214/207/345/215/227.md +1 -1
- package/examples/README.en.md +20 -0
- package/examples/README.md +20 -0
- package/examples/bridge/README.md +36 -0
- package/examples/bridge/react-host/README.md +23 -0
- package/examples/bridge/react-host/fulgurjs.config.ts +20 -0
- package/examples/bridge/react-host/index.html +11 -0
- package/examples/bridge/react-host/package-lock.json +2457 -0
- package/examples/bridge/react-host/package.json +24 -0
- package/examples/bridge/react-host/src/env.d.ts +7 -0
- package/examples/bridge/react-host/src/host-session.ts +26 -0
- package/examples/bridge/react-host/src/main.tsx +62 -0
- package/examples/bridge/react-host/tsconfig.json +13 -0
- package/examples/bridge/react-host/vite.config.ts +9 -0
- package/examples/bridge/react-remote/README.md +20 -0
- package/examples/bridge/react-remote/fulgurjs.config.ts +17 -0
- package/examples/bridge/react-remote/index.html +11 -0
- package/examples/bridge/react-remote/package-lock.json +2382 -0
- package/examples/bridge/react-remote/package.json +24 -0
- package/examples/bridge/react-remote/src/bridge.tsx +66 -0
- package/examples/bridge/react-remote/src/env.d.ts +7 -0
- package/examples/bridge/react-remote/src/main.tsx +7 -0
- package/examples/bridge/react-remote/tsconfig.json +13 -0
- package/examples/bridge/react-remote/vite.config.ts +9 -0
- package/examples/bridge/vue-host/README.md +24 -0
- package/examples/bridge/vue-host/fulgurjs.config.ts +22 -0
- package/examples/bridge/vue-host/index.html +11 -0
- package/examples/bridge/vue-host/package-lock.json +1885 -0
- package/examples/bridge/vue-host/package.json +24 -0
- package/examples/bridge/vue-host/src/App.vue +70 -0
- package/examples/bridge/vue-host/src/env.d.ts +7 -0
- package/examples/bridge/vue-host/src/host-session.ts +29 -0
- package/examples/bridge/vue-host/src/main.ts +4 -0
- package/examples/bridge/vue-host/tsconfig.json +13 -0
- package/examples/bridge/vue-host/vite.config.ts +9 -0
- package/examples/bridge/vue-remote/README.md +19 -0
- package/examples/bridge/vue-remote/fulgurjs.config.ts +16 -0
- package/examples/bridge/vue-remote/index.html +11 -0
- package/examples/bridge/vue-remote/package-lock.json +1856 -0
- package/examples/bridge/vue-remote/package.json +21 -0
- package/examples/bridge/vue-remote/src/App.vue +12 -0
- package/examples/bridge/vue-remote/src/bridge.ts +57 -0
- package/examples/bridge/vue-remote/src/env.d.ts +7 -0
- package/examples/bridge/vue-remote/src/main.ts +15 -0
- package/examples/bridge/vue-remote/tsconfig.json +13 -0
- package/examples/bridge/vue-remote/vite.config.ts +9 -0
- package/package.json +43 -2
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FgError
|
|
3
|
+
} from "./chunk-OF2JCXTZ.js";
|
|
4
|
+
|
|
5
|
+
// src/context.ts
|
|
6
|
+
var ContextErrorCodes = {
|
|
7
|
+
/** context 必需字段缺失(三段式,修法指向宿主桥) */
|
|
8
|
+
CONTEXT_MISSING_KEY: "CC-001",
|
|
9
|
+
/** 运行时单例不可用(独立直开远程页,修法=经宿主联邦加载) */
|
|
10
|
+
CONTEXT_NO_RUNTIME: "CC-002"
|
|
11
|
+
};
|
|
12
|
+
var APP_CONTEXT_STORAGE_KEY = "__FULGURJS_APP_CONFIG__";
|
|
13
|
+
function requireRuntime() {
|
|
14
|
+
const rt = globalThis.__FULGURJS_RUNTIME__;
|
|
15
|
+
if (!rt || typeof rt.loadRemote !== "function") {
|
|
16
|
+
throw new FgError(
|
|
17
|
+
ContextErrorCodes.CONTEXT_NO_RUNTIME,
|
|
18
|
+
"\u73B0\u8C61\uFF1A\u5F53\u524D\u9875\u9762\u627E\u4E0D\u5230 fulgurjs \u8FD0\u884C\u65F6\u5355\u4F8B\uFF08globalThis.__FULGURJS_RUNTIME__ \u672A\u5B9A\u4E49\uFF09\u3002\n \u6839\u56E0: \u5F53\u524D\u9875\u9762\u6CA1\u6709\u7ECF\u5BBF\u4E3B\u7684\u8054\u90A6\u8FD0\u884C\u65F6\u52A0\u8F7D\uFF08\u72EC\u7ACB\u76F4\u5F00\u8FDC\u7A0B\u9875\uFF0C\u6216\u5BBF\u4E3B\u6865\u665A\u4E8E\u672C\u8C03\u7528\u6267\u884C\uFF09\u3002\n \u4FEE\u6CD5: \u2460 \u4ECE\u5BBF\u4E3B\u5E94\u7528\u7684\u8054\u90A6\u8DEF\u7531\u6253\u5F00\u672C\u9875\u9762\uFF08\u5BBF\u4E3B\u6865\u4F1A\u5148\u52A0\u8F7D\u8FD0\u884C\u65F6\u5E76\u63D0\u4F9B context\uFF09\uFF1B\n \u2461 \u82E5\u4F60\u662F\u5BBF\u4E3B\u6865\u4F5C\u8005\uFF1A\u628A provideAppContext \u653E\u5728\u6865\u521D\u59CB\u5316\u5C3E\u90E8\uFF08\u65F6\u5E8F\u5951\u7EA6 bridge \u2192 \u8FDC\u7A0B setup \u2192 \u9875\u9762\u6A21\u5757\uFF09\u3002",
|
|
19
|
+
{ runtime: false }
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return rt;
|
|
23
|
+
}
|
|
24
|
+
function provideAppContext(config) {
|
|
25
|
+
requireRuntime();
|
|
26
|
+
const g = globalThis;
|
|
27
|
+
g[APP_CONTEXT_STORAGE_KEY] = { ...g[APP_CONTEXT_STORAGE_KEY] ?? {}, ...config };
|
|
28
|
+
}
|
|
29
|
+
function clearAppContext() {
|
|
30
|
+
const g = globalThis;
|
|
31
|
+
delete g[APP_CONTEXT_STORAGE_KEY];
|
|
32
|
+
try {
|
|
33
|
+
g.__FULGURJS_RUNTIME__?.clearSessionState?.();
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function getAppContext() {
|
|
38
|
+
requireRuntime();
|
|
39
|
+
return globalThis[APP_CONTEXT_STORAGE_KEY] ?? {};
|
|
40
|
+
}
|
|
41
|
+
function requireAppContext(...keys) {
|
|
42
|
+
const ctx = getAppContext();
|
|
43
|
+
const missing = keys.filter((k) => ctx[k] === void 0);
|
|
44
|
+
if (missing.length === 0) return ctx;
|
|
45
|
+
const got = Object.keys(ctx);
|
|
46
|
+
const err = new FgError(
|
|
47
|
+
ContextErrorCodes.CONTEXT_MISSING_KEY,
|
|
48
|
+
`\u73B0\u8C61\uFF1AAppContext \u7F3A\u5C11\u5FC5\u9700\u5B57\u6BB5 ${missing.map((k) => `"${k}"`).join("\u3001")}\u3002
|
|
49
|
+
\u5F53\u524D\u5B57\u6BB5\uFF1A${got.length ? got.map((k) => `"${k}"`).join("\u3001") : "\u7A7A\uFF08\u5BBF\u4E3B\u6865\u53EF\u80FD\u5C1A\u672A\u8C03\u7528 provideAppContext\uFF09"}\u3002
|
|
50
|
+
\u9884\u671F\uFF1A\u5BBF\u4E3B\u6865\u5E94\u5728\u8FDC\u7A0B\u9875\u9762\u52A0\u8F7D\u524D\u63D0\u4F9B ${missing.map((k) => `"${k}"`).join("\u3001")}\u3002
|
|
51
|
+
\u793A\u4F8B\uFF1Ahost/src/fulgurjs/host/bridge.ts \u2192 provideAppContext({ ${keys.join(", ")}, ... })
|
|
52
|
+
\u4FEE\u6CD5: \u68C0\u67E5\u5BBF\u4E3B\u5E94\u7528\u7684 fulgurjs \u6865\u662F\u5426\u5728 loadRemote \u9875\u9762\u524D\u5B8C\u6210 context provide\uFF08\u65F6\u5E8F\u5951\u7EA6 bridge \u2192 \u8FDC\u7A0B setup \u2192 \u9875\u9762\u6A21\u5757\uFF09`,
|
|
53
|
+
{ missing, got }
|
|
54
|
+
);
|
|
55
|
+
throw err;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
ContextErrorCodes,
|
|
60
|
+
provideAppContext,
|
|
61
|
+
clearAppContext,
|
|
62
|
+
getAppContext,
|
|
63
|
+
requireAppContext
|
|
64
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
acquireBridgeSession,
|
|
3
|
+
assertBridgeContract,
|
|
4
|
+
assertBridgeOptions,
|
|
5
|
+
assertControlledSessionKey,
|
|
6
|
+
bridgeLifecycleError,
|
|
7
|
+
provideAppContext,
|
|
8
|
+
releaseBridgeSession,
|
|
9
|
+
resolveBridgeContext,
|
|
10
|
+
withBridgeTimeout
|
|
11
|
+
} from "./chunk-TOT3P7AK.js";
|
|
12
|
+
|
|
13
|
+
// src/bridge-host-react.ts
|
|
14
|
+
import {
|
|
15
|
+
createElement,
|
|
16
|
+
Fragment,
|
|
17
|
+
useEffect,
|
|
18
|
+
useRef,
|
|
19
|
+
useState
|
|
20
|
+
} from "react";
|
|
21
|
+
var ERROR_STYLE = {
|
|
22
|
+
padding: "16px",
|
|
23
|
+
border: "1px solid #fde2e2",
|
|
24
|
+
borderRadius: "4px",
|
|
25
|
+
background: "#fef0f0",
|
|
26
|
+
color: "#c45656",
|
|
27
|
+
fontSize: "13px",
|
|
28
|
+
lineHeight: "1.6",
|
|
29
|
+
boxSizing: "border-box"
|
|
30
|
+
};
|
|
31
|
+
var MESSAGE_STYLE = { margin: "0 0 8px", wordBreak: "break-all" };
|
|
32
|
+
var BUTTON_STYLE = {
|
|
33
|
+
padding: "4px 14px",
|
|
34
|
+
marginRight: "8px",
|
|
35
|
+
border: "1px solid #c45656",
|
|
36
|
+
borderRadius: "4px",
|
|
37
|
+
background: "#c45656",
|
|
38
|
+
color: "#fff",
|
|
39
|
+
fontSize: "13px",
|
|
40
|
+
cursor: "pointer"
|
|
41
|
+
};
|
|
42
|
+
var SECONDARY_BUTTON_STYLE = {
|
|
43
|
+
padding: "4px 14px",
|
|
44
|
+
border: "1px solid #c45656",
|
|
45
|
+
borderRadius: "4px",
|
|
46
|
+
background: "#fff",
|
|
47
|
+
color: "#c45656",
|
|
48
|
+
fontSize: "13px",
|
|
49
|
+
cursor: "pointer"
|
|
50
|
+
};
|
|
51
|
+
function DefaultBridgeErrorView({ error, retry, blocked }) {
|
|
52
|
+
const err = error;
|
|
53
|
+
const code = err?.code ?? "UNKNOWN";
|
|
54
|
+
const message = err?.message ?? String(error ?? "unknown error");
|
|
55
|
+
return createElement("div", { style: ERROR_STYLE, "data-fulgurjs-error": code }, [
|
|
56
|
+
createElement("p", { key: "t", style: { margin: "0 0 4px", fontWeight: 600 } }, `\u6865\u63A5\u5E94\u7528\u52A0\u8F7D\u5931\u8D25\uFF08\u9519\u8BEF\u7801 ${code}\uFF09`),
|
|
57
|
+
createElement("p", { key: "m", style: MESSAGE_STYLE }, message),
|
|
58
|
+
createElement(
|
|
59
|
+
"p",
|
|
60
|
+
{ key: "n", style: { margin: "0 0 10px" } },
|
|
61
|
+
blocked ? "\u8BE5\u5BB9\u5668\u5DF2\u5C01\u9501\uFF08\u540C\u9875\u65E0\u6CD5\u5B89\u5168\u91CD\u6302\uFF09\uFF0C\u53EA\u80FD\u6574\u9875\u5237\u65B0\u6062\u590D\u2014\u2014\u70B9\u51FB\u300C\u5237\u65B0\u9875\u9762\u91CD\u8BD5\u300D\u4F1A\u91CD\u65B0\u52A0\u8F7D\u9875\u9762\uFF08\u4FDD\u7559\u5F53\u524D\u5730\u5740\uFF09\uFF0C\u672A\u4FDD\u5B58\u7684\u9875\u9762\u72B6\u6001\u4F1A\u4E22\u5931\u3002" : "\u300C\u91CD\u8BD5\u52A0\u8F7D\u300D\u5728\u5F53\u524D\u9875\u9762\u91CD\u5EFA\u6302\u8F7D\uFF1B\u82E5\u6D4F\u89C8\u5668\u5DF2\u7F13\u5B58\u5931\u8D25\u7684\u6A21\u5757\uFF0C\u8BF7\u7528\u300C\u5237\u65B0\u9875\u9762\u91CD\u8BD5\u300D\u2014\u2014\u5B83\u4F1A\u6574\u9875\u5237\u65B0\uFF08\u4FDD\u7559\u5F53\u524D\u5730\u5740\uFF09\uFF0C\u672A\u4FDD\u5B58\u7684\u9875\u9762\u72B6\u6001\u4F1A\u4E22\u5931\u3002"
|
|
62
|
+
),
|
|
63
|
+
blocked ? null : createElement("button", { key: "r", type: "button", style: BUTTON_STYLE, "data-fulgurjs-retry": "", onClick: retry }, "\u91CD\u8BD5\u52A0\u8F7D"),
|
|
64
|
+
createElement("button", {
|
|
65
|
+
key: "rl",
|
|
66
|
+
type: "button",
|
|
67
|
+
style: SECONDARY_BUTTON_STYLE,
|
|
68
|
+
"data-fulgurjs-reload": "",
|
|
69
|
+
onClick: () => window.location.reload()
|
|
70
|
+
}, "\u5237\u65B0\u9875\u9762\u91CD\u8BD5")
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
function renderBridgeErrorNode(errorOpt, error, retry, blocked) {
|
|
74
|
+
if (typeof errorOpt === "function") return errorOpt(error, retry);
|
|
75
|
+
if (errorOpt !== void 0) return errorOpt;
|
|
76
|
+
return createElement(DefaultBridgeErrorView, { error, retry, blocked });
|
|
77
|
+
}
|
|
78
|
+
function createReactBridgeAppWithLoader(loadRemote) {
|
|
79
|
+
return function createReactBridgeApp(spec, options = {}) {
|
|
80
|
+
assertBridgeOptions(`createReactBridgeApp("${spec}")`, options);
|
|
81
|
+
const displayName = "FulgurjsBridge_" + spec.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
82
|
+
function BridgeHost(props) {
|
|
83
|
+
const [status, setStatus] = useState("idle");
|
|
84
|
+
const [error, setError] = useState(void 0);
|
|
85
|
+
const [attempt, setAttempt] = useState(0);
|
|
86
|
+
const containerRef = useRef(null);
|
|
87
|
+
const generationRef = useRef(0);
|
|
88
|
+
const contractRef = useRef(void 0);
|
|
89
|
+
const acquiredRef = useRef(void 0);
|
|
90
|
+
const blockedRef = useRef(false);
|
|
91
|
+
const latest = useRef(props);
|
|
92
|
+
latest.current = props;
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (blockedRef.current) return;
|
|
95
|
+
const myGen = ++generationRef.current;
|
|
96
|
+
const el = containerRef.current;
|
|
97
|
+
const release = () => {
|
|
98
|
+
if (acquiredRef.current !== void 0) {
|
|
99
|
+
releaseBridgeSession(acquiredRef.current);
|
|
100
|
+
acquiredRef.current = void 0;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const run = async () => {
|
|
104
|
+
if (!el) return;
|
|
105
|
+
const sk = latest.current.sessionKey;
|
|
106
|
+
setStatus("pending");
|
|
107
|
+
setError(void 0);
|
|
108
|
+
if (sk === null) {
|
|
109
|
+
setStatus("idle");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
assertControlledSessionKey(spec, sk);
|
|
114
|
+
const controlled = typeof sk === "string" ? sk : void 0;
|
|
115
|
+
if (controlled !== void 0 && controlled !== acquiredRef.current) {
|
|
116
|
+
release();
|
|
117
|
+
acquireBridgeSession(spec, controlled);
|
|
118
|
+
acquiredRef.current = controlled;
|
|
119
|
+
}
|
|
120
|
+
const resolution = resolveBridgeContext(spec, controlled, options.getContext);
|
|
121
|
+
if (resolution.provide) provideAppContext(resolution.provide);
|
|
122
|
+
const load = loadRemote(spec, { retries: options.retries });
|
|
123
|
+
const mod = options.timeout !== void 0 ? await withBridgeTimeout(load, options.timeout, spec) : await load;
|
|
124
|
+
if (generationRef.current !== myGen) return;
|
|
125
|
+
const contract = assertBridgeContract(spec, mod);
|
|
126
|
+
contractRef.current = contract;
|
|
127
|
+
await contract.mount(el, { ...latest.current.appProps ?? {} });
|
|
128
|
+
if (generationRef.current !== myGen) return;
|
|
129
|
+
setStatus("ready");
|
|
130
|
+
} catch (e) {
|
|
131
|
+
if (generationRef.current !== myGen) return;
|
|
132
|
+
setError(e);
|
|
133
|
+
setStatus("error");
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
void run();
|
|
137
|
+
return () => {
|
|
138
|
+
generationRef.current++;
|
|
139
|
+
release();
|
|
140
|
+
const c = contractRef.current;
|
|
141
|
+
contractRef.current = void 0;
|
|
142
|
+
if (c && el) {
|
|
143
|
+
try {
|
|
144
|
+
c.unmount(el);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
const err = bridgeLifecycleError("unmount", spec, e instanceof Error ? e : String(e));
|
|
147
|
+
console.error("[fulgurjs] \u6865\u63A5\u5E94\u7528\u5378\u8F7D\u5931\u8D25\uFF1A", err);
|
|
148
|
+
blockedRef.current = true;
|
|
149
|
+
setError(err);
|
|
150
|
+
setStatus("error");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}, [props.sessionKey, attempt]);
|
|
155
|
+
const retry = () => setAttempt((a) => a + 1);
|
|
156
|
+
const children = [];
|
|
157
|
+
if (status === "pending" && options.fallback !== void 0) {
|
|
158
|
+
children.push(createElement(Fragment, { key: "loading" }, options.fallback));
|
|
159
|
+
}
|
|
160
|
+
if (status === "error") {
|
|
161
|
+
children.push(createElement(Fragment, { key: "error" }, renderBridgeErrorNode(options.error, error, retry, blockedRef.current)));
|
|
162
|
+
}
|
|
163
|
+
children.push(createElement("div", {
|
|
164
|
+
key: "bridge-root",
|
|
165
|
+
ref: containerRef,
|
|
166
|
+
"data-fulgurjs-bridge-root": spec,
|
|
167
|
+
"data-fulgurjs-bridge-status": status
|
|
168
|
+
}));
|
|
169
|
+
return createElement(Fragment, null, children);
|
|
170
|
+
}
|
|
171
|
+
;
|
|
172
|
+
BridgeHost.displayName = displayName;
|
|
173
|
+
return BridgeHost;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export {
|
|
178
|
+
createReactBridgeAppWithLoader
|
|
179
|
+
};
|
package/dist/context.js
CHANGED
|
@@ -1,67 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.details = details;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// src/context.ts
|
|
14
|
-
var ContextErrorCodes = {
|
|
15
|
-
/** context 必需字段缺失(三段式,修法指向宿主桥) */
|
|
16
|
-
CONTEXT_MISSING_KEY: "CC-001",
|
|
17
|
-
/** 运行时单例不可用(独立直开远程页,修法=经宿主联邦加载) */
|
|
18
|
-
CONTEXT_NO_RUNTIME: "CC-002"
|
|
19
|
-
};
|
|
20
|
-
var APP_CONTEXT_STORAGE_KEY = "__FULGURJS_APP_CONFIG__";
|
|
21
|
-
function requireRuntime() {
|
|
22
|
-
const rt = globalThis.__FULGURJS_RUNTIME__;
|
|
23
|
-
if (!rt || typeof rt.loadRemote !== "function") {
|
|
24
|
-
throw new FgError(
|
|
25
|
-
ContextErrorCodes.CONTEXT_NO_RUNTIME,
|
|
26
|
-
"\u73B0\u8C61\uFF1A\u5F53\u524D\u9875\u9762\u627E\u4E0D\u5230 fulgurjs \u8FD0\u884C\u65F6\u5355\u4F8B\uFF08globalThis.__FULGURJS_RUNTIME__ \u672A\u5B9A\u4E49\uFF09\u3002\n \u6839\u56E0: \u5F53\u524D\u9875\u9762\u6CA1\u6709\u7ECF\u5BBF\u4E3B\u7684\u8054\u90A6\u8FD0\u884C\u65F6\u52A0\u8F7D\uFF08\u72EC\u7ACB\u76F4\u5F00\u8FDC\u7A0B\u9875\uFF0C\u6216\u5BBF\u4E3B\u6865\u665A\u4E8E\u672C\u8C03\u7528\u6267\u884C\uFF09\u3002\n \u4FEE\u6CD5: \u2460 \u4ECE\u5BBF\u4E3B\u5E94\u7528\u7684\u8054\u90A6\u8DEF\u7531\u6253\u5F00\u672C\u9875\u9762\uFF08\u5BBF\u4E3B\u6865\u4F1A\u5148\u52A0\u8F7D\u8FD0\u884C\u65F6\u5E76\u63D0\u4F9B context\uFF09\uFF1B\n \u2461 \u82E5\u4F60\u662F\u5BBF\u4E3B\u6865\u4F5C\u8005\uFF1A\u628A provideAppContext \u653E\u5728\u6865\u521D\u59CB\u5316\u5C3E\u90E8\uFF08\u65F6\u5E8F\u5951\u7EA6 bridge \u2192 \u8FDC\u7A0B setup \u2192 \u9875\u9762\u6A21\u5757\uFF09\u3002",
|
|
27
|
-
{ runtime: false }
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
return rt;
|
|
31
|
-
}
|
|
32
|
-
function provideAppContext(config) {
|
|
33
|
-
requireRuntime();
|
|
34
|
-
const g = globalThis;
|
|
35
|
-
g[APP_CONTEXT_STORAGE_KEY] = { ...g[APP_CONTEXT_STORAGE_KEY] ?? {}, ...config };
|
|
36
|
-
}
|
|
37
|
-
function clearAppContext() {
|
|
38
|
-
const g = globalThis;
|
|
39
|
-
delete g[APP_CONTEXT_STORAGE_KEY];
|
|
40
|
-
try {
|
|
41
|
-
g.__FULGURJS_RUNTIME__?.clearSessionState?.();
|
|
42
|
-
} catch {
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function getAppContext() {
|
|
46
|
-
requireRuntime();
|
|
47
|
-
return globalThis[APP_CONTEXT_STORAGE_KEY] ?? {};
|
|
48
|
-
}
|
|
49
|
-
function requireAppContext(...keys) {
|
|
50
|
-
const ctx = getAppContext();
|
|
51
|
-
const missing = keys.filter((k) => ctx[k] === void 0);
|
|
52
|
-
if (missing.length === 0) return ctx;
|
|
53
|
-
const got = Object.keys(ctx);
|
|
54
|
-
const err = new FgError(
|
|
55
|
-
ContextErrorCodes.CONTEXT_MISSING_KEY,
|
|
56
|
-
`\u73B0\u8C61\uFF1AAppContext \u7F3A\u5C11\u5FC5\u9700\u5B57\u6BB5 ${missing.map((k) => `"${k}"`).join("\u3001")}\u3002
|
|
57
|
-
\u5F53\u524D\u5B57\u6BB5\uFF1A${got.length ? got.map((k) => `"${k}"`).join("\u3001") : "\u7A7A\uFF08\u5BBF\u4E3B\u6865\u53EF\u80FD\u5C1A\u672A\u8C03\u7528 provideAppContext\uFF09"}\u3002
|
|
58
|
-
\u9884\u671F\uFF1A\u5BBF\u4E3B\u6865\u5E94\u5728\u8FDC\u7A0B\u9875\u9762\u52A0\u8F7D\u524D\u63D0\u4F9B ${missing.map((k) => `"${k}"`).join("\u3001")}\u3002
|
|
59
|
-
\u793A\u4F8B\uFF1Ahost/src/fulgurjs/host/bridge.ts \u2192 provideAppContext({ ${keys.join(", ")}, ... })
|
|
60
|
-
\u4FEE\u6CD5: \u68C0\u67E5\u5BBF\u4E3B\u5E94\u7528\u7684 fulgurjs \u6865\u662F\u5426\u5728 loadRemote \u9875\u9762\u524D\u5B8C\u6210 context provide\uFF08\u65F6\u5E8F\u5951\u7EA6 bridge \u2192 \u8FDC\u7A0B setup \u2192 \u9875\u9762\u6A21\u5757\uFF09`,
|
|
61
|
-
{ missing, got }
|
|
62
|
-
);
|
|
63
|
-
throw err;
|
|
64
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
ContextErrorCodes,
|
|
3
|
+
clearAppContext,
|
|
4
|
+
getAppContext,
|
|
5
|
+
provideAppContext,
|
|
6
|
+
requireAppContext
|
|
7
|
+
} from "./chunk-TSYLDY6H.js";
|
|
8
|
+
import "./chunk-OF2JCXTZ.js";
|
|
65
9
|
export {
|
|
66
10
|
ContextErrorCodes,
|
|
67
11
|
clearAppContext,
|