Compare commits
10 Commits
a5d7f6df0e
...
a0f4d4507f
| Author | SHA1 | Date | |
|---|---|---|---|
| a0f4d4507f | |||
| 38c2f8e6dd | |||
| 9b5fcf9190 | |||
| 39c373ba2c | |||
| 5c36caa07b | |||
| 9b472109e9 | |||
| 243a22794c | |||
| 2c34c157f1 | |||
| 4fb4d5fd69 | |||
| 8d63b1e80b |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"mcpServers": {
|
||||
"mujian": {
|
||||
"mujian-js-sdk": {
|
||||
"command": "npx",
|
||||
"args": ["-y", "@mujian/mcp-docs-server"]
|
||||
}
|
||||
|
||||
26
.cursor/rules/general.mdc
Normal file
26
.cursor/rules/general.mdc
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
description: 工程全局规则
|
||||
alwaysApply: true
|
||||
---
|
||||
|
||||
你是一个游戏开发Agent,需要在本工程中,协助我开发一个 HTML 游戏。
|
||||
|
||||
## 本工程介绍
|
||||
|
||||
- 这是一个模版工程,开发者会基于这个工程进行拓展开发
|
||||
- 本工程采用 Vite + React 框架,是一个React SPA架构的游戏/应用
|
||||
- 本工程强烈建议使用如下前端NPM包:
|
||||
- react-router: 用于管理页面和路由
|
||||
- zustand: 用于React状态管理
|
||||
- TailwindCSS: 用于编写样式和管理主题
|
||||
- axios:用于发起http请求。包括上传和SSE场景。
|
||||
- dayjs: 用于处理日期
|
||||
- localforage: 用于管理Storage
|
||||
- react-icons: 用于使用图标
|
||||
- motion: 动效库
|
||||
- loadsh-es: 用于提供一些常用的utils函数
|
||||
|
||||
## 你需要遵循的规则
|
||||
|
||||
- Always respond in 中文
|
||||
- 只能新增、修改和删除 src 目录里的文件或者文件夹,严禁修改其他文件或者文件夹!
|
||||
@@ -1,20 +0,0 @@
|
||||
---
|
||||
description:
|
||||
globs:
|
||||
alwaysApply: false
|
||||
---
|
||||
|
||||
|
||||
|
||||
@tailwindcss
|
||||
localforage
|
||||
lodash-es
|
||||
motion
|
||||
react
|
||||
react-dom
|
||||
react-router
|
||||
tailwindcss
|
||||
zustand
|
||||
dayjs
|
||||
Axios
|
||||
react-icons
|
||||
6
.cursorignore
Normal file
6
.cursorignore
Normal file
@@ -0,0 +1,6 @@
|
||||
.npmrc
|
||||
biome.json
|
||||
index.html
|
||||
pnpm-lock.yaml
|
||||
.trae/
|
||||
.cursor/
|
||||
2
.trae/.ignore
Normal file
2
.trae/.ignore
Normal file
@@ -0,0 +1,2 @@
|
||||
!src/**
|
||||
!public/**
|
||||
80
README.md
80
README.md
@@ -1,69 +1,25 @@
|
||||
# React + TypeScript + Vite
|
||||
# 幕间自定义界面-官方模版-React版
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
- [幕间官网](https://mujian.ai)
|
||||
- [幕间文档站](https://docs.mujian.ai)
|
||||
- [幕间SDK](https://docs.mujian.ai/creator/sdk/introduction.html)
|
||||
- [教程地址](https://docs.mujian.ai/creator/game-dev/quick-start.html)
|
||||
- [仓库地址](https://git.mujian.me/mujian/react-boilerplate)
|
||||
|
||||
Currently, two official plugins are available:
|
||||
1. 初始化项目,安装依赖
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default tseslint.config([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
...tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
...tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```sh
|
||||
pnpm i
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
2. 本地开发
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default tseslint.config([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```sh
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
3. 打包
|
||||
|
||||
```sh
|
||||
pnpm build
|
||||
```
|
||||
@@ -10,7 +10,8 @@
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"indentStyle": "tab"
|
||||
"indentStyle": "space",
|
||||
"indentWidth": 2
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React + TS</title>
|
||||
<title>幕间自定义界面模版 React版</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -9,14 +9,13 @@
|
||||
},
|
||||
"packageManager": "pnpm@10.0.0",
|
||||
"scripts": {
|
||||
"mujian": "mujian hello world",
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "biome check --write ./src",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mujian/js-sdk": "^0.0.1",
|
||||
"@mujian/js-sdk": "^0.0.6-beta.45",
|
||||
"@tailwindcss/vite": "^4.1.12",
|
||||
"axios": "^1.11.0",
|
||||
"dayjs": "^1.11.18",
|
||||
@@ -37,7 +36,9 @@
|
||||
"@types/react": "^19.1.10",
|
||||
"@types/react-dom": "^19.1.7",
|
||||
"@vitejs/plugin-react": "^5.0.0",
|
||||
"clsx": "^2.1.1",
|
||||
"globals": "^16.3.0",
|
||||
"tailwind-merge": "^3.4.0",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.1.2"
|
||||
}
|
||||
|
||||
171
pnpm-lock.yaml
generated
171
pnpm-lock.yaml
generated
@@ -9,8 +9,8 @@ importers:
|
||||
.:
|
||||
dependencies:
|
||||
'@mujian/js-sdk':
|
||||
specifier: ^0.0.1
|
||||
version: 0.0.1
|
||||
specifier: ^0.0.6-beta.45
|
||||
version: 0.0.6-beta.45(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||
'@tailwindcss/vite':
|
||||
specifier: ^4.1.12
|
||||
version: 4.1.12(vite@7.1.3(@types/node@22.18.0)(jiti@2.5.1)(lightningcss@1.30.1))
|
||||
@@ -66,9 +66,15 @@ importers:
|
||||
'@vitejs/plugin-react':
|
||||
specifier: ^5.0.0
|
||||
version: 5.0.2(vite@7.1.3(@types/node@22.18.0)(jiti@2.5.1)(lightningcss@1.30.1))
|
||||
clsx:
|
||||
specifier: ^2.1.1
|
||||
version: 2.1.1
|
||||
globals:
|
||||
specifier: ^16.3.0
|
||||
version: 16.3.0
|
||||
tailwind-merge:
|
||||
specifier: ^3.4.0
|
||||
version: 3.4.0
|
||||
typescript:
|
||||
specifier: ~5.8.3
|
||||
version: 5.8.3
|
||||
@@ -78,6 +84,9 @@ importers:
|
||||
|
||||
packages:
|
||||
|
||||
'@adobe/css-tools@4.4.4':
|
||||
resolution: {integrity: sha512-Elp+iwUx5rN5+Y8xLt5/GRoG20WGoDCQ/1Fb+1LiGtvwbDavuSk0jhD/eZdckHAuzcDzccnkv+rEjyWfRx18gg==}
|
||||
|
||||
'@ampproject/remapping@2.3.0':
|
||||
resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==}
|
||||
engines: {node: '>=6.0.0'}
|
||||
@@ -153,6 +162,10 @@ packages:
|
||||
peerDependencies:
|
||||
'@babel/core': ^7.0.0-0
|
||||
|
||||
'@babel/runtime@7.28.4':
|
||||
resolution: {integrity: sha512-Q/N6JNWvIvPnLDvjlE1OUBLPQHH6l3CltCEsHIujp45zQUSSh8K+gHnaEX45yAT1nyngnINhvWtzN+Nb9D8RAQ==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
|
||||
'@babel/template@7.27.2':
|
||||
resolution: {integrity: sha512-LPDZ85aEJyYSd18/DkjNh4/y1ntkE5KwUHWTiqgRxruuZL2F1yuHligVHLvcHY2vMHXttKFpJn6LwfI7cw7ODw==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
@@ -346,8 +359,11 @@ packages:
|
||||
engines: {node: '>=18.0.0'}
|
||||
hasBin: true
|
||||
|
||||
'@mujian/js-sdk@0.0.1':
|
||||
resolution: {integrity: sha512-tJK+VL6pfsb5Gmoqtlb9yuYaX2p0SGoYxqS/8reKbu5uI7pK9uO9rHU+A7z94YCwOIDdiIefNCCrtgbTcMVMfg==}
|
||||
'@mujian/js-sdk@0.0.6-beta.45':
|
||||
resolution: {integrity: sha512-TpYyME3gk8wGha8xLDgpkO7QyLS0rE5lkvRp8fJAEeP/Tk+Ntjd/6RqAT30f/eNs1aJeUQ4JQ4tZyQaMMlQC8Q==}
|
||||
peerDependencies:
|
||||
react: ~19.1.1
|
||||
react-dom: ~19.1.1
|
||||
|
||||
'@oclif/core@4.5.2':
|
||||
resolution: {integrity: sha512-eQcKyrEcDYeZJKu4vUWiu0ii/1Gfev6GF4FsLSgNez5/+aQyAUCjg3ZWlurf491WiYZTXCWyKAxyPWk8DKv2MA==}
|
||||
@@ -584,6 +600,9 @@ packages:
|
||||
'@types/estree@1.0.8':
|
||||
resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==}
|
||||
|
||||
'@types/js-cookie@3.0.6':
|
||||
resolution: {integrity: sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==}
|
||||
|
||||
'@types/lodash-es@4.17.12':
|
||||
resolution: {integrity: sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==}
|
||||
|
||||
@@ -601,12 +620,22 @@ packages:
|
||||
'@types/react@19.1.12':
|
||||
resolution: {integrity: sha512-cMoR+FoAf/Jyq6+Df2/Z41jISvGZZ2eTlnsaJRptmZ76Caldwy1odD4xTr/gNV9VLj0AWgg/nmkevIyUfIIq5w==}
|
||||
|
||||
'@types/trusted-types@2.0.7':
|
||||
resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==}
|
||||
|
||||
'@vitejs/plugin-react@5.0.2':
|
||||
resolution: {integrity: sha512-tmyFgixPZCx2+e6VO9TNITWcCQl8+Nl/E8YbAyPVv85QCc7/A3JrdfG2A8gIzvVhWuzMOVrFW1aReaNxrI6tbw==}
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
peerDependencies:
|
||||
vite: ^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0
|
||||
|
||||
ahooks@3.9.5:
|
||||
resolution: {integrity: sha512-TrjXie49Q8HuHKTa84Fm9A+famMDAG1+7a9S9Gq6RQ0h90Jgqmiq3CkObuRjWT/C4d6nRZCw35Y2k2fmybb5eA==}
|
||||
engines: {node: '>=18'}
|
||||
peerDependencies:
|
||||
react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||
|
||||
ansi-escapes@4.3.2:
|
||||
resolution: {integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -662,6 +691,10 @@ packages:
|
||||
resolution: {integrity: sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
clsx@2.1.1:
|
||||
resolution: {integrity: sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
color-convert@2.0.1:
|
||||
resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==}
|
||||
engines: {node: '>=7.0.0'}
|
||||
@@ -673,6 +706,10 @@ packages:
|
||||
resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
|
||||
engines: {node: '>= 0.8'}
|
||||
|
||||
commander@9.5.0:
|
||||
resolution: {integrity: sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==}
|
||||
engines: {node: ^12.20.0 || >=14}
|
||||
|
||||
convert-source-map@2.0.0:
|
||||
resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==}
|
||||
|
||||
@@ -703,6 +740,9 @@ packages:
|
||||
resolution: {integrity: sha512-3UDv+G9CsCKO1WKMGw9fwq/SWJYbI0c5Y7LU1AXYoDdbhE2AHQ6N6Nb34sG8Fj7T5APy8qXDCKuuIHd1BR0tVA==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
dompurify@3.3.0:
|
||||
resolution: {integrity: sha512-r+f6MYR1gGN1eJv0TVQbhA7if/U7P87cdPl3HN5rikqaBSBxLiCb/b9O+2eG0cxz0ghyU+mU1QkbsOwERMYlWQ==}
|
||||
|
||||
dunder-proto@1.0.1:
|
||||
resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==}
|
||||
engines: {node: '>= 0.4'}
|
||||
@@ -852,6 +892,10 @@ packages:
|
||||
resolution: {integrity: sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
intersection-observer@0.12.2:
|
||||
resolution: {integrity: sha512-7m1vEcPCxXYI8HqnL8CKI6siDyD+eIWSwgB3DZA+ZTogxk9I4CDnj4wilt9x/+/QbHI4YG5YZNmC6458/e9Ktg==}
|
||||
deprecated: The Intersection Observer polyfill is no longer needed and can safely be removed. Intersection Observer has been Baseline since 2019.
|
||||
|
||||
is-docker@2.2.1:
|
||||
resolution: {integrity: sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -878,6 +922,10 @@ packages:
|
||||
resolution: {integrity: sha512-twQoecYPiVA5K/h6SxtORw/Bs3ar+mLUtoPSc7iMXzQzK8d7eJ/R09wmTwAjiamETn1cXYPGfNnu7DMoHgu12w==}
|
||||
hasBin: true
|
||||
|
||||
js-cookie@3.0.5:
|
||||
resolution: {integrity: sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==}
|
||||
engines: {node: '>=14'}
|
||||
|
||||
js-tokens@4.0.0:
|
||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||
|
||||
@@ -972,6 +1020,9 @@ packages:
|
||||
lodash-es@4.17.21:
|
||||
resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
|
||||
|
||||
lodash@4.17.21:
|
||||
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
|
||||
|
||||
lru-cache@10.4.3:
|
||||
resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==}
|
||||
|
||||
@@ -1161,6 +1212,9 @@ packages:
|
||||
peerDependencies:
|
||||
react: ^19.1.1
|
||||
|
||||
react-fast-compare@3.2.2:
|
||||
resolution: {integrity: sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==}
|
||||
|
||||
react-icons@5.5.0:
|
||||
resolution: {integrity: sha512-MEFcXdkP3dLo8uumGI5xN3lDFNsRtrjbOEKDLD7yv76v4wpnEq2Lt2qeHaQOr34I/wPN3s3+N08WkQ+CW37Xiw==}
|
||||
peerDependencies:
|
||||
@@ -1184,6 +1238,9 @@ packages:
|
||||
resolution: {integrity: sha512-w8nqGImo45dmMIfljjMwOGtbmC/mk4CMYhWIicdSflH91J9TyCyczcPFXJzrZ/ZXcgGRFeP6BU0BEJTw6tZdfQ==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
resize-observer-polyfill@1.5.1:
|
||||
resolution: {integrity: sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==}
|
||||
|
||||
rollup@4.49.0:
|
||||
resolution: {integrity: sha512-3IVq0cGJ6H7fKXXEdVt+RcYvRCt8beYY9K1760wGQwSAHZcS9eot1zDG5axUbcp/kWRi5zKIIDX8MoKv/TzvZA==}
|
||||
engines: {node: '>=18.0.0', npm: '>=8.0.0'}
|
||||
@@ -1192,6 +1249,10 @@ packages:
|
||||
scheduler@0.26.0:
|
||||
resolution: {integrity: sha512-NlHwttCI/l5gCPR3D1nNXtWABUmBwvZpEQiD4IXSbIDq8BzLIK/7Ir5gTFSGZDUu37K5cMNp0hFtzO38sC7gWA==}
|
||||
|
||||
screenfull@5.2.0:
|
||||
resolution: {integrity: sha512-9BakfsO2aUQN2K9Fdbj87RJIEZ82Q9IGim7FqM5OsebfoFC6ZHXgDq/KvniuLTPdeM8wY2o6Dj3WQ7KeQCj3cA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
semver@6.3.1:
|
||||
resolution: {integrity: sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==}
|
||||
hasBin: true
|
||||
@@ -1204,6 +1265,10 @@ packages:
|
||||
set-cookie-parser@2.7.1:
|
||||
resolution: {integrity: sha512-IOc8uWeOZgnb3ptbCURJWNjWUPcO3ZnTTdzsurqERrP6nPyv+paC55vJM0LpOlT2ne+Ix+9+CRG1MNLlyZ4GjQ==}
|
||||
|
||||
showdown@2.1.0:
|
||||
resolution: {integrity: sha512-/6NVYu4U819R2pUIk79n67SYgJHWCce0a5xTP979WbNp0FL9MN1I1QK662IDU1b6JzKTvmhgI7T7JYIxBi3kMQ==}
|
||||
hasBin: true
|
||||
|
||||
source-map-js@1.2.1:
|
||||
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@@ -1220,6 +1285,9 @@ packages:
|
||||
resolution: {integrity: sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
tailwind-merge@3.4.0:
|
||||
resolution: {integrity: sha512-uSaO4gnW+b3Y2aWoWfFpX62vn2sR3skfhbjsEnaBI81WD1wBLlHZe5sWf0AqjksNdYTbGBEd0UasQMT3SNV15g==}
|
||||
|
||||
tailwindcss@4.1.12:
|
||||
resolution: {integrity: sha512-DzFtxOi+7NsFf7DBtI3BJsynR+0Yp6etH+nRPTbpWnS2pZBaSksv/JGctNwSWzbFjp0vxSqknaUylseZqMDGrA==}
|
||||
|
||||
@@ -1256,10 +1324,34 @@ packages:
|
||||
peerDependencies:
|
||||
browserslist: '>= 4.21.0'
|
||||
|
||||
uuid@13.0.0:
|
||||
resolution: {integrity: sha512-XQegIaBTVUjSHliKqcnFqYypAd4S+WCYt5NIeRs6w/UAry7z8Y9j5ZwRRL4kzq9U3sD6v+85er9FvkEaBpji2w==}
|
||||
hasBin: true
|
||||
|
||||
validate-npm-package-name@5.0.1:
|
||||
resolution: {integrity: sha512-OljLrQ9SQdOUqTaQxqL5dEfZWrXExyyWsozYlAWFawPVNuD83igl7uJD2RTkNMbniIYgt8l81eCJGIdQF7avLQ==}
|
||||
engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0}
|
||||
|
||||
virtua@0.45.3:
|
||||
resolution: {integrity: sha512-+nW3VOwXhlte3m4jbS9gVMked/cZo95IKChH0qol+XUApQVZpPaLDGee1BC/rVng0tsMfxs0vJPEPEUAAfKpkw==}
|
||||
peerDependencies:
|
||||
react: '>=16.14.0'
|
||||
react-dom: '>=16.14.0'
|
||||
solid-js: '>=1.0'
|
||||
svelte: '>=5.0'
|
||||
vue: '>=3.2'
|
||||
peerDependenciesMeta:
|
||||
react:
|
||||
optional: true
|
||||
react-dom:
|
||||
optional: true
|
||||
solid-js:
|
||||
optional: true
|
||||
svelte:
|
||||
optional: true
|
||||
vue:
|
||||
optional: true
|
||||
|
||||
vite@7.1.3:
|
||||
resolution: {integrity: sha512-OOUi5zjkDxYrKhTV3V7iKsoS37VUM7v40+HuwEmcrsf11Cdx9y3DIr2Px6liIcZFwt3XSRpQvFpL3WVy7ApkGw==}
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
@@ -1348,6 +1440,8 @@ packages:
|
||||
|
||||
snapshots:
|
||||
|
||||
'@adobe/css-tools@4.4.4': {}
|
||||
|
||||
'@ampproject/remapping@2.3.0':
|
||||
dependencies:
|
||||
'@jridgewell/gen-mapping': 0.3.13
|
||||
@@ -1442,6 +1536,8 @@ snapshots:
|
||||
'@babel/core': 7.28.3
|
||||
'@babel/helper-plugin-utils': 7.27.1
|
||||
|
||||
'@babel/runtime@7.28.4': {}
|
||||
|
||||
'@babel/template@7.27.2':
|
||||
dependencies:
|
||||
'@babel/code-frame': 7.27.1
|
||||
@@ -1574,9 +1670,21 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@mujian/js-sdk@0.0.1':
|
||||
'@mujian/js-sdk@0.0.6-beta.45(react-dom@19.1.1(react@19.1.1))(react@19.1.1)':
|
||||
dependencies:
|
||||
'@adobe/css-tools': 4.4.4
|
||||
ahooks: 3.9.5(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||
dompurify: 3.3.0
|
||||
postmate: 1.5.2
|
||||
react: 19.1.1
|
||||
react-dom: 19.1.1(react@19.1.1)
|
||||
showdown: 2.1.0
|
||||
uuid: 13.0.0
|
||||
virtua: 0.45.3(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||
transitivePeerDependencies:
|
||||
- solid-js
|
||||
- svelte
|
||||
- vue
|
||||
|
||||
'@oclif/core@4.5.2':
|
||||
dependencies:
|
||||
@@ -1775,6 +1883,8 @@ snapshots:
|
||||
|
||||
'@types/estree@1.0.8': {}
|
||||
|
||||
'@types/js-cookie@3.0.6': {}
|
||||
|
||||
'@types/lodash-es@4.17.12':
|
||||
dependencies:
|
||||
'@types/lodash': 4.17.20
|
||||
@@ -1793,6 +1903,9 @@ snapshots:
|
||||
dependencies:
|
||||
csstype: 3.1.3
|
||||
|
||||
'@types/trusted-types@2.0.7':
|
||||
optional: true
|
||||
|
||||
'@vitejs/plugin-react@5.0.2(vite@7.1.3(@types/node@22.18.0)(jiti@2.5.1)(lightningcss@1.30.1))':
|
||||
dependencies:
|
||||
'@babel/core': 7.28.3
|
||||
@@ -1805,6 +1918,21 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
ahooks@3.9.5(react-dom@19.1.1(react@19.1.1))(react@19.1.1):
|
||||
dependencies:
|
||||
'@babel/runtime': 7.28.4
|
||||
'@types/js-cookie': 3.0.6
|
||||
dayjs: 1.11.18
|
||||
intersection-observer: 0.12.2
|
||||
js-cookie: 3.0.5
|
||||
lodash: 4.17.21
|
||||
react: 19.1.1
|
||||
react-dom: 19.1.1(react@19.1.1)
|
||||
react-fast-compare: 3.2.2
|
||||
resize-observer-polyfill: 1.5.1
|
||||
screenfull: 5.2.0
|
||||
tslib: 2.8.1
|
||||
|
||||
ansi-escapes@4.3.2:
|
||||
dependencies:
|
||||
type-fest: 0.21.3
|
||||
@@ -1857,6 +1985,8 @@ snapshots:
|
||||
|
||||
cli-spinners@2.9.2: {}
|
||||
|
||||
clsx@2.1.1: {}
|
||||
|
||||
color-convert@2.0.1:
|
||||
dependencies:
|
||||
color-name: 1.1.4
|
||||
@@ -1867,6 +1997,8 @@ snapshots:
|
||||
dependencies:
|
||||
delayed-stream: 1.0.0
|
||||
|
||||
commander@9.5.0: {}
|
||||
|
||||
convert-source-map@2.0.0: {}
|
||||
|
||||
cookie@1.0.2: {}
|
||||
@@ -1885,6 +2017,10 @@ snapshots:
|
||||
|
||||
detect-libc@2.0.4: {}
|
||||
|
||||
dompurify@3.3.0:
|
||||
optionalDependencies:
|
||||
'@types/trusted-types': 2.0.7
|
||||
|
||||
dunder-proto@1.0.1:
|
||||
dependencies:
|
||||
call-bind-apply-helpers: 1.0.2
|
||||
@@ -2032,6 +2168,8 @@ snapshots:
|
||||
|
||||
indent-string@4.0.0: {}
|
||||
|
||||
intersection-observer@0.12.2: {}
|
||||
|
||||
is-docker@2.2.1: {}
|
||||
|
||||
is-fullwidth-code-point@3.0.0: {}
|
||||
@@ -2050,6 +2188,8 @@ snapshots:
|
||||
|
||||
jiti@2.5.1: {}
|
||||
|
||||
js-cookie@3.0.5: {}
|
||||
|
||||
js-tokens@4.0.0: {}
|
||||
|
||||
jsesc@3.1.0: {}
|
||||
@@ -2113,6 +2253,8 @@ snapshots:
|
||||
|
||||
lodash-es@4.17.21: {}
|
||||
|
||||
lodash@4.17.21: {}
|
||||
|
||||
lru-cache@10.4.3: {}
|
||||
|
||||
lru-cache@5.1.1:
|
||||
@@ -2205,6 +2347,8 @@ snapshots:
|
||||
react: 19.1.1
|
||||
scheduler: 0.26.0
|
||||
|
||||
react-fast-compare@3.2.2: {}
|
||||
|
||||
react-icons@5.5.0(react@19.1.1):
|
||||
dependencies:
|
||||
react: 19.1.1
|
||||
@@ -2221,6 +2365,8 @@ snapshots:
|
||||
|
||||
react@19.1.1: {}
|
||||
|
||||
resize-observer-polyfill@1.5.1: {}
|
||||
|
||||
rollup@4.49.0:
|
||||
dependencies:
|
||||
'@types/estree': 1.0.8
|
||||
@@ -2249,12 +2395,18 @@ snapshots:
|
||||
|
||||
scheduler@0.26.0: {}
|
||||
|
||||
screenfull@5.2.0: {}
|
||||
|
||||
semver@6.3.1: {}
|
||||
|
||||
semver@7.7.2: {}
|
||||
|
||||
set-cookie-parser@2.7.1: {}
|
||||
|
||||
showdown@2.1.0:
|
||||
dependencies:
|
||||
commander: 9.5.0
|
||||
|
||||
source-map-js@1.2.1: {}
|
||||
|
||||
string-width@4.2.3:
|
||||
@@ -2271,6 +2423,8 @@ snapshots:
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
|
||||
tailwind-merge@3.4.0: {}
|
||||
|
||||
tailwindcss@4.1.12: {}
|
||||
|
||||
tapable@2.2.3: {}
|
||||
@@ -2303,8 +2457,15 @@ snapshots:
|
||||
escalade: 3.2.0
|
||||
picocolors: 1.1.1
|
||||
|
||||
uuid@13.0.0: {}
|
||||
|
||||
validate-npm-package-name@5.0.1: {}
|
||||
|
||||
virtua@0.45.3(react-dom@19.1.1(react@19.1.1))(react@19.1.1):
|
||||
optionalDependencies:
|
||||
react: 19.1.1
|
||||
react-dom: 19.1.1(react@19.1.1)
|
||||
|
||||
vite@7.1.3(@types/node@22.18.0)(jiti@2.5.1)(lightningcss@1.30.1):
|
||||
dependencies:
|
||||
esbuild: 0.25.9
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
---
|
||||
description:
|
||||
globs:
|
||||
description: Public 模版
|
||||
alwaysApply: false
|
||||
---
|
||||
4
src/assets/.cursor/rules/assets_rules.mdc
Normal file
4
src/assets/.cursor/rules/assets_rules.mdc
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
description: assets 模版
|
||||
alwaysApply: false
|
||||
---
|
||||
13
src/components/.cursor/rules/components_rules.mdc
Normal file
13
src/components/.cursor/rules/components_rules.mdc
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
description: Common Components 公共组件
|
||||
globs: ["**/*.ts", "**/*.tsx"]
|
||||
alwaysApply: Auto Attached
|
||||
---
|
||||
|
||||
# 本规则为前端公共组件规范
|
||||
|
||||
- 非公共组件不要放在本目录下
|
||||
- 样式统一使用 Tailwind
|
||||
- 如果需要动画,使用 Motion 库
|
||||
- 遵循组件命名约定
|
||||
- export 的时候采用 命名导出,不要使用 默认导出
|
||||
20
src/components/Button/index.tsx
Normal file
20
src/components/Button/index.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
|
||||
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export const Button: React.FC<ButtonProps> = ({
|
||||
children,
|
||||
className = '',
|
||||
...props
|
||||
}) => {
|
||||
return (
|
||||
<button
|
||||
className={`px-4 py-1 rounded-md font-medium transition-colors ${className} ${props.disabled ? 'opacity-50 cursor-not-allowed' : 'hover:opacity-80'}`}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
3
src/components/Example/index.tsx
Normal file
3
src/components/Example/index.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export const Example = () => {
|
||||
return <div>Example</div>;
|
||||
};
|
||||
2
src/components/index.ts
Normal file
2
src/components/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './Button';
|
||||
export * from './Example';
|
||||
1
src/components/react.svg
Normal file
1
src/components/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
@@ -1,11 +1,11 @@
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import '@/styles/fonts.css';
|
||||
import '@/styles/global.css';
|
||||
import { MujianProvider } from './providers/MujianProvider.tsx';
|
||||
import { MujianProvider } from '@mujian/js-sdk/react';
|
||||
import { ReactRouterProvider } from './providers/RouterProvider.tsx';
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<MujianProvider>
|
||||
<ReactRouterProvider />
|
||||
</MujianProvider>,
|
||||
<MujianProvider>
|
||||
<ReactRouterProvider />
|
||||
</MujianProvider>,
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
description:
|
||||
globs:
|
||||
alwaysApply: false
|
||||
description: 页面模版
|
||||
globs: ["**/*.ts", "**/*.tsx"]
|
||||
alwaysApply: Auto Attached
|
||||
---
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import './index.css';
|
||||
// import { useGlobalStore } from "@/store/global";
|
||||
|
||||
function About() {
|
||||
// const { count, increment } = useGlobalStore((state) => state);
|
||||
|
||||
return <div>about page</div>;
|
||||
}
|
||||
|
||||
export default About;
|
||||
133
src/pages/chat/index.tsx
Normal file
133
src/pages/chat/index.tsx
Normal file
@@ -0,0 +1,133 @@
|
||||
import { useChat, useMujian } from '@mujian/js-sdk/react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { Button } from '@/components';
|
||||
import { useGlobalStore } from '@/store/global';
|
||||
import { cn } from '@/utils/cn';
|
||||
|
||||
// import { useGlobalStore } from "@/store/global";
|
||||
|
||||
function Chat() {
|
||||
const { init } = useGlobalStore();
|
||||
const mujian = useMujian();
|
||||
const navigate = useNavigate();
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const messagesContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
init(mujian);
|
||||
}, []);
|
||||
|
||||
// const { count, increment } = useGlobalStore((state) => state);
|
||||
|
||||
// 调用消息 SDK,获取消息列表、状态、错误信息、添加消息、停止消息
|
||||
const { messages, status, error, append, stop } = useChat({
|
||||
onError: (e) => {
|
||||
console.error(e);
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (messagesContainerRef.current) {
|
||||
messagesContainerRef.current?.scrollTo({
|
||||
top: messagesContainerRef.current.scrollHeight,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}
|
||||
}, [messages]);
|
||||
|
||||
// 发送按钮
|
||||
const handleSend = () => {
|
||||
append(inputValue);
|
||||
setInputValue('');
|
||||
};
|
||||
|
||||
// 停止按钮
|
||||
const handleStop = () => {
|
||||
stop();
|
||||
};
|
||||
|
||||
// 输入框变化
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
setInputValue(e.target.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col justify-center items-center h-screen">
|
||||
<div className="font-bold mb-2">
|
||||
这里是首页{' '}
|
||||
<Button
|
||||
className="bg-blue-500 hover:bg-blue-600 text-white rounded-lg"
|
||||
onClick={() => navigate('/second')}
|
||||
>
|
||||
进入第二个页面
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="w-full flex flex-col gap-2 h-[calc(100vh-140px)] max-h-[calc(100vh-140px)] overflow-y-auto px-2"
|
||||
ref={messagesContainerRef}
|
||||
>
|
||||
{messages.map((message) =>
|
||||
message.role === 'user' ? (
|
||||
<div
|
||||
key={message.id}
|
||||
className="text-right p-2 rounded-md bg-red-500/30 text-white w-fit self-end"
|
||||
>
|
||||
User: {message.content}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
key={message.id}
|
||||
className={cn(
|
||||
'text-left p-2 rounded-md bg-green-500/30 text-white w-fit self-start',
|
||||
message.id === messages[messages.length - 1].id &&
|
||||
status === 'streaming' &&
|
||||
'animate-pulse',
|
||||
)}
|
||||
>
|
||||
Assistant: {message.content || '思考中...'}
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="w-full flex flex-col gap-2 pt-2">
|
||||
<textarea
|
||||
rows={3}
|
||||
placeholder="请输入内容"
|
||||
className="border-2 border-gray-300 rounded-md p-2 w-full"
|
||||
value={inputValue}
|
||||
onChange={handleInputChange}
|
||||
/>
|
||||
<div className="flex gap-2 justify-between">
|
||||
当前状态: {status}
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
className="bg-blue-500 hover:bg-blue-600 text-white rounded-lg"
|
||||
onClick={handleSend}
|
||||
onKeyDown={(e) => {
|
||||
// 按下回车键发送消息
|
||||
if (e.key === 'Enter') {
|
||||
handleSend();
|
||||
}
|
||||
}}
|
||||
disabled={status === 'streaming'}
|
||||
>
|
||||
发送
|
||||
</Button>
|
||||
<Button
|
||||
className="bg-red-500 hover:bg-red-600 text-white rounded-lg"
|
||||
onClick={handleStop}
|
||||
disabled={status !== 'streaming'}
|
||||
>
|
||||
停止
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Chat;
|
||||
@@ -1,42 +0,0 @@
|
||||
import { useGlobalStore } from '@/store/global';
|
||||
import './index.css';
|
||||
import { isEmpty } from 'lodash-es';
|
||||
import { EVENT, useMujian } from '@/providers/MujianProvider';
|
||||
|
||||
function Home() {
|
||||
const { count, increment } = useGlobalStore((state) => state);
|
||||
const mujian = useMujian();
|
||||
|
||||
console.log('count', count);
|
||||
|
||||
console.log('isEmpty', isEmpty(count));
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<div className="text-3xl font-bold underline">Hello World2</div>
|
||||
</div>
|
||||
<h1>Vite + React</h1>
|
||||
<button type="button" onClick={increment}>
|
||||
Increment
|
||||
</button>
|
||||
|
||||
<p>Count: {count}</p>
|
||||
|
||||
<br />
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={async () => {
|
||||
mujian.emit(EVENT.MUJIAN_AI_CHAT_SEND_MESSAGE, {
|
||||
message: 'Hello, World!',
|
||||
});
|
||||
}}
|
||||
>
|
||||
Hello
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Home;
|
||||
1
src/pages/second/index.css
Normal file
1
src/pages/second/index.css
Normal file
@@ -0,0 +1 @@
|
||||
/* 首页样式 */
|
||||
30
src/pages/second/index.tsx
Normal file
30
src/pages/second/index.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import './index.css';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { Button } from '@/components';
|
||||
import { useGlobalStore } from '@/store/global';
|
||||
|
||||
function Second() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { projectInfo, activePersona } = useGlobalStore();
|
||||
return (
|
||||
<div className="flex flex-col justify-center items-center h-screen">
|
||||
<div className="text-2xl font-bold mb-4">这里是第二个页面</div>
|
||||
<Button
|
||||
className="bg-green-500 hover:bg-green-600 text-white rounded-lg"
|
||||
onClick={() => navigate('/')}
|
||||
>
|
||||
返回首页
|
||||
</Button>
|
||||
<div className="w-full max-w-md">
|
||||
<pre className="text-xs text-wrap">{JSON.stringify(projectInfo, null, 2)}</pre>
|
||||
</div>
|
||||
|
||||
<div className="w-full max-w-md">
|
||||
<pre className="text-xs text-wrap">{JSON.stringify(activePersona, null, 2)}</pre>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Second;
|
||||
7
src/providers/.cursor/rules/providers_rules.mdc
Normal file
7
src/providers/.cursor/rules/providers_rules.mdc
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
description: Provider 模版
|
||||
globs: ["**/*.ts", "**/*.tsx"]
|
||||
alwaysApply: Auto Attached
|
||||
---
|
||||
|
||||
- RouterProvider 为 react-router 路由配置文件
|
||||
@@ -1,51 +0,0 @@
|
||||
// @rule: do not modify this file
|
||||
|
||||
import { MujianSdk } from '@mujian/js-sdk';
|
||||
import {
|
||||
createContext,
|
||||
type ReactNode,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
} from 'react';
|
||||
|
||||
export { EVENT } from '@mujian/js-sdk';
|
||||
|
||||
const MujianContext = createContext<MujianSdk | null>(null);
|
||||
|
||||
export interface MujianProviderProps {
|
||||
children: ReactNode;
|
||||
loadingPage?: ReactNode;
|
||||
}
|
||||
|
||||
export const MujianProvider = ({
|
||||
children,
|
||||
loadingPage,
|
||||
}: MujianProviderProps) => {
|
||||
const [mujian, setMujian] = useState<MujianSdk | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const mujian = new MujianSdk();
|
||||
await mujian.init();
|
||||
setMujian(mujian);
|
||||
})();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<MujianContext.Provider value={mujian}>
|
||||
{mujian ? children : (loadingPage ?? 'Mujian is loading')}
|
||||
</MujianContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useMujian = () => {
|
||||
const mujian = useContext(MujianContext);
|
||||
if (!mujian) {
|
||||
const message =
|
||||
'Mujian is not initialized. Please check that useMujian is called inside MujianProvider';
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
return mujian;
|
||||
};
|
||||
@@ -1,19 +1,19 @@
|
||||
import { createBrowserRouter } from 'react-router';
|
||||
import { RouterProvider } from 'react-router/dom';
|
||||
import About from '@/pages/about';
|
||||
import Home from '@/pages/home';
|
||||
import Chat from '@/pages/chat';
|
||||
import Second from '@/pages/second';
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: '/',
|
||||
element: <Home />,
|
||||
},
|
||||
{
|
||||
path: '/about',
|
||||
element: <About />,
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
element: <Chat />,
|
||||
},
|
||||
{
|
||||
path: '/second',
|
||||
element: <Second />,
|
||||
},
|
||||
]);
|
||||
|
||||
export const ReactRouterProvider = () => {
|
||||
return <RouterProvider router={router} />;
|
||||
return <RouterProvider router={router} />;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
description:
|
||||
globs:
|
||||
alwaysApply: false
|
||||
description: Zustand store 模版
|
||||
globs: ["**/*.ts", "**/*.tsx"]
|
||||
alwaysApply: Auto Attached
|
||||
---
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
import type { MujianSdk } from '@mujian/js-sdk';
|
||||
import type { PersonaInfo, ProjectInfo } from '@mujian/js-sdk/types';
|
||||
import { create } from 'zustand';
|
||||
|
||||
type GlobalState = {
|
||||
count: number;
|
||||
increment: () => void;
|
||||
projectInfo: ProjectInfo | null;
|
||||
activePersona: PersonaInfo | null;
|
||||
init: (mujian: MujianSdk) => Promise<void>;
|
||||
};
|
||||
|
||||
export const useGlobalStore = create<GlobalState>((set) => ({
|
||||
count: 0,
|
||||
increment: () => {
|
||||
console.log('increment');
|
||||
set((state) => ({ count: state.count + 1 }));
|
||||
},
|
||||
count: 0,
|
||||
projectInfo: null,
|
||||
activePersona: null,
|
||||
|
||||
init: async (mujian: MujianSdk) => {
|
||||
const [projectInfo, persona] = await Promise.all([
|
||||
mujian.ai.chat.project.getInfo(),
|
||||
mujian.ai.chat.settings.persona.getActive(),
|
||||
]);
|
||||
set({ projectInfo, activePersona: persona });
|
||||
},
|
||||
}));
|
||||
|
||||
5
src/styles/.cursor/rules/style_rules.mdc
Normal file
5
src/styles/.cursor/rules/style_rules.mdc
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
description: CSS 样式模版
|
||||
globs: ["**/*.css"]
|
||||
alwaysApply: Auto Attached
|
||||
---
|
||||
@@ -1,14 +1,16 @@
|
||||
/* 全局样式 */
|
||||
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color-scheme: light dark;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
6
src/utils/cn.ts
Normal file
6
src/utils/cn.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type ClassValue, clsx } from 'clsx';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
||||
export const cn = (...inputs: ClassValue[]) => {
|
||||
return twMerge(clsx(inputs));
|
||||
};
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"erasableSyntaxOnly": false,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true,
|
||||
"baseUrl": ".",
|
||||
|
||||
@@ -5,10 +5,13 @@ import { defineConfig } from 'vite';
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
plugins: [react(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
cors: true,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user