Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom entity feature #14

Open
wants to merge 218 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
218 commits
Select commit Hold shift + click to select a range
d109cd6
feat: sync workflow feature from old lib
Jimco Dec 4, 2024
64056a4
feat: Complete the add node feature
Jimco Dec 4, 2024
28db887
feat: Calculate the new node position based on node size; add edge ho…
Jimco Dec 5, 2024
c9e4796
feat: workflow parallel depth limit check
Jimco Dec 5, 2024
8863af3
fix: Make the tooltip appear on top of other nodes
Jimco Dec 5, 2024
8549f0a
feat: add entry panel for workflow editor
Jimco Dec 6, 2024
b84f64c
feat: add workflow api service
Jimco Dec 6, 2024
869fc35
fix: use currentColor to fill icon path
Jimco Dec 6, 2024
61d55d7
feat: Workflow Editing Modal
nianxh-milesight Dec 6, 2024
81ad25e
fix: Add a workflow addition dialog mode and make modifications for P…
nianxh-milesight Dec 9, 2024
02e268a
fix: handle the confirmation callback function for the edit dialog
nianxh-milesight Dec 9, 2024
d9927c8
Merge pull request #3 from Milesight-IoT/feat/workflow-edit-modal
Jimco Dec 9, 2024
5c393a9
feat: add/edit dialog UI interaction
nianxh-milesight Dec 9, 2024
169ec3f
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
nianxh-milesight Dec 9, 2024
cf83e8a
fix: Interactive optimization during data editing
Jimco Dec 9, 2024
2d93893
feat: add features for workflow topbar
Jimco Dec 9, 2024
aa67d3c
feat: import from DSL modal
nianxh-milesight Dec 10, 2024
bf8e611
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
nianxh-milesight Dec 10, 2024
2766fb8
fix: use the Import the DSL dialog on the workflow list page
nianxh-milesight Dec 10, 2024
c3129f1
fix: error use useCallback API
nianxh-milesight Dec 10, 2024
9653dee
feat: add TestButton, LogPanel components
Jimco Dec 10, 2024
1d66626
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
nianxh-milesight Dec 11, 2024
2e32e62
style: use color variables
nianxh-milesight Dec 11, 2024
88617d8
Merge pull request #4 from Milesight-IoT/feat/workflow-edit-modal
Jimco Dec 11, 2024
cefed22
fix: use theme color, translate the code note to en
Jimco Dec 11, 2024
3633940
fix: after importing the DSL, navigate to the edit page
nianxh-milesight Dec 11, 2024
543ce83
feat: add form components definition
Jimco Dec 11, 2024
3856ba4
feat: add a Log Modal Component
by-night Dec 12, 2024
fb3832f
Merge branch 'feat/workflow' into feat/workflow-log
by-night Dec 12, 2024
52a59c4
feat: Add a Action Log Component
by-night Dec 12, 2024
310d2dc
feat: add EntitySelect, EntityFilterSelect components
Jimco Dec 12, 2024
7aa4397
fix: add multiple prop for EntityFilterSelect component
Jimco Dec 12, 2024
6f5c9b0
fix: adjust the API interaction for the edit workflow modal
nianxh-milesight Dec 12, 2024
ee04127
fix: delete workflow interaction logic
nianxh-milesight Dec 13, 2024
24e1822
Merge pull request #5 from Milesight-IoT/feat/workflow-del
Jimco Dec 13, 2024
d315429
fix: add workflow interaction logic
nianxh-milesight Dec 13, 2024
d1ae794
Merge pull request #7 from Milesight-IoT/feat/workflow-del
Jimco Dec 13, 2024
0a36371
feat: add ParamSelect, ParamInputSelect components
Jimco Dec 13, 2024
6722dfb
fix: jump to the login page, if the user api error
Jimco Dec 16, 2024
1bb6b81
feat: Add Code editor customizes components
by-night Dec 16, 2024
77ab31c
feat: add form item components for nodes
Jimco Dec 16, 2024
b62afc1
Merge branch 'feat/workflow' into feat/workflow-log
by-night Dec 16, 2024
29fa93b
Merge branch 'feat/workflow' into feat/workflow-codeEditor
by-night Dec 16, 2024
2b38dfa
feat: triigger node
nianxh-milesight Dec 17, 2024
c5c1f48
Merge pull request #8 from nianxh-milesight/feat/workflow
Jimco Dec 17, 2024
dff1ee0
feat: Add entity feature
Lynn-Bing Dec 17, 2024
410f882
feat: Added workflow log data processing logic
by-night Dec 17, 2024
5f9406d
feat: add node form compnents and render nodes form
Jimco Dec 17, 2024
cda3536
feat: complete the ConfigPanel form
Jimco Dec 18, 2024
92bdf46
feat: Run log popup adds scrolling loading logic
by-night Dec 18, 2024
0a6a117
feat: workflow webhook add custom data form
Dec 18, 2024
7c83623
feat: The editor adds markdow format and support for custom commands
by-night Dec 18, 2024
d99da72
Merge branch 'feat/workflow' into feat/workflow-codeEditor
by-night Dec 18, 2024
379b692
feat: add a code editor component to the form
by-night Dec 18, 2024
4467325
feat: Add defaultValue to the code editor
by-night Dec 18, 2024
31b5eb6
feat: add ConditionsInput component
Jimco Dec 18, 2024
3df1b07
Merge pull request #10 from Milesight-IoT/feat/workflow-webhook
Jimco Dec 19, 2024
619302b
fix: improve the trigger node configuration
nianxh-milesight Dec 18, 2024
ef9a087
feat: service call node
nianxh-milesight Dec 19, 2024
c16e5e5
fix: file upload format restrictions & validate DSL file content
nianxh-milesight Dec 17, 2024
310bc95
refactor: adjust the DSL file validation return results
nianxh-milesight Dec 18, 2024
d267a4f
fix: remove defaultValue of param-input
nianxh-milesight Dec 18, 2024
2986b44
fix: adjust the ServiceParamAssignInput component
nianxh-milesight Dec 18, 2024
8f9f188
Merge pull request #9 from nianxh-milesight/feat/workflow
Jimco Dec 19, 2024
527d313
feat: Add run milliseconds to display in the action log component
by-night Dec 19, 2024
4564773
feat: Integrate custom entities
Lynn-Bing Dec 19, 2024
5dddec7
Merge branch 'feat/workflow' into feat/workflow-log
by-night Dec 19, 2024
64467c6
Merge branch 'feat/workflow' into feat/workflow-codeEditor
by-night Dec 19, 2024
df09e13
feat: workflow email notify node design phase 1
Dec 19, 2024
61c5a96
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
Dec 19, 2024
da59b49
feat: add common editor header class
by-night Dec 19, 2024
84b45c1
feat: Add usage documentation for the code editor component
by-night Dec 19, 2024
e76b749
feat: The select component in the editor is replaced with the public …
by-night Dec 19, 2024
ff9f1dc
feat: Optimize the logic and style of the custom entity addition dialog
Lynn-Bing Dec 20, 2024
2eccd60
feat: workflow email notify email config component design
Dec 20, 2024
6e93176
Merge pull request #11 from Milesight-IoT/feat/workflow-codeEditor
Jimco Dec 20, 2024
f5446fb
feat: complete ifelse node content render
Jimco Dec 20, 2024
c9ff446
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
Dec 20, 2024
555c4e7
Merge branch 'feat/workflow' into feat/workflow-log
by-night Dec 20, 2024
70be653
chore: Limiting pnpm versions
Jimco Dec 20, 2024
3552d62
fix: rerender ifelse node handles when data change
Jimco Dec 20, 2024
f722cac
feat: Add nested data generation logic for action log
by-night Dec 20, 2024
661fa58
feat: add MoreMenu component for ConfigPanel
Jimco Dec 20, 2024
de1aa85
feat: workflow email notify node content component
Dec 20, 2024
dc6a497
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
Dec 20, 2024
c1a11fe
feat: workflow email notify node content enter update string
Masonwzb Dec 21, 2024
e0d90de
feat: add TestDrawer component for ConfigPanel
Jimco Dec 21, 2024
6539e9f
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
Dec 23, 2024
78e3a12
Merge branch 'feat/workflow-email' of github.com:Milesight-IoT/beaver…
Dec 23, 2024
a3d851b
feat: Optimize editor style, add backend node name mapping
Jimco Dec 23, 2024
e8fc1ce
feat: workflow email notify content upstream node empty
Dec 23, 2024
734bfc5
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
Dec 23, 2024
19dc2a2
feat: modify workflow api service
Jimco Dec 23, 2024
9ecfdef
feat: Adjust the branch display rules for the action log component
by-night Dec 23, 2024
06eb36f
feat: Integrated debugging and entity export
Lynn-Bing Dec 23, 2024
c79e385
Merge pull request #17 from Milesight-IoT/feat/workflow-email
Jimco Dec 23, 2024
085a1b9
feat: Use the 'readerHeader' API to replace 'Header' usage
by-night Dec 23, 2024
8bf33f6
feat: The action log component adds an input/output editor
by-night Dec 23, 2024
1515d12
feat: The code editor component added support for the 'height' props
by-night Dec 23, 2024
766da3d
Merge branch 'feat/workflow' into feat/workflow-log
by-night Dec 23, 2024
b02e33d
feat: The action log component adds 'errMsg' text display
by-night Dec 23, 2024
2a3bc36
Merge pull request #13 from Milesight-IoT/feat/workflow-log
Jimco Dec 23, 2024
c8d41d8
feat: Adjust some ts types in the action log
by-night Dec 23, 2024
c4b3acf
feat: workflow email notify node remove gmail temporary
Dec 23, 2024
b0f1766
fix: rename the export type in workflow api service
Jimco Dec 23, 2024
55b5c6d
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
Dec 23, 2024
853bf2d
feat: modify workflow data based on api service
Jimco Dec 23, 2024
7cd5616
feat: Add active style to the code editor component
by-night Dec 23, 2024
8f4f484
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
by-night Dec 23, 2024
6e56dd9
fix: Fixed an issue where the code editor fold function required two …
by-night Dec 24, 2024
94aff73
feat: add the default height of the code editor component
by-night Dec 24, 2024
45f1865
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
Dec 24, 2024
73346f8
feat: workflow email notify node add subject recipient component
Dec 24, 2024
098771b
Merge pull request #18 from Milesight-IoT/feat/workflow-email
Jimco Dec 24, 2024
5cfea29
feat: get node dynamic form config
Jimco Dec 24, 2024
fc774d9
feat: workflow email notify node content change from markdown to text
Dec 25, 2024
d4b1d59
Merge pull request #26 from Milesight-IoT/feat/workflow-email
Jimco Dec 25, 2024
0dd9b15
feat: add type prop for ConfirmDialog
Jimco Dec 25, 2024
90d1086
feat: complete the node dynamic form rendered
Jimco Dec 25, 2024
1a9ef54
feat: add node data validators
Jimco Dec 26, 2024
94ce77f
feat: Code nodes for workflows adjust editor data types
by-night Dec 26, 2024
2ab019a
feat: modify the prop type of ActionLog component
Jimco Dec 26, 2024
4f13971
feat: add node data check
Jimco Dec 26, 2024
3708395
feat: Compatible when the action log component does not have an expan…
by-night Dec 26, 2024
7a73178
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
by-night Dec 26, 2024
9368065
fix: fix workflow service status error
Jimco Dec 26, 2024
2f53a28
feat: The loading state of the action log component is added
by-night Dec 26, 2024
9fe148e
fix: Fixed an issue where the action log component would not rerender
by-night Dec 26, 2024
76fda6f
feat: add validators for workflow data
Jimco Dec 26, 2024
2fe9bb9
fix: change the default value type
nianxh-milesight Dec 24, 2024
6034ff9
fix: update the data type options for the parameter input component
nianxh-milesight Dec 24, 2024
1471b25
refactor: refactor the service invocation parameter settings component
nianxh-milesight Dec 26, 2024
579b285
fix: integrate the API for the workflow list page
nianxh-milesight Dec 26, 2024
29ff246
Merge pull request #29 from nianxh-milesight/feat/workflow
Jimco Dec 26, 2024
931645f
fix: fix data coverage issues caused by verification
Jimco Dec 26, 2024
eb6d51f
fix: fix navigate prevent error on save success
Jimco Dec 26, 2024
1d6985a
fix: add id, version params when is in editing
Jimco Dec 26, 2024
a22ae55
feat: Log modal component docking interface
by-night Dec 26, 2024
b21a4ac
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
by-night Dec 26, 2024
6e641f5
fix: adjust the workflow list page
nianxh-milesight Dec 26, 2024
7439c73
Merge pull request #30 from nianxh-milesight/feat/workflow
nianxh-milesight Dec 26, 2024
0663e85
fix: workflow edit & export
nianxh-milesight Dec 26, 2024
04042bb
Merge pull request #31 from nianxh-milesight/feat/workflow
nianxh-milesight Dec 26, 2024
31e0597
fix: workflow list pagination
nianxh-milesight Dec 27, 2024
b9e91ca
refactor: restore the default value
nianxh-milesight Dec 27, 2024
7ba5a8b
feat: Component adjustment, adapting to backend data structures
Jimco Dec 27, 2024
f5c044a
fix: remove version param form the url query
Jimco Dec 27, 2024
6f6f1ba
fix: adjust workflow list export & service call node
nianxh-milesight Dec 27, 2024
b7e17a6
fix: adjust workflow list api
nianxh-milesight Dec 27, 2024
4442aa5
feat: add new entity select component
by-night Dec 27, 2024
0caf24b
feat: Adds virtual scrolling to the physical drop-down component
by-night Dec 27, 2024
32e4d0e
feat: complete the single node test
Jimco Dec 27, 2024
de68b78
feat: complete workflow test
Jimco Dec 27, 2024
320891e
feat: complete the data import and param reference
Jimco Dec 28, 2024
fd56cd9
feat: add workflow data validators and optimize the overall process
Jimco Dec 30, 2024
cef2b06
feat: optimize the overall process
Jimco Dec 30, 2024
f9a1ba0
feat: The entity select component increases the maxCount props and dy…
by-night Dec 30, 2024
0d91b3a
fix: entity api service params error fixed
Jimco Dec 30, 2024
70d0809
fix: icon and route jump adjustment
Jimco Dec 30, 2024
da1492f
feat: Added the log modal entry
by-night Dec 30, 2024
3cbb061
Merge branch 'feat/workflow' into feat/entity-select
by-night Dec 30, 2024
0467ad5
feat: optimize ui and enhance code robust
Jimco Dec 30, 2024
8240555
fix: remove the basic data change to prevent route jump
Jimco Dec 30, 2024
8ae953d
fix: temporarily ignore entity type errors
Jimco Dec 30, 2024
b4c8346
fix: adjust workflow delete & export api
nianxh-milesight Dec 30, 2024
680673a
fix: change param value type enum
nianxh-milesight Dec 30, 2024
88fc38e
Merge pull request #32 from nianxh-milesight/feat/workflow
nianxh-milesight Dec 30, 2024
338da78
feat: entity select component Added the interface search function
by-night Dec 30, 2024
739d967
feat: performance optimization to avoid crashing when dragging nodes
Jimco Dec 30, 2024
c6f335c
fix: modify the logic for disabling deletion
nianxh-milesight Dec 30, 2024
d323a8e
feat: the edge start/end points to the handler center position
Jimco Dec 30, 2024
5480063
feat: add identify prop for trigger node data
Jimco Dec 30, 2024
fbea673
feat: Hide the submenu as the entity select component scrolls
by-night Dec 30, 2024
c6deaf4
feat: Entity drop-down Component Adds Device list to the selected effect
by-night Dec 31, 2024
f7039c2
feat: real time rendering of node names on nodes and config panels
Jimco Dec 31, 2024
51fdff1
feat: add placeholder and popperWidth prop
by-night Dec 31, 2024
0c07cee
refactor: optimize frequent data updates
nianxh-milesight Dec 31, 2024
1001329
feat: Use pass-through props instead of react context
by-night Dec 31, 2024
5792e09
feat: Resolve editor component css variable conflicts and Format the …
by-night Dec 31, 2024
e236b90
Merge branch 'feat/workflow' into feat/entity-select
by-night Dec 31, 2024
c564579
feat: prevent navigate jump when node form data change
Jimco Dec 31, 2024
5f88eed
feat: Entity select component supports custom 'value' types
by-night Jan 1, 2025
e362d65
feat: use entity store to cache data
by-night Jan 1, 2025
b516bac
feat: Adjust entity select popper position calculation
by-night Jan 1, 2025
0fdb57b
fix: reset node form data when the node is blur
Jimco Jan 2, 2025
376e63c
feat: apply entity select component
by-night Jan 2, 2025
01af9ef
feat: code editor component remove the default value of onChange
by-night Jan 2, 2025
a32262e
feat: Added version query workflow interface in log popup
by-night Jan 2, 2025
4b8a188
feat: optimize workflow list and add status filter
Jimco Jan 2, 2025
ea9ed34
fix: adjustment the test logs type
Jimco Jan 2, 2025
02e829e
fix: adjustment the test logs type
Jimco Jan 2, 2025
c9c3a10
fix: Fixed text loss caused by switching languages in the code editor
by-night Jan 2, 2025
76e8bcb
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
by-night Jan 2, 2025
d7e817a
fix: fixed text copy failed error caused by tabindex attribute
Jimco Jan 2, 2025
7097916
fix: Optimize the rounded corners of the action log component
by-night Jan 2, 2025
344a26d
feat: Adjust the branch header display of the action log component
by-night Jan 2, 2025
8809566
feat: get the exactly design data to render run log
Jimco Jan 2, 2025
bb8bc5b
fix: modify the code expression validators based on the new data type
Jimco Jan 2, 2025
fd3afd4
feat: Tweak the onChange logic of the code editor
by-night Jan 2, 2025
ec7080a
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
by-night Jan 2, 2025
83412f6
feat: The code editor component in the workflow retains the relevant api
by-night Jan 2, 2025
87ee45c
feat: Optimize the rendering logic of the action log tree structure
by-night Jan 3, 2025
d4d1766
feat: complete the flow data recovery from log
Jimco Jan 3, 2025
4fb4e7f
Merge pull request #33 from Milesight-IoT/feat/entity-select
Jimco Jan 3, 2025
fa2aa6a
feat: The entity select component supports custom value sources for '…
by-night Jan 3, 2025
7aafde5
feat: Remove the Json parse logic for the entity select component data
by-night Jan 3, 2025
7110850
feat: Solve the problem that search results do not reset after out-of…
by-night Jan 3, 2025
fddc348
feat: Adjust the editor component javascript language to js
by-night Jan 3, 2025
eb3a237
feat: optimize the node content render
Jimco Jan 3, 2025
4d890a4
feat: Adjust the display of options in the entity select component
by-night Jan 3, 2025
fa85b9b
Merge branch 'feat/workflow' of github.com:Milesight-IoT/beaver-iot-w…
by-night Jan 3, 2025
bd6e43c
fix: optimize ParamInputSelect component data and style
Jimco Jan 3, 2025
16656b1
fix: range length validator error fixed
Jimco Jan 3, 2025
2868e79
fix: optimize the ParamSelect component style
Jimco Jan 4, 2025
d0bd1d3
feat: Merge the workflow code
Lynn-Bing Jan 4, 2025
ca6b54e
feat: Merge the entity selection component code
Lynn-Bing Jan 4, 2025
a0dd00f
feat: Disable the creation entry for custom entities based on the wor…
Lynn-Bing Jan 4, 2025
0210cf0
feat: Modify the theme color of the dashboard chart
Lynn-Bing Jan 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ WEB_API_ORIGIN=/
# Websocket Host 地址
WEB_WS_HOST=/
# 接口 API 代理地址
WEB_API_PROXY=https://beaver-iot.milesight.com/api/v1
# WEB_API_PROXY=https://demo.beaver-iot.com/api/v1
WEB_API_PROXY=http://192.168.43.48:9200
# WebSocket 代理地址
WEB_SOCKET_PROXY=wss://beaver-iot.milesight.com
# WEB_SOCKET_PROXY=wss://demo.beaver-iot.com
WEB_SOCKET_PROXY=ws://192.168.43.48:9200

# Oauth client ID
OAUTH_CLIENT_ID=iab
Expand Down
55 changes: 28 additions & 27 deletions apps/web/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
# Beaver IoT Web

This project is the Beaver IoT Web application, built upon the following core technologies:
本项目是 Beaver IoT Web 应用,基础技术栈包括:

- View Library: React
- Request Library: Axios
- Component Library: Ysd-iot
- State Management: Zustand
- Internationalization: react-intl-universal
- General Hooks: Ahooks
- 视图库:React
- 请求库:Axios
- 组件库:Ysd-iot
- 状态管理:Zustand
- 国际化:react-intl-universal
- 通用 Hook:Ahooks

## Directory Structure
## 目录结构

```
@app/web
├── public
├── src
│ ├── assets # Image assets
│ ├── components # Global components
│ ├── hooks # Global hooks
│ ├── layouts # Layout components
│ ├── pages # Route page resources
│ ├── assets # 图片资源
│ ├── components # 全局组件
│ ├── hooks # 全局 Hooks
│ ├── layouts # 布局组件
│ ├── pages # 路由页面资源
│ │ ├── page-a
│ │ │ ├── components # Page components
│ │ │ ├── index.ts # Page entry
│ │ │ ├── store.ts # Page shared state
│ │ │ ├── components # 页面组件
│ │ │ ├── index.ts # 页面入口
│ │ │ ├── store.ts # 页面共享状态
│ │ │ ├── style.ts
│ │ │ └── ...
│ │ │
│ │ └── page-b
│ │
│ ├── routes # Route configuration
│ ├── services # Common services
│ ├── stores # Global state
│ ├── styles # Global styles
│ ├── main.ts # Application entry
│ └── typings.d.ts # Type definitions
│ ├── routes # 路由配置
│ ├── services # 通用服务
│ ├── stores # 全局状态
│ ├── styles # 全局样式
│ ├── main.ts # 应用入口
│ └── typings.d.ts # 类型约束
├── index.html # Entry HTML
├── index.html # 入口 Html
├── package.json
├── tsconfig.json
├── tsconfig.node.json
└── vite.config.ts # Build configuration
└── vite.config.ts # 构建配置
```

## Development and Maintenance
## 开发维护

### Alias Support
### 别名支持

- `'@': './src/*'` src 路径别名

- `'@': './src/*'` src path alias
13 changes: 13 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,25 @@
"ts-check": "tsc --noEmit"
},
"dependencies": {
"@codemirror/commands": "^6.7.1",
"@codemirror/lang-java": "^6.0.1",
"@codemirror/lang-javascript": "^6.2.2",
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lang-markdown": "^6.3.1",
"@codemirror/lang-python": "^6.1.6",
"@codemirror/lang-yaml": "^6.1.2",
"@codemirror/language": "^6.10.6",
"@codemirror/legacy-modes": "^6.4.2",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@milesight/locales": "workspace:*",
"@milesight/shared": "workspace:*",
"@mui/material": "^6.1.0",
"@mui/x-data-grid": "^7.16.0",
"@mui/x-date-pickers": "^7.18.0",
"@uiw/codemirror-theme-vscode": "^4.23.7",
"@uiw/react-codemirror": "^4.23.6",
"@xyflow/react": "^12.3.5",
"ahooks": "^3.8.1",
"axios": "^1.7.7",
"chart.js": "^4.4.4",
Expand All @@ -37,6 +49,7 @@
"react-intl-universal": "^2.11.1",
"react-router": "^6.26.1",
"react-router-dom": "^6.26.1",
"uuid": "^11.0.3",
"zustand": "^4.5.5"
},
"devDependencies": {
Expand Down
144 changes: 144 additions & 0 deletions apps/web/src/components/code-editor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
## `CodeEditor` Component Usage

### 1. Default Usage
```jsx
const App = () => {
return (
<CodeEditor defaultEditorLang="markdown" />;
)
}
```

### 2. Controlled Editor Language and Content
```jsx
const App = () => {
const [editorLang, setEditorLang] = useState('markdown');
const [editorContent, setEditorContent] = useState('Hello World');

return (
<CodeEditor
editorLang={editorLang}
onLangChange={setEditorLang}
value={editorContent}
onChange={setEditorContent}
/>
)
}
```

### 3. Hide Certain Features
```jsx
const App = () => {
return (
<CodeEditor
// Hide function fold buttons
showFold={false}
// Hide line numbers
showLineNumber={false}
// ...other properties
/>
)
}
```

### 4. Read-Only/Edit Mode

```jsx
const App = () => {
return (
<CodeEditor
// Read-only mode: Editing is not allowed, but the cursor position will be shown
readOnly
// Edit mode: Only selection and copying are allowed, no cursor or editing behavior
editable
/>
);
};
```

### 5. Custom Header

- Simple adjustments, such as modifying only the title and icon
```jsx
import { useCallback } from 'react';
import { CheckCircleIcon } from '@milesight/shared/src/components';
import { CodeEditor, CodeEditorToolbar, type EditorToolbarProps } from '@/components';

const App = () => {
const renderHeader = useCallback(
(props: EditorToolbarProps) => (
<CodeEditorToolbar {...props} icon={<CheckCircleIcon />} title="xxxx" />
),
[],
);

return <CodeEditor renderHeader={renderHeader} />;
};
```
OR
```jsx
import { CheckCircleIcon } from '@milesight/shared/src/components';
import { CodeEditor } from '@/components';

const App = () => {
return <CodeEditor icon={<CheckCircleIcon />} title="xxxx" />;
};
```


- Custom layout, but using some components like `CodeEditorSelect`
```jsx
import { useCallback } from 'react';
import {
CodeEditor,
CodeEditorSelect,
COMMON_EDITOR_HEADER_CLASS,
type EditorToolbarProps,
} from '@/components';

const App = () => {
const renderHeader = useCallback(
(props: EditorToolbarProps) => (
<div className={COMMON_EDITOR_HEADER_CLASS}>
{/* Reuse the select component */}
<CodeEditorSelect
{...props}
renderOptions={options =>
options.map(option => <p key={option.value}>{option.label}</p>)
}
/>
<div>Some styles you want</div>
</div>
),
[],
);

return <CodeEditor renderHeader={renderHeader} />;
};
```

- Fully custom header component
```jsx
import { useCallback } from 'react';
import { CodeEditor, COMMON_EDITOR_HEADER_CLASS, type EditorToolbarProps } from '@/components';

const App = () => {
const renderHeader = useCallback((props: EditorToolbarProps) => {
const { editorHandlers } = props;
const { redo, undo, insert } = editorHandlers || {};

return (
<div className={COMMON_EDITOR_HEADER_CLASS}>
<div>Content</div>
<div>
<div onClick={undo}>undo</div>
<div onClick={redo}>redo</div>
<div onClick={() => insert('Value you want to insert')}>insert</div>
</div>
</div>
);
}, []);

return <CodeEditor renderHeader={renderHeader} />;
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import EditorHeader from '../header';
import type { EditorProps, EditorToolbarProps } from '../../types';

export default React.memo((props: EditorToolbarProps & Pick<EditorProps, 'renderHeader'>) => {
const { renderHeader, ...rest } = props;

if (renderHeader) return renderHeader(rest);
return <EditorHeader {...rest} />;
});
89 changes: 89 additions & 0 deletions apps/web/src/components/code-editor/components/editor/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { forwardRef, useCallback, useMemo } from 'react';
import cls from 'classnames';
import CodeMirror, { type ReactCodeMirrorRef } from '@uiw/react-codemirror';
// support language
import { yaml } from '@codemirror/lang-yaml';
import { json } from '@codemirror/lang-json';
import { java } from '@codemirror/lang-java';
import { python } from '@codemirror/lang-python';
import { javascript } from '@codemirror/lang-javascript';
import { markdown } from '@codemirror/lang-markdown';
// extension language
import { StreamLanguage } from '@codemirror/language';
import { groovy } from '@codemirror/legacy-modes/mode/groovy';

import type { EditorContentProps, EditorSupportLang } from '../../types';
import './style.less';

interface IProps extends EditorContentProps {
editorLang?: EditorSupportLang;
editorValue: string;
setEditorValue: (value: string) => void;
}
/**
* @docs https://github.com/uiwjs/react-codemirror
*/
export const CodeEditorContent = forwardRef<ReactCodeMirrorRef, IProps>((props, ref) => {
const {
showLineNumber = true,
showFold = true,
editable = true,
readOnly = false,
editorLang,
editorValue,
theme,
setEditorValue,
...rest
} = props;

/** editor input change callback */
const onInputChange = useCallback(
(value: string) => {
setEditorValue(value);
},
[setEditorValue],
);

/** Select the corresponding extension based on the language */
const extensions = useMemo(() => {
switch (editorLang) {
case 'yaml':
return [yaml()];
case 'json':
return [json()];
case 'mvel':
// The mvel language is similar to java, which is used here for highlighting
return [java()];
case 'python':
return [python()];
case 'js':
return [javascript()];
case 'groovy':
return [StreamLanguage.define(groovy)];
case 'markdown':
return [markdown()];
case 'text':
default:
return [];
}
}, [editorLang]);

return (
<CodeMirror
{...rest}
ref={ref}
className={cls('ms-code-editor-content', {
[`ms-editor__lineNumbers--hide`]: !showLineNumber,
[`ms-editor__foldGutter--hide`]: !showFold,
})}
value={editorValue}
extensions={extensions}
onChange={onInputChange}
theme={theme}
readOnly={readOnly}
editable={editable}
/>
);
});

export default React.memo(CodeEditorContent);
Loading