Skip to content

Commit dffb944

Browse files
committed
backup
1 parent a71db67 commit dffb944

File tree

17 files changed

+214
-70
lines changed

17 files changed

+214
-70
lines changed

package-lock.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"dependencies": {
66
"@ant-design/icons": "^5.1.4",
77
"@reduxjs/toolkit": "^1.9.5",
8+
"@rxdrag/locales": "^0.2.2",
89
"@types/jest": "^27.5.2",
910
"@types/node": "^16.18.39",
1011
"@types/react": "^18.2.18",
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { memo, useEffect, useMemo, useState } from "react"
2+
import { ThemeProvider } from "styled-components"
3+
import { IThemeToken } from "../theme"
4+
import { useToken } from "antd/es/theme/internal"
5+
import { EditorStore } from "../classes"
6+
import { WorkflowEditorStoreContext } from "../contexts"
7+
import { ConfigRoot } from "./ConfigRoot"
8+
import { ILocales, LocalesManager } from "@rxdrag/locales"
9+
import { LocalesContext } from "../react-locales"
10+
import { defalutLocales } from "../locales"
11+
12+
const WorkFlowScopeInner = memo((props: {
13+
mode?: 'dark' | 'light',
14+
themeToken?: IThemeToken,
15+
children?: React.ReactNode,
16+
}) => {
17+
const { mode, children, themeToken } = props;
18+
const [, token] = useToken();
19+
20+
const theme: { token: IThemeToken, mode?: 'dark' | 'light' } = useMemo(() => {
21+
return {
22+
token: themeToken || token,
23+
mode
24+
}
25+
}, [mode, themeToken, token])
26+
const store: EditorStore = useMemo(() => {
27+
return new EditorStore()
28+
}, [])
29+
30+
31+
return (
32+
<WorkflowEditorStoreContext.Provider value={store}>
33+
<ThemeProvider theme={theme}>
34+
{
35+
children
36+
}
37+
</ThemeProvider>
38+
</WorkflowEditorStoreContext.Provider>
39+
)
40+
})
41+
42+
export const WorkFlowScope = memo((props: {
43+
mode?: 'dark' | 'light',
44+
themeToken?: IThemeToken,
45+
children?: React.ReactNode,
46+
lang?: string,
47+
locales?: ILocales
48+
}) => {
49+
const { children, lang, locales, ...other } = props
50+
const [localesManager] = useState(new LocalesManager(lang, defalutLocales))
51+
52+
useEffect(() => {
53+
locales && localesManager.registerLocales(locales)
54+
}, [localesManager, locales])
55+
56+
return (
57+
<LocalesContext.Provider value={localesManager}>
58+
<ConfigRoot themeMode={other.mode}>
59+
<WorkFlowScopeInner {...other}>
60+
{children}
61+
</WorkFlowScopeInner>
62+
</ConfigRoot>
63+
</LocalesContext.Provider>
64+
)
65+
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { memo } from "react"
2+
import { styled } from "styled-components"
3+
import { ZoomBar } from "../ZoomBar"
4+
import { EndNode } from "../nodes/EndNode"
5+
import { StartNode } from "../nodes/StartNode"
6+
7+
const Canvas = styled.div`
8+
flex: 1;
9+
background-color: ${props => props.theme.mode === "light" ? "#f5f5f7" : undefined} ;
10+
padding: 56px 16px;
11+
position: relative;
12+
cursor: grab;//grabbing
13+
`
14+
15+
export const WorkflowDiagram = memo(() => {
16+
return (
17+
<Canvas style={{ transform: `scale(1)` }}>
18+
<StartNode />
19+
<EndNode />
20+
<ZoomBar />
21+
</Canvas>
22+
)
23+
})

src/workflow-editor/WorkflowEditor/WorkFlowEditorInner.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { LeftOutlined, RocketOutlined } from "@ant-design/icons"
22
import { Avatar, Button, Space } from "antd"
33
import { memo } from "react"
44
import { styled } from "styled-components"
5-
import { ZoomBar } from "../ZoomBar"
6-
import { StartNode } from "../nodes/StartNode"
5+
import { WorkflowDiagram } from "../WorkflowDiagram"
76

87
const Container = styled.div`
98
flex:1;
@@ -52,16 +51,7 @@ const NavIcon = styled.span`
5251
}
5352
`
5453

55-
const Canvas = styled.div`
56-
flex: 1;
57-
background-color: ${props => props.theme.mode === "light" ? "#f5f5f7" : undefined} ;
58-
padding: 56px 16px;
59-
position: relative;
60-
cursor: grab;//grabbing
61-
`
62-
63-
export const WorkFlowEditorInner = memo((props: {
64-
}) => {
54+
export const WorkFlowEditorInner = memo((props: {}) => {
6555
return (
6656
<Container className="workflow-editor">
6757
<Toolbar>
@@ -82,10 +72,7 @@ export const WorkFlowEditorInner = memo((props: {
8272
<Button type="primary">发布</Button>
8373
</Space>
8474
</Toolbar>
85-
<Canvas style={{ transform: `scale(1)` }}>
86-
<StartNode />
87-
<ZoomBar />
88-
</Canvas>
75+
<WorkflowDiagram />
8976
</Container>
9077
)
9178
})

src/workflow-editor/WorkflowEditor/WorkFlowShell.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { memo } from "react"
22
import { WorkFlowEditorInner } from "./WorkFlowEditorInner"
3-
import { ConfigRoot } from "./ConfigRoot"
4-
import { WorkFlowShell } from "./WorkFlowShell"
3+
import { WorkFlowScope } from "../WorkflowDiagram/WorkFlowScope"
54
import { IThemeToken } from "../theme"
5+
import { ILocales } from "@rxdrag/locales"
66

7-
8-
export const WorkflowEditor = memo((props: {
9-
themeMode?: "dark" | "light",
7+
export type WorkflowEditorProps = {
8+
themeMode?: 'dark' | 'light',
109
themeToken?: IThemeToken,
11-
}) => {
10+
lang?: string,
11+
locales?: ILocales
12+
}
13+
14+
export const WorkflowEditor = memo((props: WorkflowEditorProps) => {
1215
const { themeMode, themeToken } = props;
1316
return (
14-
<ConfigRoot themeMode={themeMode}>
15-
<WorkFlowShell mode={themeMode} themeToken={themeToken}>
16-
<WorkFlowEditorInner />
17-
</WorkFlowShell>
18-
</ConfigRoot>
17+
<WorkFlowScope mode={themeMode} themeToken={themeToken}>
18+
<WorkFlowEditorInner />
19+
</WorkFlowScope>
1920
)
2021
})

src/workflow-editor/locales.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ILocales } from "@rxdrag/locales";
2+
3+
export const defalutLocales: ILocales = {
4+
"zh-CN": {
5+
baseSettings: "基础设置",
6+
publish: "发布",
7+
},
8+
'en-US': {
9+
baseSettings: "Base Settings",
10+
publish: "Publish",
11+
}
12+
}

src/workflow-editor/nodes/AddButton/index.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PlusOutlined } from "@ant-design/icons"
2+
import { Popover } from "antd"
23
import { memo } from "react"
34
import { styled } from "styled-components"
45

@@ -23,11 +24,11 @@ const AddButtonBox = styled.div`
2324
margin: auto;
2425
width: 2px;
2526
height: 100%;
26-
background-color: #cacaca
27+
background-color: ${props => props.theme.mode === "light" ? "#cacaca" : "rgba(255,255,255,0.35)"};
2728
}
2829
`
2930

30-
const Button = styled.div`
31+
const ButtonShell = styled.div`
3132
user-select: none;
3233
width: 240px;
3334
padding: 20px 0 32px;
@@ -70,11 +71,13 @@ const Button = styled.div`
7071
export const AddButton = memo(() => {
7172
return (
7273
<AddButtonBox className="add-node-button-box">
73-
<Button>
74-
<div className="btn">
75-
<PlusOutlined />
76-
</div>
77-
</Button>
74+
<ButtonShell>
75+
<Popover placement="rightTop" title={"text"} content={"content"} trigger="click">
76+
<div className="btn">
77+
<PlusOutlined />
78+
</div>
79+
</Popover>
80+
</ButtonShell>
7881
</AddButtonBox>
7982
)
8083
})

0 commit comments

Comments
 (0)