@zhin.js/console 1.0.5 → 1.0.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/app/index.ts +419 -0
- package/client/index.html +13 -0
- package/client/postcss.config.js +5 -0
- package/client/src/components/PluginConfigForm/BasicFieldRenderers.tsx +253 -0
- package/client/src/components/PluginConfigForm/CollectionFieldRenderers.tsx +261 -0
- package/client/src/components/PluginConfigForm/CompositeFieldRenderers.tsx +105 -0
- package/client/src/components/PluginConfigForm/FieldRenderer.tsx +110 -0
- package/client/src/components/PluginConfigForm/NestedFieldRenderer.tsx +95 -0
- package/client/src/components/PluginConfigForm/index.tsx +237 -0
- package/client/src/components/PluginConfigForm/types.ts +46 -0
- package/client/src/components/ThemeToggle.tsx +21 -0
- package/client/src/hooks/useTheme.ts +17 -0
- package/client/src/layouts/dashboard.tsx +259 -0
- package/client/src/main.tsx +121 -0
- package/client/src/pages/dashboard-bots.tsx +198 -0
- package/client/src/pages/dashboard-home.tsx +301 -0
- package/client/src/pages/dashboard-logs.tsx +298 -0
- package/client/src/pages/dashboard-plugin-detail.tsx +360 -0
- package/client/src/pages/dashboard-plugins.tsx +166 -0
- package/client/src/style.css +1105 -0
- package/client/src/theme/index.ts +92 -0
- package/client/tailwind.config.js +70 -0
- package/client/tsconfig.json +17 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +210 -47
- package/lib/index.js.map +1 -1
- package/package.json +22 -10
- package/src/index.ts +0 -206
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/console",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Zhin 控制台",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./lib/index.d.ts",
|
|
11
11
|
"import": "./lib/index.js"
|
|
12
|
-
}
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./lib/client/index.d.ts",
|
|
15
|
+
"import": "./lib/client/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./browser.tsconfig.json": "./client/tsconfig.json"
|
|
13
18
|
},
|
|
14
19
|
"dependencies": {
|
|
15
20
|
"react": "19.2.0",
|
|
@@ -18,17 +23,25 @@
|
|
|
18
23
|
"@tailwindcss/vite": "4.1.14",
|
|
19
24
|
"radix-ui": "^1.4.3",
|
|
20
25
|
"@radix-ui/themes": "^3.2.1",
|
|
21
|
-
"
|
|
26
|
+
"@tailwindcss/postcss": "^4.1.11",
|
|
27
|
+
"tailwindcss": "latest",
|
|
22
28
|
"koa-connect": "^2.1.0",
|
|
29
|
+
"@reduxjs/toolkit": "^2.9.0",
|
|
30
|
+
"lucide-react": "^0.469.0",
|
|
31
|
+
"clsx": "^2.1.1",
|
|
32
|
+
"react-redux": "9.2.0",
|
|
33
|
+
"react-router": "7.0.0",
|
|
34
|
+
"redux-persist": "6.0.0",
|
|
35
|
+
"tailwind-merge": "^3.3.1",
|
|
23
36
|
"ws": "^8.18.3",
|
|
24
37
|
"vite": "^7.0.6"
|
|
25
38
|
},
|
|
26
39
|
"peerDependencies": {
|
|
27
40
|
"@types/ws": "^8.18.1",
|
|
28
|
-
"@zhin.js/client": "^1.0.
|
|
29
|
-
"@zhin.js/
|
|
30
|
-
"@zhin.js/
|
|
31
|
-
"@zhin.js/
|
|
41
|
+
"@zhin.js/client": "^1.0.5",
|
|
42
|
+
"@zhin.js/types": "^1.0.3",
|
|
43
|
+
"@zhin.js/http": "^1.0.6",
|
|
44
|
+
"@zhin.js/core": "^1.0.9"
|
|
32
45
|
},
|
|
33
46
|
"peerDependenciesMeta": {
|
|
34
47
|
"@zhin.js/types": {
|
|
@@ -37,9 +50,8 @@
|
|
|
37
50
|
},
|
|
38
51
|
"files": [
|
|
39
52
|
"lib",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"app"
|
|
53
|
+
"app",
|
|
54
|
+
"client"
|
|
43
55
|
],
|
|
44
56
|
"scripts": {
|
|
45
57
|
"build": "tsc",
|
package/src/index.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import {register, useContext} from '@zhin.js/core';
|
|
2
|
-
import react from '@vitejs/plugin-react';
|
|
3
|
-
import WebSocket,{WebSocketServer} from 'ws';
|
|
4
|
-
import {createServer,ViteDevServer,searchForWorkspaceRoot} from 'vite';
|
|
5
|
-
import connect from 'koa-connect';
|
|
6
|
-
import * as fs from 'fs';
|
|
7
|
-
import * as path from 'path';
|
|
8
|
-
import {fileURLToPath} from "node:url";
|
|
9
|
-
import tailwindcss from '@tailwindcss/vite';
|
|
10
|
-
|
|
11
|
-
declare module '@zhin.js/types' {
|
|
12
|
-
interface GlobalContext {
|
|
13
|
-
web: WebServer;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export type WebEntry=string|{
|
|
17
|
-
production:string
|
|
18
|
-
development:string
|
|
19
|
-
}
|
|
20
|
-
export type WebServer = {
|
|
21
|
-
vite:ViteDevServer,
|
|
22
|
-
addEntry(entry: WebEntry): () => void;
|
|
23
|
-
entries: Record<string, string>;
|
|
24
|
-
ws:WebSocketServer
|
|
25
|
-
};
|
|
26
|
-
const createSyncMsg = (key: string, value: any) => {
|
|
27
|
-
return {
|
|
28
|
-
type: 'sync',
|
|
29
|
-
data: {
|
|
30
|
-
key,
|
|
31
|
-
value,
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
const createAddMsg = (key: string, value: any) => {
|
|
36
|
-
return {
|
|
37
|
-
type: 'add',
|
|
38
|
-
data: {
|
|
39
|
-
key,
|
|
40
|
-
value,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
const createDeleteMsg = (key: string, value: any) => {
|
|
45
|
-
return {
|
|
46
|
-
type: 'delete',
|
|
47
|
-
data: {
|
|
48
|
-
key,
|
|
49
|
-
value,
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
useContext('router', async (router) => {
|
|
54
|
-
const root = path.join(process.cwd(),'node_modules','@zhin.js','client','app');
|
|
55
|
-
const base='/vite/'
|
|
56
|
-
|
|
57
|
-
const vite = await createServer({
|
|
58
|
-
root,
|
|
59
|
-
base,
|
|
60
|
-
plugins: [
|
|
61
|
-
react(),
|
|
62
|
-
tailwindcss(),
|
|
63
|
-
],
|
|
64
|
-
server: {
|
|
65
|
-
middlewareMode: true,
|
|
66
|
-
fs: {
|
|
67
|
-
strict:false
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
resolve: {
|
|
71
|
-
dedupe: ['react', 'react-dom'],
|
|
72
|
-
alias: {
|
|
73
|
-
'@zhin.js/client': path.resolve(root, '../src'),
|
|
74
|
-
'@': path.resolve(root, 'src'),
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
optimizeDeps: {
|
|
78
|
-
include: ['react', 'react-dom'],
|
|
79
|
-
},
|
|
80
|
-
build: {
|
|
81
|
-
rollupOptions: {
|
|
82
|
-
input: root + '/index.html',
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// Vite 中间件 - 必须在其他路由之前
|
|
88
|
-
router.use((ctx: any, next: any) => {
|
|
89
|
-
if(ctx.request.originalUrl.startsWith('/api')) return next()
|
|
90
|
-
return connect(vite.middlewares)(ctx,next);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// SPA 回退路由 - 处理所有未匹配的路由
|
|
94
|
-
router.all('*all', async (ctx, next) => {
|
|
95
|
-
const url = ctx.request.originalUrl.replace(base, '')
|
|
96
|
-
const name = ctx.path.slice(1);
|
|
97
|
-
|
|
98
|
-
const sendFile = (filename: string) => {
|
|
99
|
-
ctx.type = path.extname(filename);
|
|
100
|
-
if (filename.endsWith('.ts')) ctx.type = 'text/javascript';
|
|
101
|
-
return (ctx.body = fs.createReadStream(filename));
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// 1. 检查是否是动态入口
|
|
105
|
-
if (Object.keys(webServer.entries).includes(name)) {
|
|
106
|
-
return sendFile(path.resolve(process.cwd(), webServer.entries[name]));
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// 2. 检查是否是静态文件
|
|
110
|
-
const filename = path.resolve(root, name);
|
|
111
|
-
if (filename.startsWith(root) || filename.includes('node_modules')) {
|
|
112
|
-
if (fs.existsSync(filename)) {
|
|
113
|
-
const fileState = fs.statSync(filename);
|
|
114
|
-
if (fileState.isFile()) {
|
|
115
|
-
return sendFile(filename);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
// 安全检查:路径不在允许范围内
|
|
120
|
-
return (ctx.status = 403);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// 3. 所有其他路径(包括 SPA 路由)都返回 index.html
|
|
124
|
-
// 这样前端路由可以正确处理
|
|
125
|
-
const template = fs.readFileSync(path.resolve(root, 'index.html'), 'utf8');
|
|
126
|
-
ctx.type = 'html';
|
|
127
|
-
ctx.body = await vite.transformIndexHtml(url, template);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
const webServer:WebServer={
|
|
131
|
-
vite,
|
|
132
|
-
entries: {},
|
|
133
|
-
addEntry(entry) {
|
|
134
|
-
const hash = Date.now().toString(16)+Math.random().toString(16).slice(2,8);
|
|
135
|
-
const entryFile=typeof entry==="string"?entry:entry[(process.env.NODE_ENV as 'development'|'production')||'development'];
|
|
136
|
-
this.entries[hash] = `/vite/@fs/${entryFile}`;
|
|
137
|
-
for (const ws of this.ws.clients || []) {
|
|
138
|
-
ws.send(JSON.stringify(createAddMsg('entries', this.entries[hash])));
|
|
139
|
-
}
|
|
140
|
-
return () => {
|
|
141
|
-
for (const ws of this.ws.clients || []) {
|
|
142
|
-
ws.send(JSON.stringify(createDeleteMsg('entries', this.entries[hash])));
|
|
143
|
-
}
|
|
144
|
-
delete this.entries[hash];
|
|
145
|
-
};
|
|
146
|
-
},
|
|
147
|
-
ws:router.ws('/server')
|
|
148
|
-
}
|
|
149
|
-
// 数据推送函数
|
|
150
|
-
const broadcastToAll = (message: any) => {
|
|
151
|
-
for (const ws of webServer.ws.clients || []) {
|
|
152
|
-
if (ws.readyState === WebSocket.OPEN) {
|
|
153
|
-
ws.send(JSON.stringify(message));
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// 推送数据更新通知
|
|
159
|
-
const notifyDataUpdate = () => {
|
|
160
|
-
broadcastToAll({
|
|
161
|
-
type: 'data-update',
|
|
162
|
-
timestamp: Date.now()
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// WebSocket 连接处理
|
|
167
|
-
webServer.ws.on('connection', (ws: WebSocket) => {
|
|
168
|
-
// 发送初始数据
|
|
169
|
-
ws.send(JSON.stringify(createSyncMsg('entries', Array.from(new Set(Object.values(webServer.entries))))));
|
|
170
|
-
|
|
171
|
-
// 通知客户端进行数据初始化
|
|
172
|
-
ws.send(JSON.stringify({
|
|
173
|
-
type: 'init-data',
|
|
174
|
-
timestamp: Date.now()
|
|
175
|
-
}));
|
|
176
|
-
|
|
177
|
-
ws.on('close', () => {
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
ws.on('error', (error) => {
|
|
181
|
-
// console.error 已替换为注释
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// 定时通知客户端更新数据
|
|
186
|
-
const dataUpdateInterval = setInterval(() => {
|
|
187
|
-
notifyDataUpdate();
|
|
188
|
-
}, 5000); // 每5秒通知一次更新
|
|
189
|
-
|
|
190
|
-
// 插件卸载时清理定时器
|
|
191
|
-
process.on('exit', () => {
|
|
192
|
-
clearInterval(dataUpdateInterval);
|
|
193
|
-
});
|
|
194
|
-
register({
|
|
195
|
-
name:'web',
|
|
196
|
-
description:"web服务",
|
|
197
|
-
async mounted(){
|
|
198
|
-
return webServer
|
|
199
|
-
},
|
|
200
|
-
async dispose(server){
|
|
201
|
-
await server.vite.close();
|
|
202
|
-
server.ws.close()
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
});
|