index.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React from "react";
  2. import styled from "styled-components";
  3. import {
  4. TransformWrapper,
  5. TransformComponent,
  6. ReactZoomPanPinchRef,
  7. } from "react-zoom-pan-pinch";
  8. import { useConfig } from "src/hocs/config";
  9. import { Tools } from "src/containers/Editor/Tools";
  10. import { ConfigActionType } from "src/reducer/reducer";
  11. import { Graph } from "src/components/Graph";
  12. const StyledLiveEditor = styled.div`
  13. position: relative;
  14. `;
  15. const StyledEditorWrapper = styled.div`
  16. position: absolute;
  17. width: 100%;
  18. height: calc(100vh - 36px);
  19. :active {
  20. cursor: move;
  21. }
  22. rect {
  23. fill: ${({ theme }) => theme.BACKGROUND_NODE};
  24. }
  25. `;
  26. const wheelOptions = {
  27. step: 0.05,
  28. };
  29. export const LiveEditor: React.FC = React.memo(function LiveEditor() {
  30. const { dispatch } = useConfig();
  31. const onInit = (ref: ReactZoomPanPinchRef) => {
  32. dispatch({
  33. type: ConfigActionType.SET_ZOOM_PAN_PICNH_REF,
  34. payload: ref,
  35. });
  36. };
  37. return (
  38. <StyledLiveEditor>
  39. <Tools />
  40. <StyledEditorWrapper>
  41. <TransformWrapper
  42. maxScale={1.8}
  43. minScale={0.4}
  44. initialScale={0.9}
  45. wheel={wheelOptions}
  46. onInit={onInit}
  47. >
  48. <TransformComponent
  49. wrapperStyle={{
  50. width: "100%",
  51. height: "100%",
  52. overflow: "hidden",
  53. }}
  54. >
  55. <Graph />
  56. </TransformComponent>
  57. </TransformWrapper>
  58. </StyledEditorWrapper>
  59. </StyledLiveEditor>
  60. );
  61. });