@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.
Files changed (101) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/DESIGN.md +7 -0
  3. package/README.en.md +86 -4
  4. package/README.md +125 -3
  5. package/dist/bridge-app-react.cjs +185 -0
  6. package/dist/bridge-app-react.d.cts +37 -0
  7. package/dist/bridge-app-react.d.ts +37 -0
  8. package/dist/bridge-app-react.js +115 -0
  9. package/dist/bridge-app-vue.cjs +111 -0
  10. package/dist/bridge-app-vue.d.cts +34 -0
  11. package/dist/bridge-app-vue.d.ts +34 -0
  12. package/dist/bridge-app-vue.js +51 -0
  13. package/dist/bridge-core-6uLJiMVa.d.ts +42 -0
  14. package/dist/bridge-core.cjs +232 -0
  15. package/dist/bridge-core.d.cts +51 -0
  16. package/dist/bridge-core.d.ts +51 -0
  17. package/dist/bridge-core.js +21 -0
  18. package/dist/bridge-errors.cjs +114 -0
  19. package/dist/bridge-errors.d.cts +36 -0
  20. package/dist/bridge-errors.d.ts +36 -0
  21. package/dist/bridge-errors.js +15 -0
  22. package/dist/bridge-host-react-C55RmGll.d.ts +35 -0
  23. package/dist/bridge-host-react.cjs +400 -0
  24. package/dist/bridge-host-react.d.cts +45 -0
  25. package/dist/bridge-host-react.d.ts +45 -0
  26. package/dist/bridge-host-react.js +183 -0
  27. package/dist/bridge-host-vue-BAxDKqGH.d.ts +32 -0
  28. package/dist/bridge-host-vue.cjs +437 -0
  29. package/dist/bridge-host-vue.d.cts +39 -0
  30. package/dist/bridge-host-vue.d.ts +39 -0
  31. package/dist/bridge-host-vue.js +214 -0
  32. package/dist/bridge-react.d.ts +12 -0
  33. package/dist/bridge-react.js +3 -0
  34. package/dist/bridge-vue.d.ts +8 -0
  35. package/dist/bridge-vue.js +3 -0
  36. package/dist/bridge.d.ts +16 -0
  37. package/dist/bridge.js +5 -0
  38. package/dist/chunk-DH2QMM4Y.js +76 -0
  39. package/dist/chunk-LE2G23E7.js +122 -0
  40. package/dist/chunk-MMXKQN2H.js +210 -0
  41. package/dist/chunk-OF2JCXTZ.js +15 -0
  42. package/dist/chunk-TOT3P7AK.js +1229 -0
  43. package/dist/chunk-TSYLDY6H.js +64 -0
  44. package/dist/chunk-X4F2BHNM.js +179 -0
  45. package/dist/context.js +8 -64
  46. package/dist/index.cjs +139 -13
  47. package/dist/index.js +139 -13
  48. package/dist/react.d.ts +47 -2
  49. package/dist/react.js +2 -0
  50. package/dist/runtime-entry.d.ts +44 -2
  51. package/dist/runtime-entry.js +1 -1
  52. package/dist/runtime.js +19 -19
  53. package/dist/vue.js +2 -0
  54. package/docs/webpack-mf-/345/257/271/347/205/247/344/270/216/347/274/272/345/217/243.md +1 -1
  55. package/docs//350/277/201/347/247/273/346/214/207/345/215/227.md +1 -1
  56. package/examples/README.en.md +20 -0
  57. package/examples/README.md +20 -0
  58. package/examples/bridge/README.md +36 -0
  59. package/examples/bridge/react-host/README.md +23 -0
  60. package/examples/bridge/react-host/fulgurjs.config.ts +20 -0
  61. package/examples/bridge/react-host/index.html +11 -0
  62. package/examples/bridge/react-host/package-lock.json +2457 -0
  63. package/examples/bridge/react-host/package.json +24 -0
  64. package/examples/bridge/react-host/src/env.d.ts +7 -0
  65. package/examples/bridge/react-host/src/host-session.ts +26 -0
  66. package/examples/bridge/react-host/src/main.tsx +62 -0
  67. package/examples/bridge/react-host/tsconfig.json +13 -0
  68. package/examples/bridge/react-host/vite.config.ts +9 -0
  69. package/examples/bridge/react-remote/README.md +20 -0
  70. package/examples/bridge/react-remote/fulgurjs.config.ts +17 -0
  71. package/examples/bridge/react-remote/index.html +11 -0
  72. package/examples/bridge/react-remote/package-lock.json +2382 -0
  73. package/examples/bridge/react-remote/package.json +24 -0
  74. package/examples/bridge/react-remote/src/bridge.tsx +66 -0
  75. package/examples/bridge/react-remote/src/env.d.ts +7 -0
  76. package/examples/bridge/react-remote/src/main.tsx +7 -0
  77. package/examples/bridge/react-remote/tsconfig.json +13 -0
  78. package/examples/bridge/react-remote/vite.config.ts +9 -0
  79. package/examples/bridge/vue-host/README.md +24 -0
  80. package/examples/bridge/vue-host/fulgurjs.config.ts +22 -0
  81. package/examples/bridge/vue-host/index.html +11 -0
  82. package/examples/bridge/vue-host/package-lock.json +1885 -0
  83. package/examples/bridge/vue-host/package.json +24 -0
  84. package/examples/bridge/vue-host/src/App.vue +70 -0
  85. package/examples/bridge/vue-host/src/env.d.ts +7 -0
  86. package/examples/bridge/vue-host/src/host-session.ts +29 -0
  87. package/examples/bridge/vue-host/src/main.ts +4 -0
  88. package/examples/bridge/vue-host/tsconfig.json +13 -0
  89. package/examples/bridge/vue-host/vite.config.ts +9 -0
  90. package/examples/bridge/vue-remote/README.md +19 -0
  91. package/examples/bridge/vue-remote/fulgurjs.config.ts +16 -0
  92. package/examples/bridge/vue-remote/index.html +11 -0
  93. package/examples/bridge/vue-remote/package-lock.json +1856 -0
  94. package/examples/bridge/vue-remote/package.json +21 -0
  95. package/examples/bridge/vue-remote/src/App.vue +12 -0
  96. package/examples/bridge/vue-remote/src/bridge.ts +57 -0
  97. package/examples/bridge/vue-remote/src/env.d.ts +7 -0
  98. package/examples/bridge/vue-remote/src/main.ts +15 -0
  99. package/examples/bridge/vue-remote/tsconfig.json +13 -0
  100. package/examples/bridge/vue-remote/vite.config.ts +9 -0
  101. package/package.json +43 -2
@@ -0,0 +1,210 @@
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-vue.ts
14
+ import { defineComponent, h, onBeforeUnmount, onMounted, ref, shallowRef, toRaw, watch } from "vue";
15
+ var ERROR_STYLE = {
16
+ padding: "16px",
17
+ border: "1px solid #fde2e2",
18
+ borderRadius: "4px",
19
+ background: "#fef0f0",
20
+ color: "#c45656",
21
+ fontSize: "13px",
22
+ lineHeight: "1.6"
23
+ };
24
+ var BUTTON_STYLE = {
25
+ padding: "4px 14px",
26
+ marginRight: "8px",
27
+ border: "1px solid #c45656",
28
+ borderRadius: "4px",
29
+ background: "#c45656",
30
+ color: "#fff",
31
+ fontSize: "13px",
32
+ cursor: "pointer"
33
+ };
34
+ var SECONDARY_BUTTON_STYLE = {
35
+ padding: "4px 14px",
36
+ border: "1px solid #c45656",
37
+ borderRadius: "4px",
38
+ background: "#fff",
39
+ color: "#c45656",
40
+ fontSize: "13px",
41
+ cursor: "pointer"
42
+ };
43
+ var BridgeErrorPlaceholder = defineComponent({
44
+ name: "FulgurjsBridgeError",
45
+ props: {
46
+ error: { type: Object, default: void 0 },
47
+ retry: { type: Function, required: false, default: void 0 }
48
+ },
49
+ setup(props) {
50
+ const reloadPage = () => {
51
+ window.location.reload();
52
+ };
53
+ return () => {
54
+ const err = props.error;
55
+ const code = err?.code ?? "UNKNOWN";
56
+ const message = err?.message ?? String(props.error ?? "unknown error");
57
+ return h("div", { style: ERROR_STYLE, "data-fulgurjs-error": code }, [
58
+ h("p", { style: "margin:0 0 4px;font-weight:600" }, `\u6865\u63A5\u5E94\u7528\u52A0\u8F7D\u5931\u8D25\uFF08\u9519\u8BEF\u7801 ${code}\uFF09`),
59
+ h("p", { style: "margin:0 0 8px;word-break:break-all" }, message),
60
+ h("p", { style: "margin:0 0 10px" }, "\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"),
61
+ h("div", { style: "margin:0" }, [
62
+ props.retry ? h("button", {
63
+ key: "retry",
64
+ style: BUTTON_STYLE,
65
+ type: "button",
66
+ "data-fulgurjs-retry": "",
67
+ onClick: () => props.retry?.()
68
+ }, "\u91CD\u8BD5\u52A0\u8F7D") : null,
69
+ h("button", {
70
+ key: "reload",
71
+ style: SECONDARY_BUTTON_STYLE,
72
+ type: "button",
73
+ "data-fulgurjs-reload": "",
74
+ onClick: reloadPage
75
+ }, "\u5237\u65B0\u9875\u9762\u91CD\u8BD5")
76
+ ])
77
+ ]);
78
+ };
79
+ }
80
+ });
81
+ function createVueBridgeAppWithLoader(loadRemote) {
82
+ return function createVueBridgeApp(spec, options = {}) {
83
+ assertBridgeOptions(`createVueBridgeApp("${spec}")`, options);
84
+ const componentName = "FulgurjsBridge_" + spec.replace(/[^A-Za-z0-9_-]/g, "_");
85
+ return defineComponent({
86
+ name: componentName,
87
+ // 多根组件:宿主传入的 class/style 等不自动继承(v1 不提供样式透传,外观由宿主外层元素控制)
88
+ inheritAttrs: false,
89
+ props: {
90
+ appProps: { type: Object, required: false, default: void 0 },
91
+ // 桥接控制参数:undefined(不启用受控会话)/ null(登出态)/ 非空字符串(登录代次)
92
+ sessionKey: { type: null, required: false, default: void 0 }
93
+ },
94
+ setup(props) {
95
+ const status = ref("idle");
96
+ const error = shallowRef(void 0);
97
+ const container = ref(null);
98
+ let generation = 0;
99
+ let contract;
100
+ let containerBlocked = false;
101
+ let acquiredSession;
102
+ const releaseAcquired = () => {
103
+ if (acquiredSession !== void 0) {
104
+ releaseBridgeSession(acquiredSession);
105
+ acquiredSession = void 0;
106
+ }
107
+ };
108
+ const invalidate = () => {
109
+ if (containerBlocked) return false;
110
+ generation++;
111
+ const el = container.value;
112
+ releaseAcquired();
113
+ if (contract && el) {
114
+ const c = contract;
115
+ contract = void 0;
116
+ try {
117
+ c.unmount(el);
118
+ } catch (e) {
119
+ const err = bridgeLifecycleError("unmount", spec, e instanceof Error ? e : String(e));
120
+ containerBlocked = true;
121
+ console.error("[fulgurjs] \u6865\u63A5\u5E94\u7528\u5378\u8F7D\u5931\u8D25\uFF0C\u8BE5\u5BB9\u5668\u5DF2\u5C01\u9501\uFF08\u540C\u9875\u53EA\u80FD\u5237\u65B0\u6062\u590D\uFF09\uFF1A", err);
122
+ error.value = err;
123
+ status.value = "error";
124
+ return false;
125
+ }
126
+ }
127
+ return true;
128
+ };
129
+ const run = async (myGeneration) => {
130
+ const el = container.value;
131
+ if (!el) return;
132
+ const sk = props.sessionKey;
133
+ status.value = "pending";
134
+ error.value = void 0;
135
+ if (sk === null) {
136
+ status.value = "idle";
137
+ return;
138
+ }
139
+ try {
140
+ assertControlledSessionKey(spec, sk);
141
+ const controlled = typeof sk === "string" ? sk : void 0;
142
+ if (controlled !== void 0 && controlled !== acquiredSession) {
143
+ releaseAcquired();
144
+ acquireBridgeSession(spec, controlled);
145
+ acquiredSession = controlled;
146
+ }
147
+ const resolution = resolveBridgeContext(spec, controlled, options.getContext);
148
+ if (resolution.provide) provideAppContext(resolution.provide);
149
+ const load = loadRemote(spec, { retries: options.retries });
150
+ const mod = options.timeout !== void 0 ? await withBridgeTimeout(load, options.timeout, spec) : await load;
151
+ if (myGeneration !== generation) return;
152
+ contract = assertBridgeContract(spec, mod);
153
+ const appPropsSource = props.appProps ? toRaw(props.appProps) : void 0;
154
+ await contract.mount(el, { ...appPropsSource ?? {} });
155
+ if (myGeneration !== generation) return;
156
+ status.value = "ready";
157
+ } catch (e) {
158
+ if (myGeneration !== generation) return;
159
+ error.value = e;
160
+ status.value = "error";
161
+ }
162
+ };
163
+ const start = () => {
164
+ const ok = invalidate();
165
+ if (!ok) return;
166
+ const myGeneration = generation;
167
+ void run(myGeneration);
168
+ };
169
+ const retry = () => {
170
+ start();
171
+ };
172
+ onMounted(() => {
173
+ const myGeneration = generation;
174
+ void run(myGeneration);
175
+ });
176
+ watch(() => props.sessionKey, () => {
177
+ start();
178
+ });
179
+ onBeforeUnmount(() => {
180
+ invalidate();
181
+ });
182
+ return () => {
183
+ const children = [];
184
+ if (status.value === "pending" && options.loadingComponent) {
185
+ children.push(h(options.loadingComponent, { key: "loading" }));
186
+ }
187
+ if (status.value === "error") {
188
+ const err = error.value;
189
+ if (options.errorComponent) {
190
+ children.push(h(options.errorComponent, { key: "error", error: err }));
191
+ } else {
192
+ children.push(h(BridgeErrorPlaceholder, { key: "error", error: err, retry: containerBlocked ? void 0 : retry }));
193
+ }
194
+ }
195
+ children.push(h("div", {
196
+ key: "bridge-root",
197
+ ref: container,
198
+ "data-fulgurjs-bridge-root": spec,
199
+ "data-fulgurjs-bridge-status": status.value
200
+ }));
201
+ return children;
202
+ };
203
+ }
204
+ });
205
+ };
206
+ }
207
+
208
+ export {
209
+ createVueBridgeAppWithLoader
210
+ };
@@ -0,0 +1,15 @@
1
+ // src/runtime/errors.ts
2
+ var FgError = class extends Error {
3
+ code;
4
+ details;
5
+ constructor(code, message, details, options) {
6
+ super(`[fulgurjs:${code}] ${message}`, options);
7
+ this.name = "FgError";
8
+ this.code = code;
9
+ this.details = details;
10
+ }
11
+ };
12
+
13
+ export {
14
+ FgError
15
+ };