mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
feat(container): accessing form render
This commit is contained in:
parent
19cbe6a560
commit
c83d06b593
@ -1,7 +1,21 @@
|
|||||||
import React, { type FC } from 'react';
|
import React, { type FC } from 'react';
|
||||||
|
|
||||||
|
import { useNodeRender } from '@flowgram.ai/free-layout-core';
|
||||||
|
import { FlowNodeTransformData } from '@flowgram.ai/document';
|
||||||
|
|
||||||
import { ContainerNodeBorderStyle } from './style';
|
import { ContainerNodeBorderStyle } from './style';
|
||||||
|
|
||||||
export const ContainerNodeBorder: FC = () => (
|
export const ContainerNodeBorder: FC = () => {
|
||||||
<ContainerNodeBorderStyle className="container-node-border" />
|
const { node } = useNodeRender();
|
||||||
);
|
const transformData = node.getData(FlowNodeTransformData);
|
||||||
|
const topWidth = Math.max(transformData.padding.top - 50, 50);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ContainerNodeBorderStyle
|
||||||
|
className="container-node-border"
|
||||||
|
style={{
|
||||||
|
borderTopWidth: topWidth,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@ -15,7 +15,7 @@ export const ContainerNodeBorderStyle = styled.div`
|
|||||||
border: 1px solid var(--coz-stroke-plus, rgba(6, 7, 9, 15%));
|
border: 1px solid var(--coz-stroke-plus, rgba(6, 7, 9, 15%));
|
||||||
border-color: var(--coz-bg-plus, rgb(249, 249, 249));
|
border-color: var(--coz-bg-plus, rgb(249, 249, 249));
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-width: 48px 8px 8px;
|
border-width: 8px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 4%), 0 4px 12px 0 rgba(0, 0, 0, 2%);
|
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 4%), 0 4px 12px 0 rgba(0, 0, 0, 2%);
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import React, { useEffect, useState, type FC, type ReactNode } from 'react';
|
import React, { useEffect, useState, type FC, type ReactNode } from 'react';
|
||||||
|
|
||||||
import { useNodeRender } from '@flowgram.ai/free-layout-core';
|
import { useNodeRender, WorkflowNodePortsData } from '@flowgram.ai/free-layout-core';
|
||||||
import { FlowNodeTransformData } from '@flowgram.ai/document';
|
import { FlowNodeTransformData } from '@flowgram.ai/document';
|
||||||
|
|
||||||
import { useContainerNodeRenderProps } from '../../hooks';
|
import { useContainerNodeRenderProps } from '../../hooks';
|
||||||
import { ContainerNodeContainerStyle } from './style';
|
import { ContainerNodeContainerStyle } from './style';
|
||||||
|
|
||||||
interface IContainerNodeContainer {
|
interface IContainerNodeContainer {
|
||||||
children: ReactNode[];
|
children: ReactNode | ReactNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ContainerNodeContainer: FC<IContainerNodeContainer> = ({ children }) => {
|
export const ContainerNodeContainer: FC<IContainerNodeContainer> = ({ children }) => {
|
||||||
@ -20,6 +20,13 @@ export const ContainerNodeContainer: FC<IContainerNodeContainer> = ({ children }
|
|||||||
const [width, setWidth] = useState(size.width);
|
const [width, setWidth] = useState(size.width);
|
||||||
const [height, setHeight] = useState(size.height);
|
const [height, setHeight] = useState(size.height);
|
||||||
|
|
||||||
|
const updatePorts = () => {
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const portsData = node.getData<WorkflowNodePortsData>(WorkflowNodePortsData);
|
||||||
|
portsData.updateDynamicPorts();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateSize = () => {
|
const updateSize = () => {
|
||||||
// 无子节点时
|
// 无子节点时
|
||||||
@ -39,6 +46,7 @@ export const ContainerNodeContainer: FC<IContainerNodeContainer> = ({ children }
|
|||||||
updateSize();
|
updateSize();
|
||||||
const dispose = transform.onDataChange(() => {
|
const dispose = transform.onDataChange(() => {
|
||||||
updateSize();
|
updateSize();
|
||||||
|
updatePorts();
|
||||||
});
|
});
|
||||||
return () => dispose.dispose();
|
return () => dispose.dispose();
|
||||||
}, [transform]);
|
}, [transform]);
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
import React, { type FC } from 'react';
|
||||||
|
|
||||||
|
import { useNodeRender } from '@flowgram.ai/free-layout-core';
|
||||||
|
|
||||||
|
import { ContainerNodeFormStyle } from './style';
|
||||||
|
|
||||||
|
export const ContainerNodeForm: FC = () => {
|
||||||
|
const { form } = useNodeRender();
|
||||||
|
if (!form) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return <ContainerNodeFormStyle>{form.render()}</ContainerNodeFormStyle>;
|
||||||
|
};
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
export const ContainerNodeFormStyle = styled.div`
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 8px 8px 0 0;
|
||||||
|
`;
|
||||||
@ -1,14 +1,15 @@
|
|||||||
import React, { type FC } from 'react';
|
import React, { ReactNode, type FC } from 'react';
|
||||||
|
|
||||||
import { useNodeRender } from '@flowgram.ai/free-layout-core';
|
import { useNodeRender } from '@flowgram.ai/free-layout-core';
|
||||||
|
|
||||||
import { useContainerNodeRenderProps } from '../../hooks';
|
|
||||||
import { ContainerNodeHeaderStyle } from './style';
|
import { ContainerNodeHeaderStyle } from './style';
|
||||||
|
|
||||||
export const ContainerNodeHeader: FC = () => {
|
interface IContainerNodeHeader {
|
||||||
const { startDrag, onFocus, onBlur } = useNodeRender();
|
children?: ReactNode | ReactNode[];
|
||||||
|
}
|
||||||
|
|
||||||
const { title } = useContainerNodeRenderProps();
|
export const ContainerNodeHeader: FC<IContainerNodeHeader> = ({ children }) => {
|
||||||
|
const { startDrag, onFocus, onBlur } = useNodeRender();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContainerNodeHeaderStyle
|
<ContainerNodeHeaderStyle
|
||||||
@ -20,7 +21,7 @@ export const ContainerNodeHeader: FC = () => {
|
|||||||
onFocus={onFocus}
|
onFocus={onFocus}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
>
|
>
|
||||||
<p className="container-node-title">{title}</p>
|
{children}
|
||||||
</ContainerNodeHeaderStyle>
|
</ContainerNodeHeaderStyle>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
export const ContainerNodeHeaderStyle = styled.div`
|
export const ContainerNodeHeaderStyle = styled.div`
|
||||||
cursor: move;
|
|
||||||
|
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -11,8 +9,7 @@ export const ContainerNodeHeaderStyle = styled.div`
|
|||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 48px;
|
height: auto;
|
||||||
padding: 16px;
|
|
||||||
|
|
||||||
border-radius: 8px 8px 0 0;
|
border-radius: 8px 8px 0 0;
|
||||||
|
|
||||||
|
|||||||
@ -3,3 +3,4 @@ export { ContainerNodeBackground } from './background';
|
|||||||
export { ContainerNodeContainer } from './container';
|
export { ContainerNodeContainer } from './container';
|
||||||
export { ContainerNodeBorder } from './border';
|
export { ContainerNodeBorder } from './border';
|
||||||
export { ContainerNodePorts } from './ports';
|
export { ContainerNodePorts } from './ports';
|
||||||
|
export { ContainerNodeForm } from './form';
|
||||||
|
|||||||
@ -7,13 +7,16 @@ import {
|
|||||||
ContainerNodePorts,
|
ContainerNodePorts,
|
||||||
ContainerNodeBorder,
|
ContainerNodeBorder,
|
||||||
ContainerNodeContainer,
|
ContainerNodeContainer,
|
||||||
|
ContainerNodeForm,
|
||||||
} from './components';
|
} from './components';
|
||||||
|
|
||||||
export const ContainerNodeRender: FC<ContainerNodeRenderProps> = (props) => (
|
export const ContainerNodeRender: FC<ContainerNodeRenderProps> = () => (
|
||||||
<ContainerNodeContainer>
|
<ContainerNodeContainer>
|
||||||
<ContainerNodeBorder />
|
|
||||||
<ContainerNodeBackground />
|
<ContainerNodeBackground />
|
||||||
<ContainerNodeHeader />
|
<ContainerNodeBorder />
|
||||||
|
<ContainerNodeHeader>
|
||||||
|
<ContainerNodeForm />
|
||||||
|
</ContainerNodeHeader>
|
||||||
<ContainerNodePorts />
|
<ContainerNodePorts />
|
||||||
</ContainerNodeContainer>
|
</ContainerNodeContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user