|
@@ -35,35 +35,26 @@ const StyledTextNodeWrapper = styled.div<{ hasCollapse: boolean }>`
|
|
|
width: 100%;
|
|
|
`;
|
|
|
|
|
|
-type TextNodeProps = CustomNodeProps<string> & {
|
|
|
- node: NodeData;
|
|
|
- hasCollapse: boolean;
|
|
|
-};
|
|
|
-
|
|
|
-const TextNode: React.FC<TextNodeProps> = ({
|
|
|
+const TextNode: React.FC<CustomNodeProps> = ({
|
|
|
node,
|
|
|
- width,
|
|
|
- height,
|
|
|
- value,
|
|
|
- isParent = false,
|
|
|
- hasCollapse = false,
|
|
|
x,
|
|
|
y,
|
|
|
+ hasCollapse = false,
|
|
|
}) => {
|
|
|
+ const { id, text, width, height, data } = node;
|
|
|
const ref = React.useRef(null);
|
|
|
- // const { inViewport } = useInViewport(ref);
|
|
|
- const performanceMode = useConfig(state => state.performanceMode);
|
|
|
-
|
|
|
const hideCollapse = useStored(state => state.hideCollapse);
|
|
|
const expandNodes = useGraph(state => state.expandNodes);
|
|
|
const collapseNodes = useGraph(state => state.collapseNodes);
|
|
|
- const isExpanded = useGraph(state => state.collapsedParents.includes(node.id));
|
|
|
+ const isExpanded = useGraph(state => state.collapsedParents.includes(id));
|
|
|
+ const performanceMode = useConfig(state => state.performanceMode);
|
|
|
+ // const { inViewport } = useInViewport(ref);
|
|
|
|
|
|
const handleExpand = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
e.stopPropagation();
|
|
|
|
|
|
- if (!isExpanded) collapseNodes(node.id);
|
|
|
- else expandNodes(node.id);
|
|
|
+ if (!isExpanded) collapseNodes(id);
|
|
|
+ else expandNodes(id);
|
|
|
};
|
|
|
|
|
|
return (
|
|
@@ -72,26 +63,25 @@ const TextNode: React.FC<TextNodeProps> = ({
|
|
|
height={height}
|
|
|
x={0}
|
|
|
y={0}
|
|
|
- data-nodeid={node.id}
|
|
|
- ref={ref}
|
|
|
hideCollapse={hideCollapse}
|
|
|
- hasCollapse={isParent && hasCollapse}
|
|
|
+ hasCollapse={data.isParent && hasCollapse}
|
|
|
+ ref={ref}
|
|
|
>
|
|
|
- <StyledTextNodeWrapper hasCollapse={isParent && !hideCollapse}>
|
|
|
+ <StyledTextNodeWrapper hasCollapse={data.isParent && !hideCollapse}>
|
|
|
{(!performanceMode || inViewport) && (
|
|
|
<Styled.StyledKey
|
|
|
data-x={x}
|
|
|
data-y={y}
|
|
|
- data-key={JSON.stringify(value)}
|
|
|
- parent={isParent}
|
|
|
+ data-key={JSON.stringify(text)}
|
|
|
+ parent={data.isParent}
|
|
|
>
|
|
|
<Styled.StyledLinkItUrl>
|
|
|
- {JSON.stringify(value).replaceAll('"', "")}
|
|
|
+ {JSON.stringify(text).replaceAll('"', "")}
|
|
|
</Styled.StyledLinkItUrl>
|
|
|
</Styled.StyledKey>
|
|
|
)}
|
|
|
|
|
|
- {inViewport && isParent && hasCollapse && !hideCollapse && (
|
|
|
+ {inViewport && data.isParent && hasCollapse && !hideCollapse && (
|
|
|
<StyledExpand onClick={handleExpand}>
|
|
|
{isExpanded ? <MdLinkOff size={18} /> : <MdLink size={18} />}
|
|
|
</StyledExpand>
|
|
@@ -101,8 +91,8 @@ const TextNode: React.FC<TextNodeProps> = ({
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-function propsAreEqual(prev: TextNodeProps, next: TextNodeProps) {
|
|
|
- return prev.value === next.value && prev.width === next.width;
|
|
|
+function propsAreEqual(prev: CustomNodeProps, next: CustomNodeProps) {
|
|
|
+ return prev.node.text === next.node.text && prev.node.width === next.node.width;
|
|
|
}
|
|
|
|
|
|
export default React.memo(TextNode, propsAreEqual);
|