Skip to content

Commit

Permalink
feat: 部分api优化
Browse files Browse the repository at this point in the history
  • Loading branch information
jile1997 committed Jan 8, 2025
1 parent 592af80 commit 57ed161
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
11 changes: 7 additions & 4 deletions packages/x-flow/src/XFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import '@xyflow/react/dist/style.css';
import { useEventListener, useMemoizedFn } from 'ahooks';
import produce, { setAutoFreeze } from 'immer';
import { debounce } from 'lodash';
import { debounce, isFunction } from 'lodash';
import type { FC } from 'react';
import React, {
memo,
Expand Down Expand Up @@ -86,7 +86,7 @@ const XFlow: FC<FlowProps> = memo(props => {
const { settingMap, globalConfig,readOnly } = useContext(ConfigContext);
const [openPanel, setOpenPanel] = useState<boolean>(true);
const [openLogPanel, setOpenLogPanel] = useState<boolean>(true);
const { onNodeClick,panel = {} as any } = props;
const { onNodeClick } = props;

useEffect(() => {
zoomTo(0.8);
Expand Down Expand Up @@ -147,8 +147,8 @@ const XFlow: FC<FlowProps> = memo(props => {
id: uuid(),
type: 'custom',
data: {
...data,
title: `${title}_${uuid4()}`,
...data,
},
position: {
x: 0,
Expand Down Expand Up @@ -268,6 +268,7 @@ const XFlow: FC<FlowProps> = memo(props => {
}, [activeNode?.id]);

const deletable = globalConfig?.edge?.deletable ?? true;
const panelonClose = globalConfig?.nodePanel?.onClose

return (
<div id="xflow-container" ref={workflowContainerRef}>
Expand Down Expand Up @@ -341,7 +342,9 @@ const XFlow: FC<FlowProps> = memo(props => {
if (!activeNode?._status || !openLogPanel) {
setActiveNode(null);
}
panel.onClose && panel.onClose(activeNode?.id)
if(isFunction(panelonClose)){
panelonClose(activeNode?.id)
}
}}
node={activeNode}
data={activeNode?.values}
Expand Down
2 changes: 1 addition & 1 deletion packages/x-flow/src/components/CustomEdge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export default memo((edge: any) => {
id: targetId,
type: 'custom',
data: {
...data,
title: `${title}_${uuid4()}`,
...data,
},
position: { x, y },
});
Expand Down
2 changes: 1 addition & 1 deletion packages/x-flow/src/components/CustomNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export default memo((props: any) => {
id: targetId,
type: 'custom',
data: {
...data,
title: `${title}_${uuid4()}`,
...data,
},
position: { x, y },
};
Expand Down
7 changes: 1 addition & 6 deletions packages/x-flow/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface TNodePanel {
// 配置面板属性设置
width?: string | number; // 配置面板宽度
hideDesc?: boolean; // 配置面板描述
onClose?:(activeNodeId:string)=>void
}

export interface TNodeSelector {
Expand Down Expand Up @@ -99,11 +100,6 @@ export interface THandle{
// isConnectableEnd?:boolean
isValidConnection?:HandleProps['isValidConnection']
}

export interface TPanel{
onClose:(activeNodeId:string)=>void
}

export interface FlowProps {
initialValues?: {
nodes: any[];
Expand All @@ -130,7 +126,6 @@ export interface FlowProps {
};
logPanel?: TLogPanel; // 日志面板配置
readOnly?:boolean//只读模式
panel?:TPanel //表单配置面板
onNodeClick?: NodeMouseHandler;
onMenuItemClick?: (itemInfo: ItemInfo, defaultAction: () => void) => void;
clickAddNode?:(type:string,nodeItem:TNodeItem,addNode:(initData?:Record<string,any>)=>void)=>void
Expand Down

0 comments on commit 57ed161

Please sign in to comment.