AykutSarac пре 2 година
родитељ
комит
8b5179c891

+ 44 - 2
src/components/CustomNode/TextNode.tsx

@@ -1,8 +1,28 @@
 import React from "react";
 import React from "react";
+import { BiChevronLeft, BiChevronRight } from "react-icons/bi";
 import { ConditionalWrapper, CustomNodeProps } from "src/components/CustomNode";
 import { ConditionalWrapper, CustomNodeProps } from "src/components/CustomNode";
 import useConfig from "src/hooks/store/useConfig";
 import useConfig from "src/hooks/store/useConfig";
+import styled from "styled-components";
 import * as Styled from "./styles";
 import * as Styled from "./styles";
 
 
+const StyledExpand = styled.button`
+  pointer-events: all;
+  position: absolute;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  top: 0;
+  right: 0;
+  padding: 0;
+  color: ${({ theme }) => theme.TEXT_NORMAL};
+  background: rgba(0, 0, 0, 0.1);
+  min-height: 0;
+  height: 100%;
+  width: 40px;
+  border-radius: 0;
+  border-left: 1px solid ${({ theme }) => theme.BACKGROUND_MODIFIER_ACCENT};
+`;
+
 const TextNode: React.FC<CustomNodeProps<string>> = ({
 const TextNode: React.FC<CustomNodeProps<string>> = ({
   width,
   width,
   height,
   height,
@@ -12,21 +32,43 @@ const TextNode: React.FC<CustomNodeProps<string>> = ({
   y,
   y,
 }) => {
 }) => {
   const performanceMode = useConfig((state) => state.performanceMode);
   const performanceMode = useConfig((state) => state.performanceMode);
+  const expand = useConfig((state) => state.expand);
+  const [isExpanded, setIsExpanded] = React.useState(!expand);
+
+  React.useEffect(() => {
+    setIsExpanded(expand);
+  }, [expand]);
+
+  const handleExpand = (e: React.MouseEvent<HTMLButtonElement>) => {
+    e.stopPropagation();
+    setIsExpanded(!isExpanded);
+  };
 
 
   return (
   return (
     <Styled.StyledForeignObject width={width} height={height} x={0} y={0}>
     <Styled.StyledForeignObject width={width} height={height} x={0} y={0}>
       <ConditionalWrapper condition={performanceMode}>
       <ConditionalWrapper condition={performanceMode}>
-        <Styled.StyledText width={width} height={height}>
+        <Styled.StyledText parent={isParent} width={width} height={height}>
           <Styled.StyledKey
           <Styled.StyledKey
             data-x={x}
             data-x={x}
             data-y={y}
             data-y={y}
             data-key={JSON.stringify(value)}
             data-key={JSON.stringify(value)}
             parent={isParent}
             parent={isParent}
           >
           >
-            <Styled.StyledLinkItUrl>{JSON.stringify(value).replaceAll('"', "")}</Styled.StyledLinkItUrl>
+            <Styled.StyledLinkItUrl>
+              {JSON.stringify(value).replaceAll('"', "")}
+            </Styled.StyledLinkItUrl>
           </Styled.StyledKey>
           </Styled.StyledKey>
         </Styled.StyledText>
         </Styled.StyledText>
       </ConditionalWrapper>
       </ConditionalWrapper>
+      {isParent && (
+        <StyledExpand onClick={handleExpand}>
+          {isExpanded ? (
+            <BiChevronRight size={20} />
+          ) : (
+            <BiChevronLeft size={20} />
+          )}
+        </StyledExpand>
+      )}
     </Styled.StyledForeignObject>
     </Styled.StyledForeignObject>
   );
   );
 };
 };

+ 6 - 1
src/components/CustomNode/styles.tsx

@@ -23,7 +23,11 @@ export const StyledTextWrapper = styled.div`
   cursor: pointer;
   cursor: pointer;
 `;
 `;
 
 
-export const StyledText = styled.pre<{ width: number; height: number }>`
+export const StyledText = styled.pre<{
+  width: number;
+  height: number;
+  parent: boolean;
+}>`
   display: flex;
   display: flex;
   justify-content: center;
   justify-content: center;
   flex-direction: column;
   flex-direction: column;
@@ -31,6 +35,7 @@ export const StyledText = styled.pre<{ width: number; height: number }>`
   height: ${({ height }) => height};
   height: ${({ height }) => height};
   min-height: 50;
   min-height: 50;
   color: ${({ theme }) => theme.TEXT_NORMAL};
   color: ${({ theme }) => theme.TEXT_NORMAL};
+  padding-right: ${({ parent }) => parent && "20px"};
 `;
 `;
 
 
 export const StyledForeignObject = styled.foreignObject`
 export const StyledForeignObject = styled.foreignObject`

+ 5 - 11
src/components/Graph/index.tsx

@@ -65,7 +65,7 @@ const MemoizedGraph = React.memo(function Layout({ isWidget }: LayoutProps) {
     setNodeTools("edges", edges);
     setNodeTools("edges", edges);
     setNodeTools("newNodes", nodes);
     setNodeTools("newNodes", nodes);
     setNodeTools("newEdges", edges);
     setNodeTools("newEdges", edges);
-  }, [json, expand]);
+  }, [json, expand, setNodeTools]);
 
 
   const onInit = (ref: ReactZoomPanPinchRef) => {
   const onInit = (ref: ReactZoomPanPinchRef) => {
     setConfig("zoomPanPinch", ref);
     setConfig("zoomPanPinch", ref);
@@ -100,6 +100,9 @@ const MemoizedGraph = React.memo(function Layout({ isWidget }: LayoutProps) {
         wheel={{
         wheel={{
           step: 0.05,
           step: 0.05,
         }}
         }}
+        doubleClick={{
+          disabled: true,
+        }}
       >
       >
         <TransformComponent
         <TransformComponent
           wrapperStyle={{
           wrapperStyle={{
@@ -117,16 +120,7 @@ const MemoizedGraph = React.memo(function Layout({ isWidget }: LayoutProps) {
             key={layout}
             key={layout}
             onLayoutChange={onLayoutChange}
             onLayoutChange={onLayoutChange}
             selections={selections}
             selections={selections}
-            node={(props) =>
-              newNodes.find((n) => n.id === props.id) ? (
-                <CustomNode
-                  onClick={(e) => onClick && onClick(e, props)}
-                  {...props}
-                />
-              ) : (
-                <></>
-              )
-            }
+            node={(props) => <CustomNode {...props} />}
             edge={(props) =>
             edge={(props) =>
               newEdges.find((e) => e.id === props.id) ? <Edge /> : <></>
               newEdges.find((e) => e.id === props.id) ? <Edge /> : <></>
             }
             }

+ 1 - 1
src/containers/Editor/LiveEditor/helpers.ts

@@ -32,7 +32,7 @@ export function getEdgeNodes(
         data: {
         data: {
           isParent: el.parent,
           isParent: el.parent,
         },
         },
-        width: isExpanded ? 35 + longestLine * (el.parent ? 9 : 8) : 180,
+        width: isExpanded ? 35 + longestLine * 8 + (el.parent && 60) : 180,
         height,
         height,
       });
       });
     } else {
     } else {