|
@@ -2,7 +2,6 @@ import { register } from "@antv/x6-react-shape";
|
|
|
import { EventArgs, Graph, Node } from "@antv/x6";
|
|
|
import { topicData } from "@/config/data";
|
|
|
import { useSizeHook, useShapeProps } from "@/hooks";
|
|
|
-import CustomInput from "../CustomInput";
|
|
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
|
import { PlusOutlined } from "@ant-design/icons";
|
|
|
import { TopicType } from "@/enum";
|
|
@@ -10,11 +9,12 @@ import { addTopic } from "@/pages/mindmap/mindMap";
|
|
|
|
|
|
import Link from "./Link";
|
|
|
import ExtraModule from "./ExtraModule";
|
|
|
-import CustomTag from "@/components/CustomTag";
|
|
|
+import CustomTag from "@/components/mindMap/CustomTag";
|
|
|
import { TopicItem } from "@/types";
|
|
|
import { selectTopic } from "@/utils/mindmapHander";
|
|
|
import { Tooltip, Popover } from "antd";
|
|
|
import LinkForm from "./LinkForm";
|
|
|
+import Text from "./Text";
|
|
|
const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
const {
|
|
|
fill,
|
|
@@ -36,8 +36,11 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
linkTopicId,
|
|
|
} = node.getData();
|
|
|
const { size, ref } = useSizeHook();
|
|
|
- const { fillContent, strokeColor, strokeWidth } =
|
|
|
- useShapeProps(fill, size, stroke);
|
|
|
+ const { fillContent, strokeColor, strokeWidth } = useShapeProps(
|
|
|
+ fill,
|
|
|
+ size,
|
|
|
+ stroke
|
|
|
+ );
|
|
|
const [selected, setSelected] = useState(false);
|
|
|
const [showPopover, setShowPopover] = useState(false);
|
|
|
const [popoverContent, setPopoverContent] = useState<React.ReactNode>();
|
|
@@ -96,37 +99,29 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
// graph.select(node);
|
|
|
graph.on("node:selected", handleSelect);
|
|
|
graph.on("node:unselected", handleSelect);
|
|
|
- graph.on("node:resized", handleResize);
|
|
|
return () => {
|
|
|
graph.off("node:selected", handleSelect);
|
|
|
graph.off("node:unselected", handleSelect);
|
|
|
- graph.off("node:resized", handleResize);
|
|
|
- };
|
|
|
- }, []);
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- let timer = setInterval(() => {
|
|
|
- const { clientHeight = 0, clientWidth = 0 } = ref.current || {};
|
|
|
- if (clientHeight && (size.width !== clientWidth || size.height !== clientHeight)) {
|
|
|
- node.setData({
|
|
|
- width: clientWidth,
|
|
|
- height: clientHeight,
|
|
|
- });
|
|
|
- }
|
|
|
- }, 1000);
|
|
|
-
|
|
|
- return () => {
|
|
|
- clearInterval(timer);
|
|
|
};
|
|
|
}, []);
|
|
|
|
|
|
- const handleResize = () => {
|
|
|
- node.setData({
|
|
|
- fixedWidth: true,
|
|
|
- width: node.size().width,
|
|
|
- });
|
|
|
+ const changeSize = () => {
|
|
|
+ const { clientHeight = 0, clientWidth = 0 } = ref.current || {};
|
|
|
+ if (
|
|
|
+ clientHeight &&
|
|
|
+ (size.width !== clientWidth || size.height !== clientHeight)
|
|
|
+ ) {
|
|
|
+ node.setData({
|
|
|
+ width: clientWidth,
|
|
|
+ height: clientHeight,
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ changeSize();
|
|
|
+ }, [node.data]);
|
|
|
+
|
|
|
const childrenCount = useMemo(() => {
|
|
|
let count = 0;
|
|
|
const traverse = (topics: TopicItem[]) => {
|
|
@@ -176,9 +171,34 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
}
|
|
|
);
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
+ const handleChangeTag = (tagInfo: { color?: string; title?: string }, index: number) => {
|
|
|
+ node.setData({
|
|
|
+ tags: tags.map((item: { color?: string; title?: string }, i: number) => {
|
|
|
+ if (index === i) {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ ...tagInfo
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ }, {
|
|
|
+ deep: false
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleDeleteTag = (index: number) => {
|
|
|
+ tags.splice(index, 1);
|
|
|
+ node.setData({
|
|
|
+ tags
|
|
|
+ }, {
|
|
|
+ deep: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
- <>
|
|
|
+ <div>
|
|
|
{selected && (
|
|
|
<div
|
|
|
style={{
|
|
@@ -196,9 +216,7 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
className="content relative text-0"
|
|
|
ref={ref}
|
|
|
style={{
|
|
|
- // minWidth: "100%",
|
|
|
- // width: "fit-content",
|
|
|
- // minHeight: "100%",
|
|
|
+ width: fixedWidth ? "100%" : "fit-content",
|
|
|
opacity: opacity / 100,
|
|
|
border: `solid ${strokeWidth}px ${strokeColor}`,
|
|
|
background: fillContent,
|
|
@@ -216,11 +234,8 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
)}
|
|
|
|
|
|
{/* 图标、标题、链接等 */}
|
|
|
- <div
|
|
|
- className="flex-1 flex items-center justify-center"
|
|
|
- ref={titleRef}
|
|
|
- >
|
|
|
- <div className="flex items-center text-20px">
|
|
|
+ <div className="tit flex items-center justify-center" ref={titleRef}>
|
|
|
+ <div className="flex items-center text-20px flex-1">
|
|
|
{icons?.map((icon: string) => {
|
|
|
return (
|
|
|
<svg key={icon} className="icon mr-6px" aria-hidden="true">
|
|
@@ -229,22 +244,18 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
);
|
|
|
})}
|
|
|
</div>
|
|
|
- <CustomInput
|
|
|
+ <Text
|
|
|
value={label}
|
|
|
node={node}
|
|
|
+ fixedWidth={fixedWidth}
|
|
|
styles={{
|
|
|
...text,
|
|
|
- position: "relative",
|
|
|
- padding: "0",
|
|
|
}}
|
|
|
txtStyle={{
|
|
|
position: "relative",
|
|
|
- flexShrink: 0,
|
|
|
- transform: "translateY(50%)",
|
|
|
- width: "auto",
|
|
|
...(fixedWidth
|
|
|
? { maxWidth: `calc(100% - ${2 * padding.x}px)` }
|
|
|
- : {}),
|
|
|
+ : { width: "max-content" }),
|
|
|
}}
|
|
|
/>
|
|
|
<div
|
|
@@ -278,13 +289,15 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
</div>
|
|
|
{/* 标签 */}
|
|
|
<div className="flex items-center justify-center" ref={tagRef}>
|
|
|
- {tags?.map((item: { name: string; color: string }) => {
|
|
|
+ {tags?.map((item: { name: string; color: string }, index: number) => {
|
|
|
return (
|
|
|
<CustomTag
|
|
|
className="text-14px"
|
|
|
key={item.name}
|
|
|
title={item.name}
|
|
|
color={item.color}
|
|
|
+ onChangeTag={(tag) => handleChangeTag(tag, index)}
|
|
|
+ onDelete={() => handleDeleteTag(index)}
|
|
|
>
|
|
|
{item.name}
|
|
|
</CustomTag>
|
|
@@ -352,7 +365,7 @@ const component = ({ node, graph }: { node: Node; graph: Graph }) => {
|
|
|
)}
|
|
|
</div>
|
|
|
</Popover>
|
|
|
- </>
|
|
|
+ </div>
|
|
|
);
|
|
|
};
|
|
|
|