@canmingir/link 1.2.38 → 1.2.40

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.38",
3
+ "version": "1.2.40",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -3,36 +3,56 @@ import Link from "@mui/material/Link";
3
3
  import { RouterLink } from "../../routes/components";
4
4
  import config from "../../config/config";
5
5
 
6
- import React, { useEffect, useState } from "react";
6
+ import React, { useEffect, useRef, useState } from "react";
7
7
 
8
- const Logo = ({ disabledLink = false, sx, maxSize = 99 }) => {
8
+ const resolvedDimensions = {};
9
+
10
+ const Logo = ({ disabledLink = false, sx, maxSize = 65, isLogin = false }) => {
9
11
  const { icon } = config().template.login;
10
- const [dimensions, setDimensions] = useState({
11
- width: maxSize,
12
- height: maxSize,
13
- });
12
+ const key = `${icon}`;
13
+
14
+ const [dimensions, setDimensions] = useState(
15
+ resolvedDimensions[key] || { width: maxSize, height: maxSize }
16
+ );
14
17
 
15
18
  useEffect(() => {
16
- if (icon) {
17
- const img = new Image();
18
- img.onload = () => {
19
- const { naturalWidth, naturalHeight } = img;
20
-
21
- if (naturalWidth > maxSize || naturalHeight > maxSize) {
22
- setDimensions({
23
- width: 40,
24
- height: 40,
25
- });
19
+ if (!icon || resolvedDimensions[key]) return;
20
+
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
+ };
26
33
  } else {
27
- setDimensions({
28
- width: naturalWidth,
29
- height: naturalHeight,
30
- });
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
+ }
31
46
  }
32
- };
33
- img.src = icon;
34
- }
35
- }, [icon, maxSize]);
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]);
36
56
 
37
57
  const logo = (
38
58
  <Box
@@ -47,9 +67,7 @@ const Logo = ({ disabledLink = false, sx, maxSize = 99 }) => {
47
67
  />
48
68
  );
49
69
 
50
- if (disabledLink) {
51
- return logo;
52
- }
70
+ if (disabledLink) return logo;
53
71
 
54
72
  return (
55
73
  <Link component={RouterLink} href="/" sx={{ display: "contents" }}>
@@ -104,7 +104,7 @@ export default function NavVertical({ openNav, onCloseNav }) {
104
104
  mt: 3,
105
105
  }}
106
106
  >
107
- <Logo sx={{ ml: 4, mb: 1 }} />
107
+ <Logo sx={{ ml: 4 }} />
108
108
  <Typography
109
109
  sx={{
110
110
  ml: 1,
@@ -130,8 +130,9 @@ export default function NavVertical({ openNav, onCloseNav }) {
130
130
  marginBottom: lgUp ? 3 : 0,
131
131
  position: lgUp ? "static" : "fixed",
132
132
  bottom: lgUp ? "auto" : 66,
133
- width: "100%"
134
- }}>
133
+ width: "100%",
134
+ }}
135
+ >
135
136
  {actionButtons &&
136
137
  actionButtons?.map((Action, index) => (
137
138
  <Box key={index} component={Action}></Box>
@@ -190,7 +191,7 @@ export default function NavVertical({ openNav, onCloseNav }) {
190
191
  sx: {
191
192
  width: NAV.W_VERTICAL,
192
193
  },
193
- }
194
+ },
194
195
  }}
195
196
  >
196
197
  {renderContent}
@@ -46,11 +46,10 @@ export default function AuthModernLayout() {
46
46
  }}
47
47
  >
48
48
  <Logo
49
+ isLogin={true}
49
50
  maxSize={140}
50
51
  sx={{
51
52
  mb: 2,
52
- width: 72,
53
- height: 72,
54
53
  alignSelf: "center",
55
54
  }}
56
55
  />
@@ -58,7 +58,7 @@ export const Flow = ({
58
58
  .filter(Boolean);
59
59
 
60
60
  return children.length > 0
61
- ? { id: "__root__", label: "Start", children }
61
+ ? { id: "__root__", label: "Start", virtual: true, children }
62
62
  : null;
63
63
  }, [nodesById, roots]);
64
64
 
@@ -26,10 +26,12 @@ const FlowViewport = ({
26
26
  const [zoom, setZoom] = useState(1);
27
27
  const [isDragging, setIsDragging] = useState(false);
28
28
  const [selectionBox, setSelectionBox] = useState(null);
29
+ const [shouldCenter, setShouldCenter] = useState(true);
29
30
 
30
31
  const containerRef = useRef(null);
31
32
  const selectionBoxRef = useRef(null);
32
33
  const mousePositionRef = useRef({ x: 0, y: 0 });
34
+ const innerRef = useRef(null);
33
35
 
34
36
  const {
35
37
  clearSelection,
@@ -40,6 +42,28 @@ const FlowViewport = ({
40
42
  selectedIds,
41
43
  } = useSelection();
42
44
 
45
+ useEffect(() => {
46
+ const container = containerRef.current;
47
+ const inner = innerRef.current;
48
+ if (!container || !inner) return;
49
+
50
+ const observer = new ResizeObserver(() => {
51
+ const contentWidth = inner.scrollWidth;
52
+ const contentHeight = inner.scrollHeight;
53
+ const containerWidth = container.clientWidth;
54
+ const containerHeight = container.clientHeight;
55
+
56
+ const exceeds =
57
+ contentWidth > containerWidth || contentHeight > containerHeight;
58
+ setShouldCenter(!exceeds);
59
+ });
60
+
61
+ observer.observe(inner);
62
+ observer.observe(container);
63
+
64
+ return () => observer.disconnect();
65
+ }, []);
66
+
43
67
  useEffect(() => {
44
68
  const handleMouseMove = (e) => {
45
69
  mousePositionRef.current = { x: e.clientX, y: e.clientY };
@@ -241,7 +265,7 @@ const FlowViewport = ({
241
265
  ref={containerRef}
242
266
  onMouseDown={handleViewportMouseDown}
243
267
  sx={{
244
- width: "100vw",
268
+ width: "100%",
245
269
  height: "100vh",
246
270
  overflow: "hidden",
247
271
  bgcolor: "none",
@@ -252,6 +276,7 @@ const FlowViewport = ({
252
276
  >
253
277
  <SelectionOverlay box={selectionBox} selectionColor={selectionColor} />
254
278
  <Box
279
+ ref={innerRef}
255
280
  sx={{
256
281
  transform: `translate(${offset.x}px, ${offset.y}px) scale(${zoom})`,
257
282
  transformOrigin: "center center",
@@ -259,7 +284,7 @@ const FlowViewport = ({
259
284
  height: height,
260
285
  display: "flex",
261
286
  alignItems: "center",
262
- justifyContent: variant === "horizontal" ? "flex-start" : "center",
287
+ justifyContent: shouldCenter ? "center" : "flex-start",
263
288
  transition: isDragging ? "none" : "transform 0.1s ease-out",
264
289
  pointerEvents: "auto",
265
290
  position: "relative",
@@ -20,6 +20,7 @@ const FlowNodeView = ({
20
20
  onConnect,
21
21
  }) => {
22
22
  const hasChildren = Array.isArray(node.children) && node.children.length > 0;
23
+ const isVirtualRoot = !!node.virtual;
23
24
 
24
25
  const {
25
26
  baseStyle,
@@ -146,6 +147,36 @@ const FlowNodeView = ({
146
147
  );
147
148
  };
148
149
 
150
+ if (isVirtualRoot) {
151
+ return (
152
+ <Box
153
+ ref={containerRef}
154
+ sx={{
155
+ display: "flex",
156
+ flexDirection: isHorizontal ? "row" : "column",
157
+ alignItems: "flex-end",
158
+ gap,
159
+ position: "relative",
160
+ }}
161
+ >
162
+ {node.children.map((child) => (
163
+ <FlowNode
164
+ key={child.id}
165
+ node={child}
166
+ type={type}
167
+ variant={variant}
168
+ style={style}
169
+ plugin={plugin}
170
+ registerRef={(el) => (childRefs.current[child.id] = el)}
171
+ onDrag={() => setConnectorTick((t) => t + 1)}
172
+ isRoot={false}
173
+ onConnect={onConnect}
174
+ />
175
+ ))}
176
+ </Box>
177
+ );
178
+ }
179
+
149
180
  return (
150
181
  <Box
151
182
  ref={containerRef}