@chatbi-v/core 2.1.6 → 2.1.8
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/{chunk-QET56C3T.mjs → chunk-WCD7UAPU.js} +0 -1
- package/dist/{config-manager-3TKURRUT.mjs → config-manager-LIF5OXKM.js} +1 -2
- package/dist/{index.mjs → index.cjs} +287 -145
- package/dist/index.d.ts +104 -104
- package/dist/index.js +145 -289
- package/package.json +6 -5
- package/dist/chunk-QET56C3T.mjs.map +0 -1
- package/dist/config-manager-3TKURRUT.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/{index.d.mts → index.d.cts} +104 -104
|
@@ -1,7 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// src/config-manager.ts
|
|
34
|
+
var config_manager_exports = {};
|
|
35
|
+
__export(config_manager_exports, {
|
|
36
|
+
ConfigManager: () => ConfigManager,
|
|
37
|
+
configManager: () => configManager
|
|
38
|
+
});
|
|
39
|
+
var ConfigManager, configManager;
|
|
40
|
+
var init_config_manager = __esm({
|
|
41
|
+
"src/config-manager.ts"() {
|
|
42
|
+
"use strict";
|
|
43
|
+
ConfigManager = class {
|
|
44
|
+
/** 内部存储配置的 Map 对象 */
|
|
45
|
+
config = /* @__PURE__ */ new Map();
|
|
46
|
+
/**
|
|
47
|
+
* 设置特定的配置项
|
|
48
|
+
* @param key - 配置键名(如 'system' 或插件 ID)
|
|
49
|
+
* @param value - 配置内容对象
|
|
50
|
+
*/
|
|
51
|
+
set(key, value) {
|
|
52
|
+
this.config.set(key, value);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 获取指定的配置项
|
|
56
|
+
* @param key - 配置键名
|
|
57
|
+
* @returns 配置内容,若不存在则返回 undefined
|
|
58
|
+
*/
|
|
59
|
+
get(key) {
|
|
60
|
+
return this.config.get(key);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 批量合并配置对象
|
|
64
|
+
* @description 对顶层属性进行浅合并,若属性值为对象则进行一层深度的合并。
|
|
65
|
+
* @param config - 待合并的配置对象映射
|
|
66
|
+
*/
|
|
67
|
+
merge(config) {
|
|
68
|
+
Object.keys(config).forEach((key) => {
|
|
69
|
+
const existing = this.config.get(key);
|
|
70
|
+
const incoming = config[key];
|
|
71
|
+
if (existing && typeof existing === "object" && incoming && typeof incoming === "object") {
|
|
72
|
+
this.config.set(key, { ...existing, ...incoming });
|
|
73
|
+
} else {
|
|
74
|
+
this.config.set(key, incoming);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 获取当前存储的所有配置快照
|
|
80
|
+
* @returns 包含所有配置的普通对象
|
|
81
|
+
*/
|
|
82
|
+
getAll() {
|
|
83
|
+
return Object.fromEntries(this.config);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
configManager = new ConfigManager();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// src/index.ts
|
|
91
|
+
var index_exports = {};
|
|
92
|
+
__export(index_exports, {
|
|
93
|
+
ApiEngine: () => ApiEngine,
|
|
94
|
+
ApiProvider: () => ApiProvider,
|
|
95
|
+
AvatarSkeleton: () => AvatarSkeleton,
|
|
96
|
+
AxiosAdapter: () => AxiosAdapter,
|
|
97
|
+
BasePlugin: () => BasePlugin,
|
|
98
|
+
BlockSkeleton: () => BlockSkeleton,
|
|
99
|
+
ConfigManager: () => ConfigManager,
|
|
100
|
+
DefaultEventBus: () => DefaultEventBus,
|
|
101
|
+
LocalStorageAdapter: () => LocalStorageAdapter,
|
|
102
|
+
LogLevel: () => LogLevel,
|
|
103
|
+
Logger: () => Logger,
|
|
104
|
+
PLUGIN_TYPES: () => PLUGIN_TYPES,
|
|
105
|
+
PluginErrorBoundary: () => PluginErrorBoundary,
|
|
106
|
+
PluginManager: () => PluginManager,
|
|
107
|
+
PluginProvider: () => PluginProvider,
|
|
108
|
+
PluginRuntime: () => PluginRuntime,
|
|
109
|
+
PluginSandbox: () => PluginSandbox,
|
|
110
|
+
PluginSlot: () => PluginSlot,
|
|
111
|
+
ProxySandbox: () => ProxySandbox,
|
|
112
|
+
SUCCESS_CODE: () => SUCCESS_CODE,
|
|
113
|
+
ScopedStorageAdapter: () => ScopedStorageAdapter,
|
|
114
|
+
ServiceRegistry: () => ServiceRegistry,
|
|
115
|
+
SidebarIconSkeleton: () => SidebarIconSkeleton,
|
|
116
|
+
Slot: () => Slot,
|
|
117
|
+
SlotSkeletons: () => SlotSkeletons,
|
|
118
|
+
StatusBarItemSkeleton: () => StatusBarItemSkeleton,
|
|
119
|
+
StorageManager: () => StorageManager,
|
|
120
|
+
apiEngine: () => apiEngine,
|
|
121
|
+
cleanUrlParams: () => cleanUrlParams,
|
|
122
|
+
configManager: () => configManager,
|
|
123
|
+
createLogger: () => createLogger,
|
|
124
|
+
dateUtils: () => dateUtils,
|
|
125
|
+
definePlugin: () => definePlugin,
|
|
126
|
+
isMockMode: () => isMockMode,
|
|
127
|
+
logger: () => logger,
|
|
128
|
+
normalizeParams: () => normalizeParams,
|
|
129
|
+
pluginManager: () => pluginManager,
|
|
130
|
+
resolveApiModules: () => resolveApiModules,
|
|
131
|
+
resolvePluginRegistry: () => resolvePluginRegistry,
|
|
132
|
+
serviceRegistry: () => serviceRegistry,
|
|
133
|
+
useApi: () => useApi,
|
|
134
|
+
usePluginLoader: () => usePluginLoader,
|
|
135
|
+
usePluginManager: () => usePluginManager,
|
|
136
|
+
useStorageState: () => useStorageState,
|
|
137
|
+
version: () => version
|
|
138
|
+
});
|
|
139
|
+
module.exports = __toCommonJS(index_exports);
|
|
5
140
|
|
|
6
141
|
// src/ports/plugin-port.ts
|
|
7
142
|
var PLUGIN_TYPES = ["business", "functional", "view", "theme", "renderer", "system"];
|
|
@@ -36,6 +171,21 @@ function definePlugin(plugin) {
|
|
|
36
171
|
};
|
|
37
172
|
}
|
|
38
173
|
|
|
174
|
+
// src/api-context.tsx
|
|
175
|
+
var import_react = require("react");
|
|
176
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
177
|
+
var ApiContext = (0, import_react.createContext)(null);
|
|
178
|
+
var ApiProvider = ({ api, children }) => {
|
|
179
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ApiContext.Provider, { value: api, children });
|
|
180
|
+
};
|
|
181
|
+
var useApi = () => {
|
|
182
|
+
const context = (0, import_react.useContext)(ApiContext);
|
|
183
|
+
if (!context) {
|
|
184
|
+
throw new Error("useApi must be used within an ApiProvider");
|
|
185
|
+
}
|
|
186
|
+
return context;
|
|
187
|
+
};
|
|
188
|
+
|
|
39
189
|
// src/utils/logger.ts
|
|
40
190
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
41
191
|
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
@@ -389,26 +539,14 @@ var ServiceRegistry = class {
|
|
|
389
539
|
};
|
|
390
540
|
var serviceRegistry = new ServiceRegistry();
|
|
391
541
|
|
|
392
|
-
// src/
|
|
393
|
-
|
|
394
|
-
import { jsx } from "react/jsx-runtime";
|
|
395
|
-
var ApiContext = createContext(null);
|
|
396
|
-
var ApiProvider = ({ api, children }) => {
|
|
397
|
-
return /* @__PURE__ */ jsx(ApiContext.Provider, { value: api, children });
|
|
398
|
-
};
|
|
399
|
-
var useApi = () => {
|
|
400
|
-
const context = useContext(ApiContext);
|
|
401
|
-
if (!context) {
|
|
402
|
-
throw new Error("useApi must be used within an ApiProvider");
|
|
403
|
-
}
|
|
404
|
-
return context;
|
|
405
|
-
};
|
|
542
|
+
// src/index.ts
|
|
543
|
+
init_config_manager();
|
|
406
544
|
|
|
407
545
|
// src/components/PluginErrorBoundary.tsx
|
|
408
|
-
|
|
546
|
+
var import_react3 = require("react");
|
|
409
547
|
|
|
410
548
|
// src/domain/plugin-manager.ts
|
|
411
|
-
|
|
549
|
+
var import_react2 = require("react");
|
|
412
550
|
|
|
413
551
|
// src/adapters/local-storage-adapter.ts
|
|
414
552
|
var LocalStorageAdapter = class {
|
|
@@ -519,6 +657,9 @@ var LocalStorageAdapter = class {
|
|
|
519
657
|
}
|
|
520
658
|
};
|
|
521
659
|
|
|
660
|
+
// src/domain/plugin-manager.ts
|
|
661
|
+
init_config_manager();
|
|
662
|
+
|
|
522
663
|
// src/event-bus.ts
|
|
523
664
|
var logger3 = createLogger("EventBus");
|
|
524
665
|
var DefaultEventBus = class {
|
|
@@ -1071,6 +1212,7 @@ var ScopedStorageAdapter = class {
|
|
|
1071
1212
|
};
|
|
1072
1213
|
|
|
1073
1214
|
// src/domain/storage-manager.ts
|
|
1215
|
+
init_config_manager();
|
|
1074
1216
|
var StorageManager = class {
|
|
1075
1217
|
/** 底层物理存储驱动 */
|
|
1076
1218
|
baseStorage;
|
|
@@ -1314,7 +1456,7 @@ var PluginManager = class {
|
|
|
1314
1456
|
* @param affectedSlot - (可选) 受影响的插槽位置
|
|
1315
1457
|
*/
|
|
1316
1458
|
notify(affectedSlot) {
|
|
1317
|
-
startTransition(() => {
|
|
1459
|
+
(0, import_react2.startTransition)(() => {
|
|
1318
1460
|
if (affectedSlot) {
|
|
1319
1461
|
this.memoizedExtensions.delete(String(affectedSlot));
|
|
1320
1462
|
} else {
|
|
@@ -1804,9 +1946,9 @@ var PluginManager = class {
|
|
|
1804
1946
|
logger6.info("\u5F00\u59CB\u52A0\u8F7D\u63D2\u4EF6...");
|
|
1805
1947
|
const localLoadPromises = Object.entries(registry).map(async ([registryId, importFn]) => {
|
|
1806
1948
|
try {
|
|
1807
|
-
const
|
|
1949
|
+
const module2 = await importFn();
|
|
1808
1950
|
const config = configs[registryId];
|
|
1809
|
-
const plugin = this.instantiatePlugin(registryId,
|
|
1951
|
+
const plugin = this.instantiatePlugin(registryId, module2, config);
|
|
1810
1952
|
if (plugin && config) {
|
|
1811
1953
|
configManager.set(plugin.id, config);
|
|
1812
1954
|
}
|
|
@@ -1852,8 +1994,8 @@ var PluginManager = class {
|
|
|
1852
1994
|
}
|
|
1853
1995
|
try {
|
|
1854
1996
|
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
1855
|
-
const
|
|
1856
|
-
return this.instantiatePlugin(pluginId,
|
|
1997
|
+
const module2 = await dynamicImport(url);
|
|
1998
|
+
return this.instantiatePlugin(pluginId, module2, config);
|
|
1857
1999
|
} catch (e) {
|
|
1858
2000
|
logger6.warn(`ESM \u52A0\u8F7D\u5931\u8D25\uFF0C\u5C1D\u8BD5 IIFE \u52A0\u8F7D: ${pluginId}`);
|
|
1859
2001
|
return this.loadIIFEPlugin(pluginId, url, config);
|
|
@@ -1882,15 +2024,15 @@ var PluginManager = class {
|
|
|
1882
2024
|
/**
|
|
1883
2025
|
* 实例化插件
|
|
1884
2026
|
*/
|
|
1885
|
-
instantiatePlugin(pluginId,
|
|
1886
|
-
let PluginClass =
|
|
2027
|
+
instantiatePlugin(pluginId, module2, config) {
|
|
2028
|
+
let PluginClass = module2.default;
|
|
1887
2029
|
if (!PluginClass) {
|
|
1888
|
-
const key = Object.keys(
|
|
1889
|
-
if (key) PluginClass =
|
|
2030
|
+
const key = Object.keys(module2).find((k) => k.endsWith("Plugin"));
|
|
2031
|
+
if (key) PluginClass = module2[key];
|
|
1890
2032
|
}
|
|
1891
|
-
if (!PluginClass && typeof
|
|
1892
|
-
if (
|
|
1893
|
-
PluginClass =
|
|
2033
|
+
if (!PluginClass && typeof module2 === "object") {
|
|
2034
|
+
if (module2.id && module2.metadata) {
|
|
2035
|
+
PluginClass = module2;
|
|
1894
2036
|
}
|
|
1895
2037
|
}
|
|
1896
2038
|
if (PluginClass) {
|
|
@@ -1939,9 +2081,9 @@ var PluginManager = class {
|
|
|
1939
2081
|
var pluginManager = new PluginManager(new LocalStorageAdapter());
|
|
1940
2082
|
|
|
1941
2083
|
// src/components/PluginErrorBoundary.tsx
|
|
1942
|
-
|
|
2084
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1943
2085
|
var logger7 = createLogger("PluginErrorBoundary");
|
|
1944
|
-
var PluginErrorBoundary = class extends Component {
|
|
2086
|
+
var PluginErrorBoundary = class extends import_react3.Component {
|
|
1945
2087
|
constructor(props) {
|
|
1946
2088
|
super(props);
|
|
1947
2089
|
this.state = { hasError: false, error: null };
|
|
@@ -1985,7 +2127,7 @@ var PluginErrorBoundary = class extends Component {
|
|
|
1985
2127
|
if (this.props.silent) {
|
|
1986
2128
|
return null;
|
|
1987
2129
|
}
|
|
1988
|
-
return /* @__PURE__ */
|
|
2130
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1989
2131
|
"div",
|
|
1990
2132
|
{
|
|
1991
2133
|
className: "plugin-error-placeholder hidden",
|
|
@@ -1999,33 +2141,33 @@ var PluginErrorBoundary = class extends Component {
|
|
|
1999
2141
|
};
|
|
2000
2142
|
|
|
2001
2143
|
// src/components/PluginSlot.tsx
|
|
2002
|
-
|
|
2144
|
+
var import_react4 = require("react");
|
|
2003
2145
|
|
|
2004
2146
|
// src/components/SlotSkeletons.tsx
|
|
2005
|
-
|
|
2006
|
-
var SidebarIconSkeleton = ({ expanded = false }) => /* @__PURE__ */ jsxs("div", { className: `flex items-center transition-all duration-300 relative
|
|
2147
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
2148
|
+
var SidebarIconSkeleton = ({ expanded = false }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `flex items-center transition-all duration-300 relative
|
|
2007
2149
|
${expanded ? "w-full" : "w-12 justify-center"} px-3 h-11 rounded-xl`, children: [
|
|
2008
|
-
/* @__PURE__ */
|
|
2009
|
-
expanded && /* @__PURE__ */
|
|
2150
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "w-6 h-6 bg-slate-200 dark:bg-white/10 rounded-lg shrink-0 animate-pulse" }),
|
|
2151
|
+
expanded && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "ml-3 flex-1 h-4 bg-slate-200 dark:bg-white/10 rounded animate-pulse" })
|
|
2010
2152
|
] });
|
|
2011
|
-
var StatusBarItemSkeleton = () => /* @__PURE__ */
|
|
2012
|
-
var AvatarSkeleton = () => /* @__PURE__ */
|
|
2013
|
-
var BlockSkeleton = ({ className }) => /* @__PURE__ */
|
|
2153
|
+
var StatusBarItemSkeleton = () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "h-4 w-16 bg-slate-200 dark:bg-white/10 rounded animate-pulse" });
|
|
2154
|
+
var AvatarSkeleton = () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "w-10 h-10 rounded-full bg-slate-200 dark:bg-white/10 animate-pulse" });
|
|
2155
|
+
var BlockSkeleton = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: `bg-slate-200 dark:bg-white/10 rounded animate-pulse ${className || "w-full h-full"}` });
|
|
2014
2156
|
var SlotSkeletons = ({ slot, expanded }) => {
|
|
2015
2157
|
if (slot.includes("sidebar")) {
|
|
2016
|
-
return /* @__PURE__ */
|
|
2158
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SidebarIconSkeleton, { expanded });
|
|
2017
2159
|
}
|
|
2018
2160
|
if (slot.includes("status")) {
|
|
2019
|
-
return /* @__PURE__ */
|
|
2161
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(StatusBarItemSkeleton, {});
|
|
2020
2162
|
}
|
|
2021
2163
|
if (slot.includes("avatar")) {
|
|
2022
|
-
return /* @__PURE__ */
|
|
2164
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AvatarSkeleton, {});
|
|
2023
2165
|
}
|
|
2024
|
-
return /* @__PURE__ */
|
|
2166
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(BlockSkeleton, {});
|
|
2025
2167
|
};
|
|
2026
2168
|
|
|
2027
2169
|
// src/components/PluginSlot.tsx
|
|
2028
|
-
|
|
2170
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
2029
2171
|
var ExtensionLoader = ({ pluginId, component: Component2, props }) => {
|
|
2030
2172
|
const status = pluginManager.getPluginRuntimeStatus(pluginId);
|
|
2031
2173
|
if (status !== "mounted") {
|
|
@@ -2035,7 +2177,7 @@ var ExtensionLoader = ({ pluginId, component: Component2, props }) => {
|
|
|
2035
2177
|
}
|
|
2036
2178
|
throw pluginManager.mountPlugin(pluginId);
|
|
2037
2179
|
}
|
|
2038
|
-
return /* @__PURE__ */
|
|
2180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Component2, { ...props });
|
|
2039
2181
|
};
|
|
2040
2182
|
var PluginSlot = ({
|
|
2041
2183
|
slot,
|
|
@@ -2046,10 +2188,10 @@ var PluginSlot = ({
|
|
|
2046
2188
|
skeleton,
|
|
2047
2189
|
fallback
|
|
2048
2190
|
}) => {
|
|
2049
|
-
const [, forceUpdate] = useState({});
|
|
2050
|
-
useEffect(() => {
|
|
2191
|
+
const [, forceUpdate] = (0, import_react4.useState)({});
|
|
2192
|
+
(0, import_react4.useEffect)(() => {
|
|
2051
2193
|
const unsubscribe = pluginManager.subscribe(() => {
|
|
2052
|
-
|
|
2194
|
+
(0, import_react4.startTransition)(() => {
|
|
2053
2195
|
forceUpdate({});
|
|
2054
2196
|
});
|
|
2055
2197
|
}, slot);
|
|
@@ -2061,18 +2203,18 @@ var PluginSlot = ({
|
|
|
2061
2203
|
logo: pluginManager.getSystemConfig("logo"),
|
|
2062
2204
|
version: pluginManager.getSystemConfig("version")
|
|
2063
2205
|
} : void 0;
|
|
2064
|
-
const mergedProps = useMemo(() => ({
|
|
2206
|
+
const mergedProps = (0, import_react4.useMemo)(() => ({
|
|
2065
2207
|
...props,
|
|
2066
2208
|
systemConfig
|
|
2067
2209
|
}), [props, systemConfig]);
|
|
2068
|
-
const items = useMemo(() => {
|
|
2210
|
+
const items = (0, import_react4.useMemo)(() => {
|
|
2069
2211
|
return extensions.map((ext, index) => {
|
|
2070
2212
|
const Component2 = ext.component;
|
|
2071
2213
|
const key = ext.meta?.key || `${ext.slot}-${ext.order || 0}-${index}`;
|
|
2072
2214
|
return {
|
|
2073
2215
|
key,
|
|
2074
2216
|
extension: ext,
|
|
2075
|
-
component: /* @__PURE__ */
|
|
2217
|
+
component: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PluginErrorBoundary, { pluginId: ext._pluginId, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react4.Suspense, { fallback: skeleton || /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotSkeletons, { slot }), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2076
2218
|
ExtensionLoader,
|
|
2077
2219
|
{
|
|
2078
2220
|
pluginId: ext._pluginId || "",
|
|
@@ -2085,17 +2227,17 @@ var PluginSlot = ({
|
|
|
2085
2227
|
}, [extensions, mergedProps]);
|
|
2086
2228
|
if (items.length === 0) {
|
|
2087
2229
|
if (fallback) {
|
|
2088
|
-
return /* @__PURE__ */
|
|
2230
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: fallback });
|
|
2089
2231
|
}
|
|
2090
2232
|
if (skeleton) {
|
|
2091
|
-
return /* @__PURE__ */
|
|
2233
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `plugin-slot plugin-slot-${slot} plugin-slot-skeleton ${className || ""}`, style, children: skeleton });
|
|
2092
2234
|
}
|
|
2093
2235
|
return null;
|
|
2094
2236
|
}
|
|
2095
2237
|
if (items.length === 1 && slot === "root-layout" && !className && !style && !renderItem) {
|
|
2096
|
-
return /* @__PURE__ */
|
|
2238
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: items[0].component });
|
|
2097
2239
|
}
|
|
2098
|
-
return /* @__PURE__ */
|
|
2240
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `plugin-slot plugin-slot-${slot} ${className || ""}`, style, children: renderItem ? items.map((item, index) => renderItem(item, index)) : items.map((item) => item.component) });
|
|
2099
2241
|
};
|
|
2100
2242
|
|
|
2101
2243
|
// src/domain/auto-loader.ts
|
|
@@ -2142,27 +2284,12 @@ var resolvePluginRegistry = (options) => {
|
|
|
2142
2284
|
// src/domain/models.ts
|
|
2143
2285
|
var SUCCESS_CODE = "000000";
|
|
2144
2286
|
|
|
2145
|
-
// src/plugin-context.tsx
|
|
2146
|
-
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
2147
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
2148
|
-
var PluginContext = createContext2(null);
|
|
2149
|
-
var PluginProvider = ({ manager, children }) => {
|
|
2150
|
-
return /* @__PURE__ */ jsx5(PluginContext.Provider, { value: manager, children });
|
|
2151
|
-
};
|
|
2152
|
-
var usePluginManager = () => {
|
|
2153
|
-
const context = useContext2(PluginContext);
|
|
2154
|
-
if (!context) {
|
|
2155
|
-
throw new Error("usePluginManager must be used within a PluginProvider");
|
|
2156
|
-
}
|
|
2157
|
-
return context;
|
|
2158
|
-
};
|
|
2159
|
-
|
|
2160
2287
|
// src/api/adapters/axios-adapter.ts
|
|
2161
|
-
|
|
2288
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
2162
2289
|
var AxiosAdapter = class {
|
|
2163
2290
|
client;
|
|
2164
2291
|
constructor(baseURL = "/api", timeout = 1e4) {
|
|
2165
|
-
this.client =
|
|
2292
|
+
this.client = import_axios.default.create({
|
|
2166
2293
|
baseURL,
|
|
2167
2294
|
timeout
|
|
2168
2295
|
});
|
|
@@ -2282,8 +2409,8 @@ var ApiEngine = class {
|
|
|
2282
2409
|
/**
|
|
2283
2410
|
* 获取接口配置
|
|
2284
2411
|
*/
|
|
2285
|
-
getEndpoint(
|
|
2286
|
-
return this.config[
|
|
2412
|
+
getEndpoint(module2, action) {
|
|
2413
|
+
return this.config[module2]?.[action];
|
|
2287
2414
|
}
|
|
2288
2415
|
/**
|
|
2289
2416
|
* 发起 API 请求
|
|
@@ -2292,10 +2419,10 @@ var ApiEngine = class {
|
|
|
2292
2419
|
* @param data 请求数据 (Body 或 Query)
|
|
2293
2420
|
* @param options 请求选项
|
|
2294
2421
|
*/
|
|
2295
|
-
async call(
|
|
2296
|
-
const endpoint = this.getEndpoint(
|
|
2422
|
+
async call(module2, action, data, options = {}) {
|
|
2423
|
+
const endpoint = this.getEndpoint(module2, action);
|
|
2297
2424
|
if (!endpoint) {
|
|
2298
|
-
logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${
|
|
2425
|
+
logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${module2}.${action} (\u5F53\u524D\u5DF2\u6CE8\u518C\u6A21\u5757: ${Object.keys(this.config).join(", ")})`);
|
|
2299
2426
|
return Promise.resolve(void 0);
|
|
2300
2427
|
}
|
|
2301
2428
|
const requestConfig = await this.prepareRequestConfig(endpoint, data, options);
|
|
@@ -2311,12 +2438,12 @@ var ApiEngine = class {
|
|
|
2311
2438
|
}
|
|
2312
2439
|
const hijacked = await this.applyResponseInterceptors(response, requestConfig);
|
|
2313
2440
|
if (hijacked) {
|
|
2314
|
-
logger9.info("\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:",
|
|
2441
|
+
logger9.info("\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:", module2, action);
|
|
2315
2442
|
return void 0;
|
|
2316
2443
|
}
|
|
2317
2444
|
this.checkHttpStatus(response);
|
|
2318
2445
|
const responseData = this.extractResponseData(response);
|
|
2319
|
-
this.handleBusinessError(responseData, endpoint,
|
|
2446
|
+
this.handleBusinessError(responseData, endpoint, module2, action);
|
|
2320
2447
|
return responseData;
|
|
2321
2448
|
}
|
|
2322
2449
|
/**
|
|
@@ -2326,10 +2453,10 @@ var ApiEngine = class {
|
|
|
2326
2453
|
* @param data 请求数据
|
|
2327
2454
|
* @param options 请求选项
|
|
2328
2455
|
*/
|
|
2329
|
-
async stream(
|
|
2330
|
-
const endpoint = this.getEndpoint(
|
|
2456
|
+
async stream(module2, action, data, options = {}) {
|
|
2457
|
+
const endpoint = this.getEndpoint(module2, action);
|
|
2331
2458
|
if (!endpoint) {
|
|
2332
|
-
logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${
|
|
2459
|
+
logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${module2}.${action}\uFF0C\u8DF3\u8FC7\u6D41\u5F0F\u8BF7\u6C42\u3002`);
|
|
2333
2460
|
return;
|
|
2334
2461
|
}
|
|
2335
2462
|
if (!this.adapter.stream) {
|
|
@@ -2350,7 +2477,7 @@ var ApiEngine = class {
|
|
|
2350
2477
|
onResponse: async (response) => {
|
|
2351
2478
|
const hijacked = await this.applyResponseInterceptors(response, requestConfig);
|
|
2352
2479
|
if (hijacked) {
|
|
2353
|
-
logger9.info("\u6D41\u5F0F\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:",
|
|
2480
|
+
logger9.info("\u6D41\u5F0F\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:", module2, action);
|
|
2354
2481
|
if (requestConfig.signal instanceof AbortController) {
|
|
2355
2482
|
requestConfig.signal.abort();
|
|
2356
2483
|
}
|
|
@@ -2441,7 +2568,7 @@ var ApiEngine = class {
|
|
|
2441
2568
|
/**
|
|
2442
2569
|
* 处理业务错误
|
|
2443
2570
|
*/
|
|
2444
|
-
handleBusinessError(responseData, endpoint,
|
|
2571
|
+
handleBusinessError(responseData, endpoint, module2, action) {
|
|
2445
2572
|
if (!this.isBaseResponse(responseData)) return;
|
|
2446
2573
|
const res = responseData;
|
|
2447
2574
|
const code = String(res.code);
|
|
@@ -2449,7 +2576,7 @@ var ApiEngine = class {
|
|
|
2449
2576
|
if (!isSuccess) {
|
|
2450
2577
|
const strategy = endpoint.errorStrategy || "reject";
|
|
2451
2578
|
if (strategy === "reject") {
|
|
2452
|
-
logger9.error(`API \u8BF7\u6C42\u4E1A\u52A1\u9519\u8BEF (${
|
|
2579
|
+
logger9.error(`API \u8BF7\u6C42\u4E1A\u52A1\u9519\u8BEF (${module2}.${action}):`, res.message);
|
|
2453
2580
|
throw new Error(res.message || `Request failed with code ${code}`);
|
|
2454
2581
|
}
|
|
2455
2582
|
}
|
|
@@ -2568,11 +2695,11 @@ function resolveApiModules(definitionsMap, mocksMap = {}) {
|
|
|
2568
2695
|
const fileName = path.split("/").pop() || "";
|
|
2569
2696
|
return fileName.replace(/\.mock\.(ts|js|tsx|jsx|json)$/, "").replace(/\.(ts|js|tsx|jsx|json)$/, "");
|
|
2570
2697
|
};
|
|
2571
|
-
Object.entries(definitionsMap).forEach(([path,
|
|
2698
|
+
Object.entries(definitionsMap).forEach(([path, module2]) => {
|
|
2572
2699
|
if (path.includes(".mock.")) return;
|
|
2573
2700
|
const namespace = getNamespace(path);
|
|
2574
|
-
if (!namespace || !
|
|
2575
|
-
let apiDef =
|
|
2701
|
+
if (!namespace || !module2.default) return;
|
|
2702
|
+
let apiDef = module2.default;
|
|
2576
2703
|
const mockEntry = Object.entries(mocksMap).find(([mockPath]) => {
|
|
2577
2704
|
return getNamespace(mockPath) === namespace && mockPath.includes(".mock.");
|
|
2578
2705
|
});
|
|
@@ -2588,93 +2715,75 @@ function resolveApiModules(definitionsMap, mocksMap = {}) {
|
|
|
2588
2715
|
return config;
|
|
2589
2716
|
}
|
|
2590
2717
|
|
|
2718
|
+
// src/plugin-context.tsx
|
|
2719
|
+
var import_react5 = require("react");
|
|
2720
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
2721
|
+
var PluginContext = (0, import_react5.createContext)(null);
|
|
2722
|
+
var PluginProvider = ({ manager, children }) => {
|
|
2723
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PluginContext.Provider, { value: manager, children });
|
|
2724
|
+
};
|
|
2725
|
+
var usePluginManager = () => {
|
|
2726
|
+
const context = (0, import_react5.useContext)(PluginContext);
|
|
2727
|
+
if (!context) {
|
|
2728
|
+
throw new Error("usePluginManager must be used within a PluginProvider");
|
|
2729
|
+
}
|
|
2730
|
+
return context;
|
|
2731
|
+
};
|
|
2732
|
+
|
|
2591
2733
|
// src/utils/date.ts
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2734
|
+
var import_zh_cn = require("dayjs/locale/zh-cn");
|
|
2735
|
+
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
2736
|
+
var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime"), 1);
|
|
2737
|
+
import_dayjs.default.extend(import_relativeTime.default);
|
|
2738
|
+
import_dayjs.default.locale("zh-cn");
|
|
2597
2739
|
var dateUtils = {
|
|
2598
2740
|
/**
|
|
2599
2741
|
* 格式化日期为 YYYY-MM-DD
|
|
2600
2742
|
*/
|
|
2601
2743
|
formatDate(date) {
|
|
2602
|
-
return
|
|
2744
|
+
return (0, import_dayjs.default)(date).format("YYYY-MM-DD");
|
|
2603
2745
|
},
|
|
2604
2746
|
/**
|
|
2605
2747
|
* 格式化时间为 HH:mm:ss
|
|
2606
2748
|
*/
|
|
2607
2749
|
formatTime(date) {
|
|
2608
|
-
return
|
|
2750
|
+
return (0, import_dayjs.default)(date).format("HH:mm:ss");
|
|
2609
2751
|
},
|
|
2610
2752
|
/**
|
|
2611
2753
|
* 格式化日期时间为 YYYY-MM-DD HH:mm:ss
|
|
2612
2754
|
*/
|
|
2613
2755
|
formatDateTime(date) {
|
|
2614
|
-
return
|
|
2756
|
+
return (0, import_dayjs.default)(date).format("YYYY-MM-DD HH:mm:ss");
|
|
2615
2757
|
},
|
|
2616
2758
|
/**
|
|
2617
2759
|
* 获取当前时间戳(毫秒)
|
|
2618
2760
|
*/
|
|
2619
2761
|
now() {
|
|
2620
|
-
return
|
|
2762
|
+
return (0, import_dayjs.default)().valueOf();
|
|
2621
2763
|
},
|
|
2622
2764
|
/**
|
|
2623
2765
|
* 获取相对时间(例如:几分钟前)
|
|
2624
2766
|
*/
|
|
2625
2767
|
fromNow(date) {
|
|
2626
|
-
return
|
|
2768
|
+
return (0, import_dayjs.default)(date).fromNow();
|
|
2627
2769
|
},
|
|
2628
2770
|
/**
|
|
2629
2771
|
* 原始 dayjs 对象,用于更复杂的场景
|
|
2630
2772
|
*/
|
|
2631
|
-
dayjs
|
|
2773
|
+
dayjs: import_dayjs.default
|
|
2632
2774
|
};
|
|
2633
2775
|
|
|
2634
2776
|
// src/utils/index.ts
|
|
2635
2777
|
var version = "1.0.0";
|
|
2636
2778
|
|
|
2637
|
-
// src/hooks/use-storage-state.ts
|
|
2638
|
-
import { useCallback, useState as useState2 } from "react";
|
|
2639
|
-
function useStorageState(pluginId, key, options = {}) {
|
|
2640
|
-
const { defaultValue, scope = "plugin" } = options;
|
|
2641
|
-
const storageManager = pluginManager.getStorageManager();
|
|
2642
|
-
const getStorage = useCallback(() => {
|
|
2643
|
-
const contextStorage = storageManager.getContextStorage(pluginId);
|
|
2644
|
-
return scope === "shared" ? contextStorage.shared : contextStorage;
|
|
2645
|
-
}, [pluginId, scope, storageManager]);
|
|
2646
|
-
const [state, setState] = useState2(() => {
|
|
2647
|
-
try {
|
|
2648
|
-
if (typeof window === "undefined") return defaultValue;
|
|
2649
|
-
const storage = getStorage();
|
|
2650
|
-
const val = storage.get(key);
|
|
2651
|
-
return val !== null ? val : defaultValue;
|
|
2652
|
-
} catch (e) {
|
|
2653
|
-
console.warn(`[useStorageState] \u8BFB\u53D6 Key "${key}" \u5931\u8D25`, e);
|
|
2654
|
-
return defaultValue;
|
|
2655
|
-
}
|
|
2656
|
-
});
|
|
2657
|
-
const setValue = useCallback((value) => {
|
|
2658
|
-
try {
|
|
2659
|
-
const valueToStore = value instanceof Function ? value(state) : value;
|
|
2660
|
-
setState(valueToStore);
|
|
2661
|
-
const storage = getStorage();
|
|
2662
|
-
storage.set(key, valueToStore);
|
|
2663
|
-
} catch (error) {
|
|
2664
|
-
console.warn(`[useStorageState] \u8BBE\u7F6E Key "${key}" \u5931\u8D25:`, error);
|
|
2665
|
-
}
|
|
2666
|
-
}, [key, state, getStorage]);
|
|
2667
|
-
return [state, setValue];
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
2779
|
// src/hooks/use-plugin-loader.ts
|
|
2671
|
-
|
|
2780
|
+
var import_react6 = require("react");
|
|
2672
2781
|
var logger10 = createLogger("PluginLoader");
|
|
2673
2782
|
var usePluginLoader = (options) => {
|
|
2674
|
-
const [pluginsLoaded, setPluginsLoaded] =
|
|
2675
|
-
const [pluginVersion, setPluginVersion] =
|
|
2676
|
-
const loadingRef = useRef(false);
|
|
2677
|
-
|
|
2783
|
+
const [pluginsLoaded, setPluginsLoaded] = (0, import_react6.useState)(false);
|
|
2784
|
+
const [pluginVersion, setPluginVersion] = (0, import_react6.useState)(0);
|
|
2785
|
+
const loadingRef = (0, import_react6.useRef)(false);
|
|
2786
|
+
(0, import_react6.useEffect)(() => {
|
|
2678
2787
|
const unsubscribe = pluginManager.subscribe(() => {
|
|
2679
2788
|
logger10.debug("Plugin state changed, refreshing UI...");
|
|
2680
2789
|
setPluginVersion((v) => v + 1);
|
|
@@ -2698,7 +2807,7 @@ var usePluginLoader = (options) => {
|
|
|
2698
2807
|
}) : {};
|
|
2699
2808
|
const finalRegistry = { ...discoveredRegistry, ...manualRegistry };
|
|
2700
2809
|
if (options.systemConfig) {
|
|
2701
|
-
const { configManager: configManager2 } = await
|
|
2810
|
+
const { configManager: configManager2 } = await Promise.resolve().then(() => (init_config_manager(), config_manager_exports));
|
|
2702
2811
|
configManager2.set("system", options.systemConfig);
|
|
2703
2812
|
}
|
|
2704
2813
|
await pluginManager.loadPlugins(pluginConfigs, finalRegistry, false);
|
|
@@ -2716,7 +2825,41 @@ var usePluginLoader = (options) => {
|
|
|
2716
2825
|
}, []);
|
|
2717
2826
|
return { pluginsLoaded, pluginVersion };
|
|
2718
2827
|
};
|
|
2719
|
-
|
|
2828
|
+
|
|
2829
|
+
// src/hooks/use-storage-state.ts
|
|
2830
|
+
var import_react7 = require("react");
|
|
2831
|
+
function useStorageState(pluginId, key, options = {}) {
|
|
2832
|
+
const { defaultValue, scope = "plugin" } = options;
|
|
2833
|
+
const storageManager = pluginManager.getStorageManager();
|
|
2834
|
+
const getStorage = (0, import_react7.useCallback)(() => {
|
|
2835
|
+
const contextStorage = storageManager.getContextStorage(pluginId);
|
|
2836
|
+
return scope === "shared" ? contextStorage.shared : contextStorage;
|
|
2837
|
+
}, [pluginId, scope, storageManager]);
|
|
2838
|
+
const [state, setState] = (0, import_react7.useState)(() => {
|
|
2839
|
+
try {
|
|
2840
|
+
if (typeof window === "undefined") return defaultValue;
|
|
2841
|
+
const storage = getStorage();
|
|
2842
|
+
const val = storage.get(key);
|
|
2843
|
+
return val !== null ? val : defaultValue;
|
|
2844
|
+
} catch (e) {
|
|
2845
|
+
console.warn(`[useStorageState] \u8BFB\u53D6 Key "${key}" \u5931\u8D25`, e);
|
|
2846
|
+
return defaultValue;
|
|
2847
|
+
}
|
|
2848
|
+
});
|
|
2849
|
+
const setValue = (0, import_react7.useCallback)((value) => {
|
|
2850
|
+
try {
|
|
2851
|
+
const valueToStore = value instanceof Function ? value(state) : value;
|
|
2852
|
+
setState(valueToStore);
|
|
2853
|
+
const storage = getStorage();
|
|
2854
|
+
storage.set(key, valueToStore);
|
|
2855
|
+
} catch (error) {
|
|
2856
|
+
console.warn(`[useStorageState] \u8BBE\u7F6E Key "${key}" \u5931\u8D25:`, error);
|
|
2857
|
+
}
|
|
2858
|
+
}, [key, state, getStorage]);
|
|
2859
|
+
return [state, setValue];
|
|
2860
|
+
}
|
|
2861
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2862
|
+
0 && (module.exports = {
|
|
2720
2863
|
ApiEngine,
|
|
2721
2864
|
ApiProvider,
|
|
2722
2865
|
AvatarSkeleton,
|
|
@@ -2762,5 +2905,4 @@ export {
|
|
|
2762
2905
|
usePluginManager,
|
|
2763
2906
|
useStorageState,
|
|
2764
2907
|
version
|
|
2765
|
-
};
|
|
2766
|
-
//# sourceMappingURL=index.mjs.map
|
|
2908
|
+
});
|