ObjectNode.tsx 996 B

12345678910111213141516171819202122232425262728293031
  1. import React from "react";
  2. import { CustomNodeProps } from "src/components/CustomNode";
  3. import * as Styled from "./styles";
  4. export const ObjectNode: React.FC<CustomNodeProps> = ({ node, x, y }) => {
  5. const { text, width, height, data } = node;
  6. const ref = React.useRef(null);
  7. if (data.isEmpty) return null;
  8. return (
  9. <Styled.StyledForeignObject width={width} height={height} x={0} y={0} ref={ref} isObject>
  10. {text.map((val, idx) => {
  11. return (
  12. <Styled.StyledRow
  13. data-key={JSON.stringify(val)}
  14. data-type={JSON.stringify(val[1])}
  15. data-x={x}
  16. data-y={y + idx * 17.8}
  17. key={idx}
  18. >
  19. <Styled.StyledKey objectKey>
  20. {JSON.stringify(val[0]).replaceAll('"', "")}:{" "}
  21. </Styled.StyledKey>
  22. <Styled.StyledLinkItUrl>{JSON.stringify(val[1])}</Styled.StyledLinkItUrl>
  23. </Styled.StyledRow>
  24. );
  25. })}
  26. </Styled.StyledForeignObject>
  27. );
  28. };