Skip to content

Commit

Permalink
✨ feat(FlowView): add stepless zooming switch (#41)
Browse files Browse the repository at this point in the history
* ✨ feat: step less zooming switch

* 📝 feat: test md disable

* 📝 fix: rm flow eitor demo

---------

Co-authored-by: jiangchu <[email protected]>
  • Loading branch information
ModestFun and jiangchu authored Dec 5, 2023
1 parent cf6b1be commit 51783fc
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 28 deletions.
84 changes: 84 additions & 0 deletions docs/guide/demos/muchNode/CustomNode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Handle, Position } from '@ant-design/pro-flow';
import { FC } from 'react';

interface PipeNodeChild {
title: string;
logo?: string;
id: string;
}

interface PipeNode {
title: string;
logo: string;
des?: string;
children?: PipeNodeChild[];
}

const CustomNode: FC<{
data: PipeNode;
}> = ({ data }) => {
const { title, des, logo, children = [] } = data;

console.log('reload');

return (
<div className={'techUIpipeNodeWrap'}>
<div className="pipeNode">
<div className="mainBox">
<div className="logo">
<img src={logo} alt="" />
</div>
<div className="title">{title}</div>
<div className="subLogo">
<img
src={
'https://mdn.alipayobjects.com/huamei_d2ejos/afts/img/A*Rg0cQpidn8cAAAAAAAAAAAAADvl6AQ/original'
}
alt=""
/>
</div>
</div>

{children.length > 0 && (
<div className="children">
{children.map((item, index) => (
<>
<div className="childrenBox" key={index}>
<Handle
id={`${item.id}-target`}
type="target"
position={Position.Left}
style={{
opacity: 0,
}}
/>
{item.logo && (
<div className="logo">
<img src={item.logo} alt="" />
</div>
)}
<div className="wrap">
<div className="title">{item.title}</div>
<div className="des">{item.des}</div>
</div>
<Handle
id={`${item.id}-source`}
type="source"
position={Position.Right}
style={{
opacity: 0,
}}
/>
</div>
</>
))}
</div>
)}

{des && <div className="des">{des}</div>}
</div>
</div>
);
};

export default CustomNode;
41 changes: 41 additions & 0 deletions docs/guide/demos/muchNode/data.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export const nodes = [
{
id: 'a1',
type: 'customNode',
data: {
title: 'XXX_API_a1',
logo: 'https://mdn.alipayobjects.com/huamei_ntgeqc/afts/img/A*kgyiRKi04eUAAAAAAAAAAAAADvuvAQ/original',
des: 'XXX_XXX_XXX_API',
},
},
{
id: 'a2',
data: {
title: 'XXX_API_a2',
logo: 'https://mdn.alipayobjects.com/huamei_ntgeqc/afts/img/A*kgyiRKi04eUAAAAAAAAAAAAADvuvAQ/original',
describe: 'XXX_XXX_XXX_API',
},
},
{
id: 'a3',
label: 'aaaa3',
data: {
title: 'XXX_API_a3',
logo: 'https://mdn.alipayobjects.com/huamei_ntgeqc/afts/img/A*kgyiRKi04eUAAAAAAAAAAAAADvuvAQ/original',
describe: 'XXX_XXX_XXX_API',
},
},
];
export const edges = [
{
id: 'a1-a2',
source: 'a1',
target: 'a2',
},
{
id: 'a1-a3',
source: 'a1',
target: 'a3',
type: 'radius',
},
];
38 changes: 38 additions & 0 deletions docs/guide/demos/muchNode/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* compact: true
* defaultShowCode: true
*/
import { FlowPanel, FlowView, FlowViewProvider, useFlowViewer } from '@ant-design/pro-flow';
import { useState } from 'react';
// import './css/index.less';
import CustomNode from './CustomNode';
import { edges, nodes } from './data';

const nodeTypes = { customNode: CustomNode };

function App() {
const { selectNode, selectEdges, selectNodes } = useFlowViewer();
const [node, setNode] = useState(null);

return (
<div className="container">
<FlowView nodeTypes={nodeTypes} nodes={nodes} edges={edges}>
<FlowPanel>
<div className="panel-title">
{node ? `当前选中的是:${node.id}` : `当前没有选中节点`}
</div>
</FlowPanel>
</FlowView>
</div>
);
}

function ProApp() {
return (
<FlowViewProvider>
<App />
</FlowViewProvider>
);
}

export default ProApp;
13 changes: 13 additions & 0 deletions docs/guide/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
nav:
title: 快速上手
order: 10
group:
title: test
order: 2
title: 安装使用
order: 1
description:
---

<code src='./demos/muchNode/index.tsx'></code>
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ features:
imageType: primary

- title: 现代化设计
link: /guide/switch-theme
link: /guide/brief-intro
description: 默认节点打造出来的流程图,看起来用起来都更像是一个产品,而不是简易流程图。
image: https://mdn.alipayobjects.com/huamei_rqvucu/afts/img/A*MvKkQqXEyfQAAAAAAAAAAAAADoN6AQ/original
imageType: light

- title: 完善的基本功能
description: 提供众多画布展示与交互的基础能力,开箱即用。
link: /guide/custom-theme
link: /guide/brief-intro
image: https://mdn.alipayobjects.com/huamei_rqvucu/afts/img/A*6sjjRa7lLhAAAAAAAAAAAAAADoN6AQ/original
imageType: primary

Expand Down
54 changes: 29 additions & 25 deletions src/FlowEditor/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
/**
* compact: true
*/
import { FlowEditor, FlowEditorProvider, useFlowEditor } from '@ant-design/pro-flow';
import {
FlowEditor,
FlowEditorProvider,
Handle,
Position,
useFlowEditor,
} from '@ant-design/pro-flow';
import { createStyles } from 'antd-style';
import { FC, useEffect } from 'react';
import { Handle, Position } from 'reactflow';
import styled from 'styled-components';

const StringNode = styled.div`
width: 150px;
height: 30px;
text-align: center;
background-color: white;
border: 1px solid aqua;
border-radius: 4px;
line-height: 30px;
`;
const useStyles = createStyles(({ css }) => ({
container: css`
width: 100%;
height: 600px;
.ant-progress-text {
text-align: center !important;
}
`,
stringNode: css`
width: 150px;
height: 30px;
text-align: center;
background-color: white;
border: 1px solid aqua;
border-radius: 4px;
line-height: 30px;
`,
}));

const StringRender: FC = (node: any) => {
console.log(node);
const { handles, id } = node;
const { styles } = useStyles();

return (
<StringNode>
<div className={styles.stringNode}>
<Handle
id={typeof handles?.source === 'string' ? handles?.source : id}
type={'target'}
Expand All @@ -33,20 +47,10 @@ const StringRender: FC = (node: any) => {
type={'source'}
position={Position.Right}
/>
</StringNode>
</div>
);
};

const useStyles = createStyles(({ css }) => ({
container: css`
width: 100%;
height: 600px;
.ant-progress-text {
text-align: center !important;
}
`,
}));

const ProFlowDemo = () => {
const editor = useFlowEditor();
const { styles } = useStyles();
Expand Down
8 changes: 7 additions & 1 deletion src/FlowView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const FlowView: React.FC<Partial<FlowViewProps>> = (props) => {
children,
background = true,
autoLayout = true,
stepLessZooming = true,
} = props;
const {
miniMapPosition,
Expand All @@ -58,8 +59,13 @@ const FlowView: React.FC<Partial<FlowViewProps>> = (props) => {
const { zoom } = useViewport();

useEffect(() => {
flowDataAdapter!(nodes, edges, 1, autoLayout);
}, [nodes, edges]);

useEffect(() => {
if (!stepLessZooming) return;
flowDataAdapter!(nodes, edges, zoom, autoLayout);
}, [nodes, edges, zoom]);
}, [zoom]);

const handleNodeDragStart = useCallback(
(event: ReactMouseEvent, node: Node, nodes: Node[]) => {
Expand Down
1 change: 1 addition & 0 deletions src/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface FlowViewProps {
background?: boolean;
children?: React.ReactNode;
autoLayout?: boolean;
stepLessZooming?: boolean;
}

export interface MiniMapPosition {
Expand Down

0 comments on commit 51783fc

Please sign in to comment.