Skip to content

Commit 5e29959

Browse files
author
昔梦
committed
fix:antdVersion配置化显示传递
1 parent 8ba0943 commit 5e29959

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

docs/xflow/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ title: API
1818
| globalConfig | 全局的面板和节点配置 | {nodePanel:[TNodePanel](#tnodepanel),nodeView:[TNodeView](#tnodeview),edge:[TEdge](#tedge)} | |
1919
| logPanel | 日志面板配置 | [TLogPanel](#tlogpanel) | |
2020
| onNodeClick | 节点点击事件 | `NodeMouseHandler` | |
21+
| antdVersion | antd 的版本 | `V4 \| V5` | `V4` |
2122

2223
## TNodePanel
2324

packages/x-flow/src/components/CustomNode/sourceHandle.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { PlusOutlined } from '@ant-design/icons';
22
import { Handle } from '@xyflow/react';
33
import { Tooltip } from 'antd';
4-
import React, { memo, useMemo, useRef, useState } from 'react';
5-
import { getAntdVersion } from '../../utils';
4+
import React, { memo, useContext, useMemo, useRef, useState } from 'react';
65
import NodeSelectPopover from '../NodesPopover';
6+
import { ConfigContext } from '../../models/context';
7+
78

89
export default memo((props: any) => {
910
const {
@@ -18,10 +19,11 @@ export default memo((props: any) => {
1819
const [isShowTooltip, setIsShowTooltip] = useState(false);
1920
const [openNodeSelectPopover, setOpenNodeSelectPopover] = useState(false);
2021
const popoverRef = useRef(null);
22+
const { antdVersion }: any = useContext(ConfigContext);
23+
2124

2225
const toolTipVersionProps = useMemo(() => {
23-
const version = getAntdVersion();
24-
if (version === 'V5') {
26+
if (antdVersion === 'V5') {
2527
return {
2628
open: isShowTooltip,
2729
};

packages/x-flow/src/components/NodesPopover/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import React, {
1111
} from 'react';
1212
import { useStore } from '../../hooks/useStore';
1313
import { ConfigContext } from '../../models/context';
14-
import { getAntdVersion, uuid } from '../../utils';
14+
import { uuid } from '../../utils';
1515
import NodesMenu from '../NodesMenu';
1616
import './index.less';
1717

@@ -24,7 +24,7 @@ export default forwardRef((props: any, popoverRef) => {
2424
const closeRef: any = useRef<HTMLButtonElement>(null);
2525
const [open, setOpen] = useState(false);
2626

27-
const { settings, nodeSelector }: any = useContext(ConfigContext);
27+
const { settings, nodeSelector, antdVersion }: any = useContext(ConfigContext);
2828
const { showSearch, popoverProps = { placement: 'top' } } =
2929
nodeSelector || {};
3030

@@ -61,8 +61,7 @@ export default forwardRef((props: any, popoverRef) => {
6161
};
6262

6363
const popoverVersionProps = useMemo(() => {
64-
const version = getAntdVersion();
65-
if (version === 'V5') {
64+
if (antdVersion === 'V5') {
6665
return {
6766
open,
6867
onOpenChange: openChange,

packages/x-flow/src/components/PanelContainer/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React, { FC, useContext, useEffect, useMemo, useState } from 'react';
55
import { shallow } from 'zustand/shallow';
66
import { useStore } from '../../hooks/useStore';
77
import { ConfigContext } from '../../models/context';
8-
import { getAntdVersion, safeJsonStringify } from '../../utils';
8+
import { safeJsonStringify } from '../../utils';
99
import createIconFont from '../../utils/createIconFont';
1010
import IconView from '../IconView';
1111
import './index.less';
@@ -41,7 +41,7 @@ const Panel: FC<IPanelProps> = (props: IPanelProps) => {
4141
openLogPanel,
4242
} = props;
4343
// 1.获取节点配置信息
44-
const { settingMap, iconFontUrl, globalConfig }: any =
44+
const { settingMap, iconFontUrl, globalConfig, antdVersion }: any =
4545
useContext(ConfigContext);
4646
const nodeSetting = settingMap[nodeType] || {};
4747
const { nodes, setNodes } = useStore(
@@ -86,8 +86,7 @@ const Panel: FC<IPanelProps> = (props: IPanelProps) => {
8686
const Icon = useMemo(() => createIconFont(iconFontUrl), [iconFontUrl]);
8787

8888
const drawerVersionProps = useMemo(() => {
89-
const version = getAntdVersion();
90-
if (version === 'V5') {
89+
if (antdVersion === 'V5') {
9190
return {
9291
rootClassName: 'custom-node-panel',
9392
open: true,

packages/x-flow/src/components/PanelStatusLogContainer/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Drawer, Popover } from 'antd';
22
import classNames from 'classnames';
33
import React, { FC, useContext, useMemo } from 'react';
44
import { ConfigContext } from '../../models/context';
5-
import { getAntdVersion } from '../../utils';
65
import createIconFont from '../../utils/createIconFont';
76
import IconView from '../IconView';
87
import TitleMenuTooltip from '../NodeContainer/TitleMenuTooltip';
@@ -19,7 +18,7 @@ interface IPanelProps {
1918
const PanelStatusLogContainer: FC<IPanelProps> = (props: IPanelProps) => {
2019
const { onClose, children, nodeType } = props;
2120
// 1.获取节点配置信息
22-
const { settingMap, iconFontUrl, globalConfig, logPanel, widgets }: any =
21+
const { settingMap, iconFontUrl, globalConfig, logPanel, widgets, antdVersion }: any =
2322
useContext(ConfigContext);
2423
const nodeSetting = settingMap[nodeType] || {};
2524
const { nodePanel, iconSvg } = nodeSetting;
@@ -29,8 +28,7 @@ const PanelStatusLogContainer: FC<IPanelProps> = (props: IPanelProps) => {
2928
const isCustomWidget = !Boolean(logPanel?.logWidget && CustomWidget);
3029

3130
const drawerVersionProps = useMemo(() => {
32-
const version = getAntdVersion();
33-
if (version === 'V5') {
31+
if (antdVersion === 'V5') {
3432
return {
3533
rootClassName: classNames('node-log-panel', {
3634
'no-header-line': isCustomWidget,

packages/x-flow/src/utils/index.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
// import { version as antdVersion } from 'antd';
21
import { customAlphabet } from 'nanoid';
32
import tinycolor from 'tinycolor2';
43
export const uuid = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 16);
54
export const uuid4 = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', 4);
65

76
import { isMatch, some, set, get, cloneDeep, has as _has, merge, mergeWith, isUndefined, omitBy } from 'lodash-es';
87

9-
const antdVersion = "5.22.6"
108
export const _set = set;
119
export const _get = get;
1210
export const _cloneDeep = cloneDeep;
@@ -173,16 +171,17 @@ export const transformNodes = (nodes: any[]) => {
173171
});
174172
};
175173

176-
export const getAntdVersion = () => {
177-
const majorVersion = parseInt(antdVersion?.split('.')?.[0], 10);
178-
if (majorVersion >= 5) {
179-
return 'V5';
180-
} else if (majorVersion === 4) {
181-
return 'V4';
182-
} else {
183-
return 'V4';
184-
}
185-
};
174+
// 废弃:
175+
// export const getAntdVersion = () => {
176+
// const majorVersion = parseInt(antdVersion?.split('.')?.[0], 10);
177+
// if (majorVersion >= 5) {
178+
// return 'V5';
179+
// } else if (majorVersion === 4) {
180+
// return 'V4';
181+
// } else {
182+
// return 'V4';
183+
// }
184+
// };
186185

187186
// 安全的JSON.stringify
188187
export function safeJsonStringify(obj: Object) {

packages/x-flow/src/withProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function withProvider<T>(
2828
iconFontUrl,
2929
globalConfig,
3030
logPanel,
31+
antdVersion='V4',
3132
...restProps
3233
} = props;
3334
const settingMap = useMemo(() => {
@@ -52,6 +53,7 @@ export default function withProvider<T>(
5253
iconFontUrl,
5354
globalConfig,
5455
logPanel,
56+
antdVersion,
5557
widgets: {
5658
...defaultWidgets,
5759
...widgets,

0 commit comments

Comments
 (0)