@canmingir/link 1.2.54 → 1.2.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canmingir/link",
3
- "version": "1.2.54",
3
+ "version": "1.2.55",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "link-server": "./server/server.ts"
@@ -1,66 +1,30 @@
1
- import React, { useEffect, useRef, useState } from "react";
1
+ import React, { useState } from "react";
2
2
 
3
3
  import Box from "@mui/material/Box";
4
4
  import Link from "@mui/material/Link";
5
5
  import { RouterLink } from "../../routes/components";
6
6
  import config from "../../config/config";
7
7
 
8
- const resolvedDimensions = {};
9
-
10
8
  const Logo = ({ disabledLink = false, sx, maxSize = 65, isLogin = false }) => {
11
9
  const { icon } = config().template.login;
12
- const key = `${icon}_${maxSize}_${isLogin}`;
13
-
14
- const [dimensions, setDimensions] = useState(
15
- resolvedDimensions[key] || { width: maxSize, height: maxSize },
16
- );
17
-
18
- useEffect(() => {
19
- if (!icon || resolvedDimensions[key]) return;
20
10
 
21
- const img = new Image();
22
- img.onload = () => {
23
- const { naturalWidth, naturalHeight } = img;
24
- const isSquare = naturalWidth === naturalHeight;
25
- let newDimensions;
26
-
27
- if (naturalWidth > maxSize || naturalHeight > maxSize) {
28
- if (isSquare) {
29
- newDimensions = {
30
- width: isLogin ? maxSize : 40,
31
- height: isLogin ? maxSize : 40,
32
- };
33
- } else {
34
- const aspectRatio = naturalWidth / naturalHeight;
35
- if (naturalWidth >= naturalHeight) {
36
- newDimensions = {
37
- width: maxSize,
38
- height: Math.round(maxSize / aspectRatio),
39
- };
40
- } else {
41
- newDimensions = {
42
- width: Math.round(maxSize * aspectRatio),
43
- height: maxSize,
44
- };
45
- }
46
- }
47
- } else {
48
- newDimensions = { width: naturalWidth, height: naturalHeight };
49
- }
50
-
51
- resolvedDimensions[key] = newDimensions;
52
- setDimensions(newDimensions);
53
- };
54
- img.src = icon;
55
- }, [icon, maxSize, key]);
11
+ const [isSquare, setIsSquare] = useState(false);
12
+ const squareCap = isSquare && !isLogin ? 40 : maxSize;
56
13
 
57
14
  const logo = (
58
15
  <Box
59
16
  component="img"
60
17
  src={icon}
18
+ onLoad={(e) => {
19
+ const { naturalWidth, naturalHeight } = e.currentTarget;
20
+ setIsSquare(naturalWidth === naturalHeight);
21
+ }}
61
22
  sx={{
62
- width: dimensions.width,
63
- height: dimensions.height,
23
+ maxWidth: squareCap,
24
+ maxHeight: squareCap,
25
+ width: "auto",
26
+ height: "auto",
27
+ objectFit: "contain",
64
28
  cursor: "pointer",
65
29
  ...sx,
66
30
  }}
@@ -14,6 +14,7 @@ export const Flow = ({
14
14
  onChange,
15
15
  height,
16
16
  initialZoom,
17
+ centered = false,
17
18
  }) => {
18
19
  const [floatingNodes, setFloatingNodes] = useState([]);
19
20
 
@@ -90,6 +91,7 @@ export const Flow = ({
90
91
  floatingNodes={floatingNodes}
91
92
  height={height}
92
93
  initialZoom={initialZoom}
94
+ centered={centered}
93
95
  />
94
96
  </Box>
95
97
  );
@@ -18,6 +18,7 @@ const FlowNode = ({
18
18
  node,
19
19
  height,
20
20
  initialZoom,
21
+ centered,
21
22
  ...props
22
23
  }) => {
23
24
  if (!isRoot) {
@@ -52,6 +53,7 @@ const FlowNode = ({
52
53
  plugin={plugin}
53
54
  height={height}
54
55
  initialZoom={initialZoom}
56
+ centered={centered}
55
57
  >
56
58
  {node && (
57
59
  <FlowNodeView
@@ -18,6 +18,7 @@ const FlowViewport = ({
18
18
  plugin,
19
19
  height = "100vh",
20
20
  initialZoom = 1,
21
+ centered = false,
21
22
  sx = {},
22
23
  ...rest
23
24
  }) => {
@@ -45,6 +46,8 @@ const FlowViewport = ({
45
46
  } = useSelection();
46
47
 
47
48
  useEffect(() => {
49
+ if (centered) return;
50
+
48
51
  const container = containerRef.current;
49
52
  const inner = innerRef.current;
50
53
  if (!container || !inner) return;
@@ -64,7 +67,7 @@ const FlowViewport = ({
64
67
  observer.observe(container);
65
68
 
66
69
  return () => observer.disconnect();
67
- }, []);
70
+ }, [centered]);
68
71
 
69
72
  useEffect(() => {
70
73
  const handleMouseMove = (e) => {
@@ -310,11 +313,11 @@ const FlowViewport = ({
310
313
  height: height,
311
314
  display: "flex",
312
315
  alignItems: "center",
313
- justifyContent: shouldCenter ? "center" : "flex-start",
316
+ justifyContent: centered || shouldCenter ? "center" : "flex-start",
314
317
  transition: isDragging ? "none" : "transform 0.1s ease-out",
315
318
  pointerEvents: "auto",
316
319
  position: "relative",
317
- pl: variant === "horizontal" ? 4 : 0,
320
+ pl: centered ? 0 : variant === "horizontal" ? 4 : 0,
318
321
  }}
319
322
  >
320
323
  {children}