@canmingir/link 1.2.42 → 1.2.44

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.42",
3
+ "version": "1.2.44",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -1,8 +1,8 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from "react";
2
+
1
3
  import { Box } from "@mui/material";
2
4
  import { useSelection } from "../selection/SelectionContext";
3
5
 
4
- import React, { useCallback, useEffect, useRef, useState } from "react";
5
-
6
6
  const DraggableNode = ({
7
7
  children,
8
8
  registerRef,
@@ -13,7 +13,7 @@ const DraggableNode = ({
13
13
  onConnect,
14
14
  }) => {
15
15
  const [offset, setOffset] = useState(() =>
16
- initialPosition ? { ...initialPosition } : { x: 0, y: 0 }
16
+ initialPosition ? { ...initialPosition } : { x: 0, y: 0 },
17
17
  );
18
18
 
19
19
  useEffect(() => {
@@ -27,6 +27,7 @@ const DraggableNode = ({
27
27
  const localRef = useRef(null);
28
28
  const lastDeltaRef = useRef({ x: 0, y: 0 });
29
29
  const onDragRef = useRef(onDrag);
30
+ const didDragRef = useRef(false);
30
31
 
31
32
  const {
32
33
  isSelected,
@@ -58,14 +59,32 @@ const DraggableNode = ({
58
59
  localRef.current = el;
59
60
  registerRef?.(el);
60
61
  },
61
- [registerRef]
62
+ [registerRef],
62
63
  );
63
64
 
65
+ useEffect(() => {
66
+ const el = localRef.current;
67
+ if (!el) return;
68
+
69
+ const onClickCapture = (e) => {
70
+ if (didDragRef.current) {
71
+ e.stopPropagation();
72
+ e.preventDefault();
73
+ didDragRef.current = false;
74
+ }
75
+ };
76
+
77
+ el.addEventListener("click", onClickCapture, true);
78
+ return () => el.removeEventListener("click", onClickCapture, true);
79
+ }, []);
80
+
64
81
  const handleMouseDown = useCallback(
65
82
  (e) => {
66
83
  if (e.button !== 0) return;
67
84
  e.stopPropagation();
68
85
 
86
+ didDragRef.current = false;
87
+
69
88
  if (onConnect && e.altKey) {
70
89
  e.preventDefault();
71
90
  onConnect(nodeId, [...selectedIds]);
@@ -91,6 +110,10 @@ const DraggableNode = ({
91
110
  const dx = ev.clientX - startX;
92
111
  const dy = ev.clientY - startY;
93
112
 
113
+ if (!didDragRef.current && (Math.abs(dx) > 3 || Math.abs(dy) > 3)) {
114
+ didDragRef.current = true;
115
+ }
116
+
94
117
  const deltaDx = dx - lastDeltaRef.current.x;
95
118
  const deltaDy = dy - lastDeltaRef.current.y;
96
119
  lastDeltaRef.current = { x: dx, y: dy };
@@ -125,7 +148,7 @@ const DraggableNode = ({
125
148
  clearSelection,
126
149
  moveSelectedNodes,
127
150
  onConnect,
128
- ]
151
+ ],
129
152
  );
130
153
 
131
154
  return (
@@ -1,24 +1,20 @@
1
- import { Box, Card, Divider, Typography } from "@mui/material";
2
- import { alpha, useTheme } from "@mui/material/styles";
1
+ import {
2
+ Card,
3
+ CardActions,
4
+ CardContent,
5
+ CardHeader,
6
+ Divider,
7
+ } from "@mui/material";
3
8
 
4
9
  import React from "react";
10
+ import { useTheme } from "@mui/material/styles";
5
11
 
6
- const GlassCard = ({
7
- width = "100%",
8
- height = "85vh",
9
- header,
10
- content,
11
- actions,
12
- contentSx = {},
13
- }) => {
12
+ const GlassCard = ({ children, sx = {}, ...props }) => {
14
13
  const theme = useTheme();
15
14
 
16
15
  return (
17
16
  <Card
18
17
  sx={{
19
- width: width || "100%",
20
- height: height || "85vh",
21
- flexShrink: 0,
22
18
  display: "flex",
23
19
  flexDirection: "column",
24
20
  background: `linear-gradient(135deg, ${theme.palette.primary.main}08 0%, ${theme.palette.secondary.main}05 100%)`,
@@ -26,70 +22,63 @@ const GlassCard = ({
26
22
  border: `1px solid ${theme.palette.divider}`,
27
23
  borderRadius: 2,
28
24
  overflow: "hidden",
25
+ ...sx,
29
26
  }}
27
+ {...props}
30
28
  >
31
- {header && (
32
- <>
33
- <Box
34
- sx={{
35
- display: "flex",
36
- alignItems: "center",
37
- justifyContent: "space-between",
38
- px: 2,
39
- py: 1.5,
40
- minHeight: 52,
41
- flexShrink: 0,
42
- }}
43
- >
44
- <Box sx={{ minWidth: 0, flex: 1 }}>
45
- <Typography
46
- variant="subtitle2"
47
- noWrap
48
- sx={{
49
- fontWeight: 600,
50
- color: "text.primary",
51
- lineHeight: 1.3,
52
- }}
53
- >
54
- {header.title}
55
- </Typography>
56
- {header.subtitle && (
57
- <Typography
58
- variant="caption"
59
- noWrap
60
- sx={{
61
- color: "text.secondary",
62
- lineHeight: 1.3,
63
- display: "block",
64
- }}
65
- >
66
- {header.subtitle}
67
- </Typography>
68
- )}
69
- </Box>
70
- {actions && <Box sx={{ ml: 1, flexShrink: 0 }}>{actions}</Box>}
71
- </Box>
72
- <Divider />
73
- </>
74
- )}
75
-
76
- <Box
77
- sx={{
78
- flex: 1,
79
- overflow: "auto",
80
- position: "relative",
81
- ...contentSx,
82
- }}
83
- >
84
- {!header && actions && (
85
- <Box sx={{ position: "absolute", top: 8, right: 8, zIndex: 1 }}>
86
- {actions}
87
- </Box>
88
- )}
89
- {content}
90
- </Box>
29
+ {children}
91
30
  </Card>
92
31
  );
93
32
  };
94
33
 
34
+ const GlassCardHeader = ({ divider = true, sx = {}, ...props }) => (
35
+ <>
36
+ <CardHeader
37
+ sx={{
38
+ px: 1.5,
39
+ py: 0.75,
40
+ "& .MuiCardHeader-title": {
41
+ fontSize: "0.8125rem",
42
+ fontWeight: 600,
43
+ lineHeight: 1.3,
44
+ },
45
+ "& .MuiCardHeader-subheader": {
46
+ fontSize: "0.75rem",
47
+ lineHeight: 1.3,
48
+ },
49
+ ...sx,
50
+ }}
51
+ {...props}
52
+ />
53
+ {divider && <Divider />}
54
+ </>
55
+ );
56
+
57
+ const GlassCardContent = ({ sx = {}, ...props }) => (
58
+ <CardContent
59
+ sx={{
60
+ flex: 1,
61
+ overflow: "auto",
62
+ position: "relative",
63
+ p: 0,
64
+ "&:last-child": { pb: 0 },
65
+ ...sx,
66
+ }}
67
+ {...props}
68
+ />
69
+ );
70
+
71
+ const GlassCardActions = ({ sx = {}, ...props }) => (
72
+ <CardActions
73
+ sx={{
74
+ px: 1.5,
75
+ py: 0.75,
76
+ flexShrink: 0,
77
+ ...sx,
78
+ }}
79
+ {...props}
80
+ />
81
+ );
82
+
83
+ export { GlassCardHeader, GlassCardContent, GlassCardActions };
95
84
  export default GlassCard;
@@ -1 +1 @@
1
- export { default } from "./GlassCard";
1
+ export { default, GlassCardHeader, GlassCardContent, GlassCardActions } from "./GlassCard";
package/src/lib/index.js CHANGED
@@ -49,4 +49,9 @@ export { default as Schema } from "./Schema";
49
49
  export { default as SchemaEditor } from "./SchemaEditor";
50
50
  export { default as ToggleableMenu } from "./ToggleableMenu";
51
51
  export { default as APIBody } from "./NewApiBody/NewAPIBody";
52
- export { default as GlassCard } from "./GlassCard/GlassCard";
52
+ export {
53
+ default as GlassCard,
54
+ GlassCardHeader,
55
+ GlassCardContent,
56
+ GlassCardActions,
57
+ } from "./GlassCard/GlassCard";