feat: change to center and clean code

This commit is contained in:
2025-02-16 02:09:14 +08:00
parent 73de223d56
commit 1363b87f36
97 changed files with 882 additions and 6775 deletions

View File

@@ -1,142 +0,0 @@
import { RenderData } from '@kevisual/container';
type Page = {
data: {
edges: { id: string; source: string; target: string }[];
nodes: { id: string; type: string; position: { x: number; y: number }; data: any }[];
};
id: string;
type: string;
[key: string]: any;
};
type Container = {
code: string;
id: string;
[key: string]: any;
};
type PageEditData = {
page: Page;
containerList: Container[];
};
export const getContainerData = (pageEditData: PageEditData) => {
const { page, containerList } = pageEditData;
const containerObj = containerList.reduce((acc, container) => {
acc[container.id] = container;
return acc;
}, {});
const { edges, nodes } = page.data;
const nodesObj = nodes.reduce((acc, node) => {
acc[node.id] = node;
return acc;
}, {});
const treeArray = getTreeFromEdges(edges);
const floatNodes = nodes.filter((node) => !treeArray.find((item) => item.id === node.id));
const treeNodes = nodes.filter((node) => treeArray.find((item) => item.id === node.id));
const renderData: RenderData[] = [];
for (let tree of treeArray) {
const node = nodesObj[tree.id];
const container = containerObj[node.data?.cid];
const style = node.data?.style ?? {
position: 'absolute',
width: 100,
height: 100,
};
const data = {
node: { ...node },
container: { ...container },
};
renderData.push({
id: node.id,
children: tree.children,
parents: tree.parents,
code: container?.code || '',
codeId: container?.id,
data: data || {},
className: node.data?.className,
shadowRoot: node.data?.shadowRoot,
showChild: node.data?.showChild,
style,
});
}
for (let node of floatNodes) {
const container = containerObj[node.data?.cid];
const style = node.data?.style ?? {
position: 'absolute',
width: 100,
height: 100,
};
const data = {
node: { ...node },
container: { ...container },
};
renderData.push({
id: node.id,
children: [],
parents: [],
code: container?.code || '',
codeId: container?.id,
data: data || {},
className: node.data?.className,
shadowRoot: node.data?.shadowRoot,
showChild: node.data?.showChild,
style,
});
}
return renderData;
};
const getTreeFromEdges = (
edges: { id: string; source: string; target: string }[],
): {
id: string;
parents: string[];
children: string[];
}[] => {
// 构建树形结构
function buildNodeTree(edges) {
const nodeMap = {};
// 初始化每个节点的子节点列表和父节点列表
edges.forEach((edge) => {
if (!nodeMap[edge.source]) {
nodeMap[edge.source] = { id: edge.source, parents: [], children: [] };
}
if (!nodeMap[edge.target]) {
nodeMap[edge.target] = { id: edge.target, parents: [], children: [] };
}
// 连接父节点和子节点
nodeMap[edge.source].children.push(nodeMap[edge.target]);
nodeMap[edge.target].parents.push(nodeMap[edge.source]);
});
return nodeMap;
}
const nodeTree = buildNodeTree(edges);
// 递归获取所有父节点,按顺序
function getAllParents(node) {
const parents: string[] = [];
function traverseParents(currentNode) {
if (currentNode.parents.length > 0) {
currentNode.parents.forEach((parent: any) => {
parents.push(parent.id);
traverseParents(parent);
});
}
}
traverseParents(node);
return parents.reverse(); // 确保顺序从最顶层到直接父节点
}
function getNodeInfo(nodeMap) {
return Object.values(nodeMap).map((node: any) => ({
id: node.id,
parents: getAllParents(node),
children: node.children.map((child) => child.id),
}));
}
const result = getNodeInfo(nodeTree);
return result;
};

View File

@@ -1,4 +1,3 @@
export * from './query';
export * from './deck-to-flow/deck';
export * from './navicate';

View File

@@ -22,11 +22,6 @@ const meun = [
icon: <HomeOutlined />,
link: '/map',
},
{
title: 'Panel',
icon: <DashboardOutlined />,
link: '/panel/edit/list',
},
{
title: 'User App',
icon: <AppstoreOutlined />,
@@ -37,26 +32,11 @@ const meun = [
icon: <FolderOutlined />,
link: '/file/edit/list',
},
{
title: 'Prompt',
icon: <MessageOutlined />,
link: '/prompt',
},
{
title: 'Container',
icon: <CodeOutlined />,
link: '/container/edit/list',
},
{
title: 'Agent',
icon: <RocketOutlined />,
link: '/agent/edit/list',
},
{
title: 'Chat Prompt',
icon: <ReadOutlined />,
link: '/chat/chat-prompt/list',
},
{
title: 'Org',
icon: <SwitcherOutlined />,
@@ -79,7 +59,7 @@ export const LayoutMenu = () => {
}}></div>
<div className='w-[300px] h-full absolute top-0 left-0 bg-white'>
<div className='flex justify-between p-6 mt-4 font-bold items-center'>
Envision
Envision Center
<div>
<Button icon={<CloseOutlined />} onClick={() => setOpen(false)}></Button>
</div>
@@ -93,7 +73,7 @@ export const LayoutMenu = () => {
onClick={() => {
if (item.link) navigate(`${item.link}`);
else {
message.info('About Envision');
message.info('About Envision Center');
}
setOpen(false);
}}>

View File

@@ -1,4 +1,3 @@
import { AiMoudle, useAiStore } from '@/pages/ai-chat';
import { MenuOutlined, SwapOutlined } from '@ant-design/icons';
import { Button, Tooltip } from 'antd';
import { Outlet } from 'react-router-dom';
@@ -39,11 +38,7 @@ export const LayoutMain = (props: LayoutMainProps) => {
}),
);
const { isMac, mount, isElectron } = platformStore;
const aiStore = useAiStore(
useShallow((state) => {
return { open: state.open };
}),
);
useLayoutEffect(() => {
platformStore.init();
}, []);
@@ -106,12 +101,10 @@ export const LayoutMain = (props: LayoutMainProps) => {
</div>
</Panel>
<PanelResizeHandle />
<Panel style={{ height: '100%' }} defaultSize={25} className={clsx(!aiStore.open && 'hidden')}>
<div className='w-full h-full'>
<AiMoudle />
</div>
</Panel>
{/* <PanelResizeHandle />
<Panel style={{ height: '100%' }} defaultSize={25} className={clsx('bg-gray-100')}>
侧边栏
</Panel> */}
</PanelGroup>
</div>
<LayoutUser />