Skip to content

Commit

Permalink
Merge branch 'xflow' of https://github.com/alibaba/x-render into xflow
Browse files Browse the repository at this point in the history
  • Loading branch information
昔梦 committed Jan 6, 2025
2 parents a29111c + 54994b7 commit ca574b5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/x-flow/src/components/NodesPopover/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useClickAway } from 'ahooks';
import { Popover } from 'antd';
import { isFunction } from 'lodash';
import React, {
forwardRef,
useCallback,
Expand All @@ -24,7 +25,7 @@ export default forwardRef((props: any, popoverRef) => {
const closeRef: any = useRef<HTMLButtonElement>(null);
const [open, setOpen] = useState(false);

const { settings, nodeSelector, antdVersion ,readOnly }: any = useContext(ConfigContext);
const { settings, nodeSelector, antdVersion ,readOnly ,clickAddNode }: any = useContext(ConfigContext);
const { showSearch, popoverProps = { placement: 'top' } } =
nodeSelector || {};

Expand All @@ -41,13 +42,20 @@ export default forwardRef((props: any, popoverRef) => {
}, ref);

const handCreateNode = useCallback<any>(({ type }) => {
if (type === 'Switch') {
addNode({ _nodeType: type, list: [{ '_id':`${uuid()}`}] });
} else if (type === 'Parallel') {
addNode({ _nodeType: type, list: [{ _id: `id_${uuid()}` }, { _id: `id_${uuid()}` }] });
} else {
addNode({ _nodeType: type });
if (isFunction(clickAddNode)) {
clickAddNode(type, ( data = {} )=>{
addNode({ _nodeType: type, ...data })
});
}else{
if (type === 'Switch') {
addNode({ _nodeType: type, list: [{ '_id':`${uuid()}`}] });
} else if (type === 'Parallel') {
addNode({ _nodeType: type, list: [{ _id: `id_${uuid()}` }, { _id: `id_${uuid()}` }] });
} else {
addNode({ _nodeType: type });
}
}

setOpen(false);
onNodeSelectPopoverChange && onNodeSelectPopoverChange(false);
}, []);
Expand All @@ -56,7 +64,7 @@ export default forwardRef((props: any, popoverRef) => {
setTimeout(() => {
setIsAddingNode(true);
closeRef.current = true;
if(!readOnly){
if (!readOnly) {
setOpen(true);
}
}, 50);
Expand Down
1 change: 1 addition & 0 deletions packages/x-flow/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export interface FlowProps {
panel?:TPanel //表单配置面板
onNodeClick?: NodeMouseHandler;
onMenuItemClick: (itemInfo: ItemInfo, defaultAction: () => void) => void;
clickAddNode:(type:string,addNode:(initData?:Record<string,any>)=>void)=>void
// 单点调试方法
}
interface ItemInfo {
Expand Down
2 changes: 2 additions & 0 deletions packages/x-flow/src/withProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function withProvider<T>(
onMenuItemClick,
antdVersion ='V4',
readOnly,
clickAddNode,
...restProps
} = props;
const settingMap = useMemo(() => {
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function withProvider<T>(
antdVersion,
onMenuItemClick,
readOnly,
clickAddNode,
widgets: {
...defaultWidgets,
...widgets,
Expand Down

0 comments on commit ca574b5

Please sign in to comment.