@chatbi-v/core 2.1.5 → 2.1.7
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-FF3Y2HHJ.js} +1 -1
- package/dist/{config-manager-3TKURRUT.mjs → config-manager-G2FCKELO.js} +2 -2
- package/dist/{index.mjs → index.cjs} +288 -145
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +104 -104
- package/dist/index.js +145 -288
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/dist/index.mjs.map +0 -1
- package/dist/{chunk-QET56C3T.mjs.map → chunk-FF3Y2HHJ.js.map} +0 -0
- package/dist/{config-manager-3TKURRUT.mjs.map → config-manager-G2FCKELO.js.map} +0 -0
- package/dist/{index.d.mts → index.d.cts} +104 -104
package/dist/index.js
CHANGED
|
@@ -1,142 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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);
|
|
1
|
+
import {
|
|
2
|
+
ConfigManager,
|
|
3
|
+
configManager
|
|
4
|
+
} from "./chunk-FF3Y2HHJ.js";
|
|
140
5
|
|
|
141
6
|
// src/ports/plugin-port.ts
|
|
142
7
|
var PLUGIN_TYPES = ["business", "functional", "view", "theme", "renderer", "system"];
|
|
@@ -171,6 +36,21 @@ function definePlugin(plugin) {
|
|
|
171
36
|
};
|
|
172
37
|
}
|
|
173
38
|
|
|
39
|
+
// src/api-context.tsx
|
|
40
|
+
import { createContext, useContext } from "react";
|
|
41
|
+
import { jsx } from "react/jsx-runtime";
|
|
42
|
+
var ApiContext = createContext(null);
|
|
43
|
+
var ApiProvider = ({ api, children }) => {
|
|
44
|
+
return /* @__PURE__ */ jsx(ApiContext.Provider, { value: api, children });
|
|
45
|
+
};
|
|
46
|
+
var useApi = () => {
|
|
47
|
+
const context = useContext(ApiContext);
|
|
48
|
+
if (!context) {
|
|
49
|
+
throw new Error("useApi must be used within an ApiProvider");
|
|
50
|
+
}
|
|
51
|
+
return context;
|
|
52
|
+
};
|
|
53
|
+
|
|
174
54
|
// src/utils/logger.ts
|
|
175
55
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
176
56
|
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
@@ -524,29 +404,11 @@ var ServiceRegistry = class {
|
|
|
524
404
|
};
|
|
525
405
|
var serviceRegistry = new ServiceRegistry();
|
|
526
406
|
|
|
527
|
-
// src/api-context.tsx
|
|
528
|
-
var import_react = require("react");
|
|
529
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
530
|
-
var ApiContext = (0, import_react.createContext)(null);
|
|
531
|
-
var ApiProvider = ({ api, children }) => {
|
|
532
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ApiContext.Provider, { value: api, children });
|
|
533
|
-
};
|
|
534
|
-
var useApi = () => {
|
|
535
|
-
const context = (0, import_react.useContext)(ApiContext);
|
|
536
|
-
if (!context) {
|
|
537
|
-
throw new Error("useApi must be used within an ApiProvider");
|
|
538
|
-
}
|
|
539
|
-
return context;
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
// src/index.ts
|
|
543
|
-
init_config_manager();
|
|
544
|
-
|
|
545
407
|
// src/components/PluginErrorBoundary.tsx
|
|
546
|
-
|
|
408
|
+
import { Component } from "react";
|
|
547
409
|
|
|
548
410
|
// src/domain/plugin-manager.ts
|
|
549
|
-
|
|
411
|
+
import { startTransition } from "react";
|
|
550
412
|
|
|
551
413
|
// src/adapters/local-storage-adapter.ts
|
|
552
414
|
var LocalStorageAdapter = class {
|
|
@@ -657,9 +519,6 @@ var LocalStorageAdapter = class {
|
|
|
657
519
|
}
|
|
658
520
|
};
|
|
659
521
|
|
|
660
|
-
// src/domain/plugin-manager.ts
|
|
661
|
-
init_config_manager();
|
|
662
|
-
|
|
663
522
|
// src/event-bus.ts
|
|
664
523
|
var logger3 = createLogger("EventBus");
|
|
665
524
|
var DefaultEventBus = class {
|
|
@@ -1212,7 +1071,6 @@ var ScopedStorageAdapter = class {
|
|
|
1212
1071
|
};
|
|
1213
1072
|
|
|
1214
1073
|
// src/domain/storage-manager.ts
|
|
1215
|
-
init_config_manager();
|
|
1216
1074
|
var StorageManager = class {
|
|
1217
1075
|
/** 底层物理存储驱动 */
|
|
1218
1076
|
baseStorage;
|
|
@@ -1456,7 +1314,7 @@ var PluginManager = class {
|
|
|
1456
1314
|
* @param affectedSlot - (可选) 受影响的插槽位置
|
|
1457
1315
|
*/
|
|
1458
1316
|
notify(affectedSlot) {
|
|
1459
|
-
|
|
1317
|
+
startTransition(() => {
|
|
1460
1318
|
if (affectedSlot) {
|
|
1461
1319
|
this.memoizedExtensions.delete(String(affectedSlot));
|
|
1462
1320
|
} else {
|
|
@@ -1946,9 +1804,9 @@ var PluginManager = class {
|
|
|
1946
1804
|
logger6.info("\u5F00\u59CB\u52A0\u8F7D\u63D2\u4EF6...");
|
|
1947
1805
|
const localLoadPromises = Object.entries(registry).map(async ([registryId, importFn]) => {
|
|
1948
1806
|
try {
|
|
1949
|
-
const
|
|
1807
|
+
const module = await importFn();
|
|
1950
1808
|
const config = configs[registryId];
|
|
1951
|
-
const plugin = this.instantiatePlugin(registryId,
|
|
1809
|
+
const plugin = this.instantiatePlugin(registryId, module, config);
|
|
1952
1810
|
if (plugin && config) {
|
|
1953
1811
|
configManager.set(plugin.id, config);
|
|
1954
1812
|
}
|
|
@@ -1994,8 +1852,8 @@ var PluginManager = class {
|
|
|
1994
1852
|
}
|
|
1995
1853
|
try {
|
|
1996
1854
|
const dynamicImport = new Function("specifier", "return import(specifier)");
|
|
1997
|
-
const
|
|
1998
|
-
return this.instantiatePlugin(pluginId,
|
|
1855
|
+
const module = await dynamicImport(url);
|
|
1856
|
+
return this.instantiatePlugin(pluginId, module, config);
|
|
1999
1857
|
} catch (e) {
|
|
2000
1858
|
logger6.warn(`ESM \u52A0\u8F7D\u5931\u8D25\uFF0C\u5C1D\u8BD5 IIFE \u52A0\u8F7D: ${pluginId}`);
|
|
2001
1859
|
return this.loadIIFEPlugin(pluginId, url, config);
|
|
@@ -2024,15 +1882,15 @@ var PluginManager = class {
|
|
|
2024
1882
|
/**
|
|
2025
1883
|
* 实例化插件
|
|
2026
1884
|
*/
|
|
2027
|
-
instantiatePlugin(pluginId,
|
|
2028
|
-
let PluginClass =
|
|
1885
|
+
instantiatePlugin(pluginId, module, config) {
|
|
1886
|
+
let PluginClass = module.default;
|
|
2029
1887
|
if (!PluginClass) {
|
|
2030
|
-
const key = Object.keys(
|
|
2031
|
-
if (key) PluginClass =
|
|
1888
|
+
const key = Object.keys(module).find((k) => k.endsWith("Plugin"));
|
|
1889
|
+
if (key) PluginClass = module[key];
|
|
2032
1890
|
}
|
|
2033
|
-
if (!PluginClass && typeof
|
|
2034
|
-
if (
|
|
2035
|
-
PluginClass =
|
|
1891
|
+
if (!PluginClass && typeof module === "object") {
|
|
1892
|
+
if (module.id && module.metadata) {
|
|
1893
|
+
PluginClass = module;
|
|
2036
1894
|
}
|
|
2037
1895
|
}
|
|
2038
1896
|
if (PluginClass) {
|
|
@@ -2081,9 +1939,9 @@ var PluginManager = class {
|
|
|
2081
1939
|
var pluginManager = new PluginManager(new LocalStorageAdapter());
|
|
2082
1940
|
|
|
2083
1941
|
// src/components/PluginErrorBoundary.tsx
|
|
2084
|
-
|
|
1942
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
2085
1943
|
var logger7 = createLogger("PluginErrorBoundary");
|
|
2086
|
-
var PluginErrorBoundary = class extends
|
|
1944
|
+
var PluginErrorBoundary = class extends Component {
|
|
2087
1945
|
constructor(props) {
|
|
2088
1946
|
super(props);
|
|
2089
1947
|
this.state = { hasError: false, error: null };
|
|
@@ -2127,7 +1985,7 @@ var PluginErrorBoundary = class extends import_react3.Component {
|
|
|
2127
1985
|
if (this.props.silent) {
|
|
2128
1986
|
return null;
|
|
2129
1987
|
}
|
|
2130
|
-
return /* @__PURE__ */ (
|
|
1988
|
+
return /* @__PURE__ */ jsx2(
|
|
2131
1989
|
"div",
|
|
2132
1990
|
{
|
|
2133
1991
|
className: "plugin-error-placeholder hidden",
|
|
@@ -2141,33 +1999,33 @@ var PluginErrorBoundary = class extends import_react3.Component {
|
|
|
2141
1999
|
};
|
|
2142
2000
|
|
|
2143
2001
|
// src/components/PluginSlot.tsx
|
|
2144
|
-
|
|
2002
|
+
import { startTransition as startTransition2, Suspense, useEffect, useMemo, useState } from "react";
|
|
2145
2003
|
|
|
2146
2004
|
// src/components/SlotSkeletons.tsx
|
|
2147
|
-
|
|
2148
|
-
var SidebarIconSkeleton = ({ expanded = false }) => /* @__PURE__ */
|
|
2005
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
2006
|
+
var SidebarIconSkeleton = ({ expanded = false }) => /* @__PURE__ */ jsxs("div", { className: `flex items-center transition-all duration-300 relative
|
|
2149
2007
|
${expanded ? "w-full" : "w-12 justify-center"} px-3 h-11 rounded-xl`, children: [
|
|
2150
|
-
/* @__PURE__ */ (
|
|
2151
|
-
expanded && /* @__PURE__ */ (
|
|
2008
|
+
/* @__PURE__ */ jsx3("div", { className: "w-6 h-6 bg-slate-200 dark:bg-white/10 rounded-lg shrink-0 animate-pulse" }),
|
|
2009
|
+
expanded && /* @__PURE__ */ jsx3("div", { className: "ml-3 flex-1 h-4 bg-slate-200 dark:bg-white/10 rounded animate-pulse" })
|
|
2152
2010
|
] });
|
|
2153
|
-
var StatusBarItemSkeleton = () => /* @__PURE__ */ (
|
|
2154
|
-
var AvatarSkeleton = () => /* @__PURE__ */ (
|
|
2155
|
-
var BlockSkeleton = ({ className }) => /* @__PURE__ */ (
|
|
2011
|
+
var StatusBarItemSkeleton = () => /* @__PURE__ */ jsx3("div", { className: "h-4 w-16 bg-slate-200 dark:bg-white/10 rounded animate-pulse" });
|
|
2012
|
+
var AvatarSkeleton = () => /* @__PURE__ */ jsx3("div", { className: "w-10 h-10 rounded-full bg-slate-200 dark:bg-white/10 animate-pulse" });
|
|
2013
|
+
var BlockSkeleton = ({ className }) => /* @__PURE__ */ jsx3("div", { className: `bg-slate-200 dark:bg-white/10 rounded animate-pulse ${className || "w-full h-full"}` });
|
|
2156
2014
|
var SlotSkeletons = ({ slot, expanded }) => {
|
|
2157
2015
|
if (slot.includes("sidebar")) {
|
|
2158
|
-
return /* @__PURE__ */ (
|
|
2016
|
+
return /* @__PURE__ */ jsx3(SidebarIconSkeleton, { expanded });
|
|
2159
2017
|
}
|
|
2160
2018
|
if (slot.includes("status")) {
|
|
2161
|
-
return /* @__PURE__ */ (
|
|
2019
|
+
return /* @__PURE__ */ jsx3(StatusBarItemSkeleton, {});
|
|
2162
2020
|
}
|
|
2163
2021
|
if (slot.includes("avatar")) {
|
|
2164
|
-
return /* @__PURE__ */ (
|
|
2022
|
+
return /* @__PURE__ */ jsx3(AvatarSkeleton, {});
|
|
2165
2023
|
}
|
|
2166
|
-
return /* @__PURE__ */ (
|
|
2024
|
+
return /* @__PURE__ */ jsx3(BlockSkeleton, {});
|
|
2167
2025
|
};
|
|
2168
2026
|
|
|
2169
2027
|
// src/components/PluginSlot.tsx
|
|
2170
|
-
|
|
2028
|
+
import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
|
|
2171
2029
|
var ExtensionLoader = ({ pluginId, component: Component2, props }) => {
|
|
2172
2030
|
const status = pluginManager.getPluginRuntimeStatus(pluginId);
|
|
2173
2031
|
if (status !== "mounted") {
|
|
@@ -2177,7 +2035,7 @@ var ExtensionLoader = ({ pluginId, component: Component2, props }) => {
|
|
|
2177
2035
|
}
|
|
2178
2036
|
throw pluginManager.mountPlugin(pluginId);
|
|
2179
2037
|
}
|
|
2180
|
-
return /* @__PURE__ */ (
|
|
2038
|
+
return /* @__PURE__ */ jsx4(Component2, { ...props });
|
|
2181
2039
|
};
|
|
2182
2040
|
var PluginSlot = ({
|
|
2183
2041
|
slot,
|
|
@@ -2188,10 +2046,10 @@ var PluginSlot = ({
|
|
|
2188
2046
|
skeleton,
|
|
2189
2047
|
fallback
|
|
2190
2048
|
}) => {
|
|
2191
|
-
const [, forceUpdate] =
|
|
2192
|
-
|
|
2049
|
+
const [, forceUpdate] = useState({});
|
|
2050
|
+
useEffect(() => {
|
|
2193
2051
|
const unsubscribe = pluginManager.subscribe(() => {
|
|
2194
|
-
(
|
|
2052
|
+
startTransition2(() => {
|
|
2195
2053
|
forceUpdate({});
|
|
2196
2054
|
});
|
|
2197
2055
|
}, slot);
|
|
@@ -2203,18 +2061,18 @@ var PluginSlot = ({
|
|
|
2203
2061
|
logo: pluginManager.getSystemConfig("logo"),
|
|
2204
2062
|
version: pluginManager.getSystemConfig("version")
|
|
2205
2063
|
} : void 0;
|
|
2206
|
-
const mergedProps =
|
|
2064
|
+
const mergedProps = useMemo(() => ({
|
|
2207
2065
|
...props,
|
|
2208
2066
|
systemConfig
|
|
2209
2067
|
}), [props, systemConfig]);
|
|
2210
|
-
const items =
|
|
2068
|
+
const items = useMemo(() => {
|
|
2211
2069
|
return extensions.map((ext, index) => {
|
|
2212
2070
|
const Component2 = ext.component;
|
|
2213
2071
|
const key = ext.meta?.key || `${ext.slot}-${ext.order || 0}-${index}`;
|
|
2214
2072
|
return {
|
|
2215
2073
|
key,
|
|
2216
2074
|
extension: ext,
|
|
2217
|
-
component: /* @__PURE__ */ (
|
|
2075
|
+
component: /* @__PURE__ */ jsx4(PluginErrorBoundary, { pluginId: ext._pluginId, children: /* @__PURE__ */ jsx4(Suspense, { fallback: skeleton || /* @__PURE__ */ jsx4(SlotSkeletons, { slot }), children: /* @__PURE__ */ jsx4(
|
|
2218
2076
|
ExtensionLoader,
|
|
2219
2077
|
{
|
|
2220
2078
|
pluginId: ext._pluginId || "",
|
|
@@ -2227,17 +2085,17 @@ var PluginSlot = ({
|
|
|
2227
2085
|
}, [extensions, mergedProps]);
|
|
2228
2086
|
if (items.length === 0) {
|
|
2229
2087
|
if (fallback) {
|
|
2230
|
-
return /* @__PURE__ */ (
|
|
2088
|
+
return /* @__PURE__ */ jsx4(Fragment, { children: fallback });
|
|
2231
2089
|
}
|
|
2232
2090
|
if (skeleton) {
|
|
2233
|
-
return /* @__PURE__ */ (
|
|
2091
|
+
return /* @__PURE__ */ jsx4("div", { className: `plugin-slot plugin-slot-${slot} plugin-slot-skeleton ${className || ""}`, style, children: skeleton });
|
|
2234
2092
|
}
|
|
2235
2093
|
return null;
|
|
2236
2094
|
}
|
|
2237
2095
|
if (items.length === 1 && slot === "root-layout" && !className && !style && !renderItem) {
|
|
2238
|
-
return /* @__PURE__ */ (
|
|
2096
|
+
return /* @__PURE__ */ jsx4(Fragment, { children: items[0].component });
|
|
2239
2097
|
}
|
|
2240
|
-
return /* @__PURE__ */ (
|
|
2098
|
+
return /* @__PURE__ */ jsx4("div", { className: `plugin-slot plugin-slot-${slot} ${className || ""}`, style, children: renderItem ? items.map((item, index) => renderItem(item, index)) : items.map((item) => item.component) });
|
|
2241
2099
|
};
|
|
2242
2100
|
|
|
2243
2101
|
// src/domain/auto-loader.ts
|
|
@@ -2284,27 +2142,12 @@ var resolvePluginRegistry = (options) => {
|
|
|
2284
2142
|
// src/domain/models.ts
|
|
2285
2143
|
var SUCCESS_CODE = "000000";
|
|
2286
2144
|
|
|
2287
|
-
// src/plugin-context.tsx
|
|
2288
|
-
var import_react5 = require("react");
|
|
2289
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
2290
|
-
var PluginContext = (0, import_react5.createContext)(null);
|
|
2291
|
-
var PluginProvider = ({ manager, children }) => {
|
|
2292
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PluginContext.Provider, { value: manager, children });
|
|
2293
|
-
};
|
|
2294
|
-
var usePluginManager = () => {
|
|
2295
|
-
const context = (0, import_react5.useContext)(PluginContext);
|
|
2296
|
-
if (!context) {
|
|
2297
|
-
throw new Error("usePluginManager must be used within a PluginProvider");
|
|
2298
|
-
}
|
|
2299
|
-
return context;
|
|
2300
|
-
};
|
|
2301
|
-
|
|
2302
2145
|
// src/api/adapters/axios-adapter.ts
|
|
2303
|
-
|
|
2146
|
+
import axios from "axios";
|
|
2304
2147
|
var AxiosAdapter = class {
|
|
2305
2148
|
client;
|
|
2306
2149
|
constructor(baseURL = "/api", timeout = 1e4) {
|
|
2307
|
-
this.client =
|
|
2150
|
+
this.client = axios.create({
|
|
2308
2151
|
baseURL,
|
|
2309
2152
|
timeout
|
|
2310
2153
|
});
|
|
@@ -2424,8 +2267,8 @@ var ApiEngine = class {
|
|
|
2424
2267
|
/**
|
|
2425
2268
|
* 获取接口配置
|
|
2426
2269
|
*/
|
|
2427
|
-
getEndpoint(
|
|
2428
|
-
return this.config[
|
|
2270
|
+
getEndpoint(module, action) {
|
|
2271
|
+
return this.config[module]?.[action];
|
|
2429
2272
|
}
|
|
2430
2273
|
/**
|
|
2431
2274
|
* 发起 API 请求
|
|
@@ -2434,10 +2277,10 @@ var ApiEngine = class {
|
|
|
2434
2277
|
* @param data 请求数据 (Body 或 Query)
|
|
2435
2278
|
* @param options 请求选项
|
|
2436
2279
|
*/
|
|
2437
|
-
async call(
|
|
2438
|
-
const endpoint = this.getEndpoint(
|
|
2280
|
+
async call(module, action, data, options = {}) {
|
|
2281
|
+
const endpoint = this.getEndpoint(module, action);
|
|
2439
2282
|
if (!endpoint) {
|
|
2440
|
-
logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${
|
|
2283
|
+
logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${module}.${action} (\u5F53\u524D\u5DF2\u6CE8\u518C\u6A21\u5757: ${Object.keys(this.config).join(", ")})`);
|
|
2441
2284
|
return Promise.resolve(void 0);
|
|
2442
2285
|
}
|
|
2443
2286
|
const requestConfig = await this.prepareRequestConfig(endpoint, data, options);
|
|
@@ -2453,12 +2296,12 @@ var ApiEngine = class {
|
|
|
2453
2296
|
}
|
|
2454
2297
|
const hijacked = await this.applyResponseInterceptors(response, requestConfig);
|
|
2455
2298
|
if (hijacked) {
|
|
2456
|
-
logger9.info("\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:",
|
|
2299
|
+
logger9.info("\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:", module, action);
|
|
2457
2300
|
return void 0;
|
|
2458
2301
|
}
|
|
2459
2302
|
this.checkHttpStatus(response);
|
|
2460
2303
|
const responseData = this.extractResponseData(response);
|
|
2461
|
-
this.handleBusinessError(responseData, endpoint,
|
|
2304
|
+
this.handleBusinessError(responseData, endpoint, module, action);
|
|
2462
2305
|
return responseData;
|
|
2463
2306
|
}
|
|
2464
2307
|
/**
|
|
@@ -2468,10 +2311,10 @@ var ApiEngine = class {
|
|
|
2468
2311
|
* @param data 请求数据
|
|
2469
2312
|
* @param options 请求选项
|
|
2470
2313
|
*/
|
|
2471
|
-
async stream(
|
|
2472
|
-
const endpoint = this.getEndpoint(
|
|
2314
|
+
async stream(module, action, data, options = {}) {
|
|
2315
|
+
const endpoint = this.getEndpoint(module, action);
|
|
2473
2316
|
if (!endpoint) {
|
|
2474
|
-
logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${
|
|
2317
|
+
logger9.warn(`\u672A\u627E\u5230 API \u5B9A\u4E49: ${module}.${action}\uFF0C\u8DF3\u8FC7\u6D41\u5F0F\u8BF7\u6C42\u3002`);
|
|
2475
2318
|
return;
|
|
2476
2319
|
}
|
|
2477
2320
|
if (!this.adapter.stream) {
|
|
@@ -2492,7 +2335,7 @@ var ApiEngine = class {
|
|
|
2492
2335
|
onResponse: async (response) => {
|
|
2493
2336
|
const hijacked = await this.applyResponseInterceptors(response, requestConfig);
|
|
2494
2337
|
if (hijacked) {
|
|
2495
|
-
logger9.info("\u6D41\u5F0F\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:",
|
|
2338
|
+
logger9.info("\u6D41\u5F0F\u8BF7\u6C42\u88AB\u62E6\u622A\u5668\u52AB\u6301:", module, action);
|
|
2496
2339
|
if (requestConfig.signal instanceof AbortController) {
|
|
2497
2340
|
requestConfig.signal.abort();
|
|
2498
2341
|
}
|
|
@@ -2583,7 +2426,7 @@ var ApiEngine = class {
|
|
|
2583
2426
|
/**
|
|
2584
2427
|
* 处理业务错误
|
|
2585
2428
|
*/
|
|
2586
|
-
handleBusinessError(responseData, endpoint,
|
|
2429
|
+
handleBusinessError(responseData, endpoint, module, action) {
|
|
2587
2430
|
if (!this.isBaseResponse(responseData)) return;
|
|
2588
2431
|
const res = responseData;
|
|
2589
2432
|
const code = String(res.code);
|
|
@@ -2591,7 +2434,7 @@ var ApiEngine = class {
|
|
|
2591
2434
|
if (!isSuccess) {
|
|
2592
2435
|
const strategy = endpoint.errorStrategy || "reject";
|
|
2593
2436
|
if (strategy === "reject") {
|
|
2594
|
-
logger9.error(`API \u8BF7\u6C42\u4E1A\u52A1\u9519\u8BEF (${
|
|
2437
|
+
logger9.error(`API \u8BF7\u6C42\u4E1A\u52A1\u9519\u8BEF (${module}.${action}):`, res.message);
|
|
2595
2438
|
throw new Error(res.message || `Request failed with code ${code}`);
|
|
2596
2439
|
}
|
|
2597
2440
|
}
|
|
@@ -2710,11 +2553,11 @@ function resolveApiModules(definitionsMap, mocksMap = {}) {
|
|
|
2710
2553
|
const fileName = path.split("/").pop() || "";
|
|
2711
2554
|
return fileName.replace(/\.mock\.(ts|js|tsx|jsx|json)$/, "").replace(/\.(ts|js|tsx|jsx|json)$/, "");
|
|
2712
2555
|
};
|
|
2713
|
-
Object.entries(definitionsMap).forEach(([path,
|
|
2556
|
+
Object.entries(definitionsMap).forEach(([path, module]) => {
|
|
2714
2557
|
if (path.includes(".mock.")) return;
|
|
2715
2558
|
const namespace = getNamespace(path);
|
|
2716
|
-
if (!namespace || !
|
|
2717
|
-
let apiDef =
|
|
2559
|
+
if (!namespace || !module.default) return;
|
|
2560
|
+
let apiDef = module.default;
|
|
2718
2561
|
const mockEntry = Object.entries(mocksMap).find(([mockPath]) => {
|
|
2719
2562
|
return getNamespace(mockPath) === namespace && mockPath.includes(".mock.");
|
|
2720
2563
|
});
|
|
@@ -2730,93 +2573,75 @@ function resolveApiModules(definitionsMap, mocksMap = {}) {
|
|
|
2730
2573
|
return config;
|
|
2731
2574
|
}
|
|
2732
2575
|
|
|
2576
|
+
// src/plugin-context.tsx
|
|
2577
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
2578
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
2579
|
+
var PluginContext = createContext2(null);
|
|
2580
|
+
var PluginProvider = ({ manager, children }) => {
|
|
2581
|
+
return /* @__PURE__ */ jsx5(PluginContext.Provider, { value: manager, children });
|
|
2582
|
+
};
|
|
2583
|
+
var usePluginManager = () => {
|
|
2584
|
+
const context = useContext2(PluginContext);
|
|
2585
|
+
if (!context) {
|
|
2586
|
+
throw new Error("usePluginManager must be used within a PluginProvider");
|
|
2587
|
+
}
|
|
2588
|
+
return context;
|
|
2589
|
+
};
|
|
2590
|
+
|
|
2733
2591
|
// src/utils/date.ts
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2592
|
+
import "dayjs/locale/zh-cn";
|
|
2593
|
+
import dayjs from "dayjs";
|
|
2594
|
+
import relativeTime from "dayjs/plugin/relativeTime";
|
|
2595
|
+
dayjs.extend(relativeTime);
|
|
2596
|
+
dayjs.locale("zh-cn");
|
|
2739
2597
|
var dateUtils = {
|
|
2740
2598
|
/**
|
|
2741
2599
|
* 格式化日期为 YYYY-MM-DD
|
|
2742
2600
|
*/
|
|
2743
2601
|
formatDate(date) {
|
|
2744
|
-
return (
|
|
2602
|
+
return dayjs(date).format("YYYY-MM-DD");
|
|
2745
2603
|
},
|
|
2746
2604
|
/**
|
|
2747
2605
|
* 格式化时间为 HH:mm:ss
|
|
2748
2606
|
*/
|
|
2749
2607
|
formatTime(date) {
|
|
2750
|
-
return (
|
|
2608
|
+
return dayjs(date).format("HH:mm:ss");
|
|
2751
2609
|
},
|
|
2752
2610
|
/**
|
|
2753
2611
|
* 格式化日期时间为 YYYY-MM-DD HH:mm:ss
|
|
2754
2612
|
*/
|
|
2755
2613
|
formatDateTime(date) {
|
|
2756
|
-
return (
|
|
2614
|
+
return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
|
|
2757
2615
|
},
|
|
2758
2616
|
/**
|
|
2759
2617
|
* 获取当前时间戳(毫秒)
|
|
2760
2618
|
*/
|
|
2761
2619
|
now() {
|
|
2762
|
-
return (
|
|
2620
|
+
return dayjs().valueOf();
|
|
2763
2621
|
},
|
|
2764
2622
|
/**
|
|
2765
2623
|
* 获取相对时间(例如:几分钟前)
|
|
2766
2624
|
*/
|
|
2767
2625
|
fromNow(date) {
|
|
2768
|
-
return (
|
|
2626
|
+
return dayjs(date).fromNow();
|
|
2769
2627
|
},
|
|
2770
2628
|
/**
|
|
2771
2629
|
* 原始 dayjs 对象,用于更复杂的场景
|
|
2772
2630
|
*/
|
|
2773
|
-
dayjs
|
|
2631
|
+
dayjs
|
|
2774
2632
|
};
|
|
2775
2633
|
|
|
2776
2634
|
// src/utils/index.ts
|
|
2777
2635
|
var version = "1.0.0";
|
|
2778
2636
|
|
|
2779
|
-
// src/hooks/use-storage-state.ts
|
|
2780
|
-
var import_react6 = require("react");
|
|
2781
|
-
function useStorageState(pluginId, key, options = {}) {
|
|
2782
|
-
const { defaultValue, scope = "plugin" } = options;
|
|
2783
|
-
const storageManager = pluginManager.getStorageManager();
|
|
2784
|
-
const getStorage = (0, import_react6.useCallback)(() => {
|
|
2785
|
-
const contextStorage = storageManager.getContextStorage(pluginId);
|
|
2786
|
-
return scope === "shared" ? contextStorage.shared : contextStorage;
|
|
2787
|
-
}, [pluginId, scope, storageManager]);
|
|
2788
|
-
const [state, setState] = (0, import_react6.useState)(() => {
|
|
2789
|
-
try {
|
|
2790
|
-
if (typeof window === "undefined") return defaultValue;
|
|
2791
|
-
const storage = getStorage();
|
|
2792
|
-
const val = storage.get(key);
|
|
2793
|
-
return val !== null ? val : defaultValue;
|
|
2794
|
-
} catch (e) {
|
|
2795
|
-
console.warn(`[useStorageState] \u8BFB\u53D6 Key "${key}" \u5931\u8D25`, e);
|
|
2796
|
-
return defaultValue;
|
|
2797
|
-
}
|
|
2798
|
-
});
|
|
2799
|
-
const setValue = (0, import_react6.useCallback)((value) => {
|
|
2800
|
-
try {
|
|
2801
|
-
const valueToStore = value instanceof Function ? value(state) : value;
|
|
2802
|
-
setState(valueToStore);
|
|
2803
|
-
const storage = getStorage();
|
|
2804
|
-
storage.set(key, valueToStore);
|
|
2805
|
-
} catch (error) {
|
|
2806
|
-
console.warn(`[useStorageState] \u8BBE\u7F6E Key "${key}" \u5931\u8D25:`, error);
|
|
2807
|
-
}
|
|
2808
|
-
}, [key, state, getStorage]);
|
|
2809
|
-
return [state, setValue];
|
|
2810
|
-
}
|
|
2811
|
-
|
|
2812
2637
|
// src/hooks/use-plugin-loader.ts
|
|
2813
|
-
|
|
2638
|
+
import { useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
2814
2639
|
var logger10 = createLogger("PluginLoader");
|
|
2815
2640
|
var usePluginLoader = (options) => {
|
|
2816
|
-
const [pluginsLoaded, setPluginsLoaded] = (
|
|
2817
|
-
const [pluginVersion, setPluginVersion] = (0
|
|
2818
|
-
const loadingRef =
|
|
2819
|
-
(
|
|
2641
|
+
const [pluginsLoaded, setPluginsLoaded] = useState2(false);
|
|
2642
|
+
const [pluginVersion, setPluginVersion] = useState2(0);
|
|
2643
|
+
const loadingRef = useRef(false);
|
|
2644
|
+
useEffect2(() => {
|
|
2820
2645
|
const unsubscribe = pluginManager.subscribe(() => {
|
|
2821
2646
|
logger10.debug("Plugin state changed, refreshing UI...");
|
|
2822
2647
|
setPluginVersion((v) => v + 1);
|
|
@@ -2840,7 +2665,7 @@ var usePluginLoader = (options) => {
|
|
|
2840
2665
|
}) : {};
|
|
2841
2666
|
const finalRegistry = { ...discoveredRegistry, ...manualRegistry };
|
|
2842
2667
|
if (options.systemConfig) {
|
|
2843
|
-
const { configManager: configManager2 } = await
|
|
2668
|
+
const { configManager: configManager2 } = await import("./config-manager-G2FCKELO.js");
|
|
2844
2669
|
configManager2.set("system", options.systemConfig);
|
|
2845
2670
|
}
|
|
2846
2671
|
await pluginManager.loadPlugins(pluginConfigs, finalRegistry, false);
|
|
@@ -2858,8 +2683,40 @@ var usePluginLoader = (options) => {
|
|
|
2858
2683
|
}, []);
|
|
2859
2684
|
return { pluginsLoaded, pluginVersion };
|
|
2860
2685
|
};
|
|
2861
|
-
|
|
2862
|
-
|
|
2686
|
+
|
|
2687
|
+
// src/hooks/use-storage-state.ts
|
|
2688
|
+
import { useCallback, useState as useState3 } from "react";
|
|
2689
|
+
function useStorageState(pluginId, key, options = {}) {
|
|
2690
|
+
const { defaultValue, scope = "plugin" } = options;
|
|
2691
|
+
const storageManager = pluginManager.getStorageManager();
|
|
2692
|
+
const getStorage = useCallback(() => {
|
|
2693
|
+
const contextStorage = storageManager.getContextStorage(pluginId);
|
|
2694
|
+
return scope === "shared" ? contextStorage.shared : contextStorage;
|
|
2695
|
+
}, [pluginId, scope, storageManager]);
|
|
2696
|
+
const [state, setState] = useState3(() => {
|
|
2697
|
+
try {
|
|
2698
|
+
if (typeof window === "undefined") return defaultValue;
|
|
2699
|
+
const storage = getStorage();
|
|
2700
|
+
const val = storage.get(key);
|
|
2701
|
+
return val !== null ? val : defaultValue;
|
|
2702
|
+
} catch (e) {
|
|
2703
|
+
console.warn(`[useStorageState] \u8BFB\u53D6 Key "${key}" \u5931\u8D25`, e);
|
|
2704
|
+
return defaultValue;
|
|
2705
|
+
}
|
|
2706
|
+
});
|
|
2707
|
+
const setValue = useCallback((value) => {
|
|
2708
|
+
try {
|
|
2709
|
+
const valueToStore = value instanceof Function ? value(state) : value;
|
|
2710
|
+
setState(valueToStore);
|
|
2711
|
+
const storage = getStorage();
|
|
2712
|
+
storage.set(key, valueToStore);
|
|
2713
|
+
} catch (error) {
|
|
2714
|
+
console.warn(`[useStorageState] \u8BBE\u7F6E Key "${key}" \u5931\u8D25:`, error);
|
|
2715
|
+
}
|
|
2716
|
+
}, [key, state, getStorage]);
|
|
2717
|
+
return [state, setValue];
|
|
2718
|
+
}
|
|
2719
|
+
export {
|
|
2863
2720
|
ApiEngine,
|
|
2864
2721
|
ApiProvider,
|
|
2865
2722
|
AvatarSkeleton,
|
|
@@ -2905,5 +2762,5 @@ var usePluginLoader = (options) => {
|
|
|
2905
2762
|
usePluginManager,
|
|
2906
2763
|
useStorageState,
|
|
2907
2764
|
version
|
|
2908
|
-
}
|
|
2765
|
+
};
|
|
2909
2766
|
//# sourceMappingURL=index.js.map
|