Skip to content

Commit 8f40c81

Browse files
committed
重构目录
1 parent 9424c80 commit 8f40c81

File tree

17 files changed

+109
-104
lines changed

17 files changed

+109
-104
lines changed

src/example/WorkflowEditor/WorkFlowEditorInner.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Avatar, Button, Dropdown, MenuProps, Space } from "antd"
33
import { memo, useCallback, useMemo, useState } from "react"
44
import { styled } from "styled-components"
55
import classNames from "classnames"
6-
import { NavTabs, Toolbar, WorkflowDiagram, useImport } from "../../workflow-editor"
6+
import { NavTabs, Toolbar, FlowEditorCanvas, useImport } from "../../workflow-editor"
77
import { useTranslate } from "../../workflow-editor/react-locales"
88
import { useExport } from "../../workflow-editor"
99
import { PublishButton } from "./PublishButton"
@@ -101,7 +101,7 @@ export const WorkFlowEditorInner = memo((props: {
101101
</Toolbar>
102102
{
103103
selectedTab === TabType.flowDesign &&
104-
<WorkflowDiagram />
104+
<FlowEditorCanvas />
105105
}
106106
</Container>
107107
)

src/example/WorkflowEditor/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { memo } from "react"
22
import { WorkFlowEditorInner } from "./WorkFlowEditorInner"
33
import { ILocales } from "@rxdrag/locales"
44
import { IThemeToken } from "../../workflow-editor"
5-
import { IMaterialUIs, WorkFlowScope } from "../../workflow-editor/"
5+
import { IMaterialUIs, FlowEditorScope } from "../../workflow-editor/"
66

77
export type WorkflowEditorProps = {
88
themeMode?: 'dark' | 'light',
@@ -15,14 +15,14 @@ export type WorkflowEditorProps = {
1515
export const WorkflowEditor = memo((props: WorkflowEditorProps) => {
1616
const { themeMode, themeToken, lang, locales, materialUis, ...other } = props;
1717
return (
18-
<WorkFlowScope
18+
<FlowEditorScope
1919
mode={themeMode}
2020
themeToken={themeToken}
2121
lang={lang}
2222
locales={locales}
2323
materialUis = {materialUis}
2424
>
2525
<WorkFlowEditorInner {...other} />
26-
</WorkFlowScope>
26+
</FlowEditorScope>
2727
)
2828
})

src/workflow-editor/WorkflowDiagram/WorkflowDiagram.tsx renamed to src/workflow-editor/FlowEditor/FlowEditorCanvas.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ZoomBar } from "./ZoomBar"
66
import { SettingsPanel } from "./SettingsPanel"
77
import { OperationBar } from "./OperationBar"
88

9-
const DiagramContainer = styled.div`
9+
const CanvasContainer = styled.div`
1010
flex: 1;
1111
display: flex;
1212
flex-flow: column;
@@ -40,7 +40,7 @@ export interface IPosition {
4040
scrollTop: number
4141
}
4242

43-
export const WorkflowDiagram = memo((
43+
export const FlowEditorCanvas = memo((
4444
props: {
4545
className?: string,
4646
style?: CSSProperties,
@@ -99,7 +99,7 @@ export const WorkflowDiagram = memo((
9999
}, [])
100100

101101
return (
102-
<DiagramContainer {...props}>
102+
<CanvasContainer {...props}>
103103
<Canvas
104104
ref={canvasRef}
105105
className={"flow-canvas"}
@@ -126,6 +126,6 @@ export const WorkflowDiagram = memo((
126126
onZoomOut={haneldZoomOut}
127127
/>
128128
<SettingsPanel />
129-
</DiagramContainer >
129+
</CanvasContainer >
130130
)
131131
})
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { useToken } from "antd/es/theme/internal";
2+
import { memo, useMemo, useEffect } from "react";
3+
import { ThemeProvider } from "styled-components";
4+
import { EditorEngine } from "../../classes";
5+
import { WorkflowEditorStoreContext } from "../../contexts";
6+
import { INodeMaterial, IMaterialUIs } from "../../interfaces";
7+
import { useTranslate } from "../../react-locales";
8+
import { IThemeToken } from "../../theme";
9+
import { defaultMaterials } from "../defaultMaterials";
10+
11+
export const FlowEditorScopeInner = memo((props: {
12+
mode?: 'dark' | 'light',
13+
themeToken?: IThemeToken,
14+
children?: React.ReactNode,
15+
materials?: INodeMaterial[],
16+
materialUis?: IMaterialUIs,
17+
}) => {
18+
const { mode, children, themeToken, materials, materialUis } = props;
19+
const [, token] = useToken();
20+
const t = useTranslate()
21+
22+
const theme: { token: IThemeToken, mode?: 'dark' | 'light' } = useMemo(() => {
23+
return {
24+
token: themeToken || token,
25+
mode
26+
}
27+
}, [mode, themeToken, token])
28+
const store: EditorEngine = useMemo(() => {
29+
return new EditorEngine()
30+
}, [])
31+
32+
useEffect(() => {
33+
store.t = t
34+
}, [store, t])
35+
36+
useEffect(() => {
37+
const oldMaterials = store.materials
38+
const oldMaterialUis = store.materialUis
39+
store.materials = [...oldMaterials, ...defaultMaterials, ...materials || []]
40+
store.materialUis = { ...oldMaterialUis, ...materialUis }
41+
return () => {
42+
store.materials = oldMaterials;
43+
store.materialUis = oldMaterialUis;
44+
}
45+
}, [materialUis, materials, store])
46+
47+
return (
48+
<WorkflowEditorStoreContext.Provider value={store}>
49+
<ThemeProvider theme={theme}>
50+
{
51+
store && children
52+
}
53+
</ThemeProvider>
54+
</WorkflowEditorStoreContext.Provider>
55+
)
56+
})
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { memo, useEffect, useState } from "react"
2+
import { IThemeToken } from "../../theme"
3+
import { ConfigRoot } from "../ConfigRoot"
4+
import { ILocales, LocalesManager } from "@rxdrag/locales"
5+
import { LocalesContext } from "../../react-locales"
6+
import { defalutLocales } from "../../locales"
7+
import { IMaterialUIs, INodeMaterial } from "../../interfaces/material"
8+
import { FlowEditorScopeInner } from "./FlowEditorScopeInner"
9+
10+
export const FlowEditorScope = memo((props: {
11+
mode?: 'dark' | 'light',
12+
themeToken?: IThemeToken,
13+
children?: React.ReactNode,
14+
lang?: string,
15+
locales?: ILocales,
16+
materials?: INodeMaterial[],
17+
materialUis?: IMaterialUIs,
18+
}) => {
19+
const { children, lang, locales, ...other } = props
20+
const [localesManager, setLocalesManager] = useState(new LocalesManager(lang, defalutLocales))
21+
22+
useEffect(() => {
23+
locales && localesManager.registerLocales(locales)
24+
}, [localesManager, locales])
25+
26+
useEffect(() => {
27+
//暂时这么处理,后面把语言切换移动到locales-react
28+
setLocalesManager(new LocalesManager(lang, defalutLocales))
29+
}, [lang])
30+
31+
return (
32+
<LocalesContext.Provider value={localesManager}>
33+
<ConfigRoot themeMode={other.mode}>
34+
<FlowEditorScopeInner {...other}>
35+
{children}
36+
</FlowEditorScopeInner>
37+
</ConfigRoot>
38+
</LocalesContext.Provider>
39+
)
40+
})

0 commit comments

Comments
 (0)