Skip to content

Free, simple, and intuitive online database diagram editor and SQL generator.

i wanna cry

1ilit0e4879bab5a7
diff --git a/src/components/area.jsx b/src/components/area.jsx
index 37fd154b..92ae242e 100644
--- a/src/components/area.jsx
+++ b/src/components/area.jsx
@@ -1,10 +1,103 @@
import { React, useState } from "react";
export default function Area(props) {
- const [size, setSize] = useState({
- width: props.areaData.width,
- height: props.areaData.height,
- });
+ const [resize, setResize] = useState("none");
+ const [initialMouseX, setInitialMouseX] = useState(0);
+ const [initialMouseY, setInitialMouseY] = useState(0);
+ const [initialWidth, setInitialWidth] = useState(0);
+ const [initialHeight, setInitialHeight] = useState(0);
+ const [initialX, setInitialX] = useState(0);
+ const [initialY, setInitialY] = useState(0);
+
+ const handleMouseDown = (e, dir) => {
+ setResize(dir);
+ props.setPanning(false);
+ setInitialMouseX(e.clientX);
+ setInitialMouseY(e.clientY);
+ setInitialWidth(props.areaData.width);
+ setInitialHeight(props.areaData.height);
+ setInitialX(props.areaData.x);
+ setInitialY(props.areaData.y);
+ };
+
+ const handleMouseMove = (e) => {
+ props.setPanning(false);
+ if (resize === "br") {
+ const newWidth = initialWidth + (e.clientX - initialMouseX);
+ const newHeight = initialHeight + (e.clientY - initialMouseY);
+ props.setAreas((prev) => {
+ return prev.map((a) => {
+ if (a.id === props.areaData.id) {
+ return {
+ ...a,
+ width: newWidth,
+ height: newHeight,
+ };
+ }
+ return a;
+ });
+ });
+ } else if (resize === "tl") {
+ const newX = initialX + (e.clientX - initialMouseX);
+ const newY = initialY + (e.clientY - initialMouseY);
+ const newWidth = initialWidth - (e.clientX - initialMouseX);
+ const newHeight = initialHeight - (e.clientY - initialMouseY);
+ props.setAreas((prev) => {
+ return prev.map((a) => {
+ if (a.id === props.areaData.id) {
+ return {
+ ...a,
+ x: newX,
+ y: newY,
+ width: newWidth,
+ height: newHeight,
+ };
+ }
+ return a;
+ });
+ });
+ } else if (resize === "tr") {
+ const newY = initialY + (e.clientY - initialMouseY);
+ const newWidth = initialWidth + (e.clientX - initialMouseX);
+ const newHeight = initialHeight - (e.clientY - initialMouseY);
+ props.setAreas((prev) => {
+ return prev.map((a) => {
+ if (a.id === props.areaData.id) {
+ return {
+ ...a,
+ y: newY,
+ width: newWidth,
+ height: newHeight,
+ };
+ }
+ return a;
+ });
+ });
+ } else if (resize === "bl") {
+ const newX = initialX + (e.clientX - initialMouseX);
+ const newWidth = initialWidth - (e.clientX - initialMouseX);
+ const newHeight = initialHeight + (e.clientY - initialMouseY);
+ props.setAreas((prev) => {
+ return prev.map((a) => {
+ if (a.id === props.areaData.id) {
+ return {
+ ...a,
+ x: newX,
+ width: newWidth,
+ height: newHeight,
+ };
+ }
+ return a;
+ });
+ });
+ } else {
+ return;
+ }
+ };
+
+ const handleMouseUp = () => {
+ setResize("none");
+ };
return (
<g>
@@ -12,35 +105,78 @@ export default function Area(props) {
key={props.areaData.id}
x={props.areaData.x}
y={props.areaData.y}
- width={size.width}
- height={size.height}
+ width={props.areaData.width}
+ height={props.areaData.height}
style={{ cursor: "move" }}
onMouseDown={props.onMouseDown}
>
- <div className="border-2 border-dashed border-blue-600 opacity-70 bg-slate-400 w-fill h-full">
+ <div className="border-2 border-dashed border-blue-600 opacity-70 bg-slate-400 w-fill h-full select-none">
{props.areaData.name}
</div>
</foreignObject>
- <circle cx={props.areaData.x} cy={props.areaData.y} r={5} fill="blue" />
- <circle
- cx={props.areaData.x + props.areaData.width}
- cy={props.areaData.y}
- r={5}
- fill="blue"
+ <rect
+ x={props.areaData.x - 6}
+ y={props.areaData.y - 6}
+ width={32}
+ height={32}
+ fill="lightblue"
+ stroke="blue"
+ strokeWidth={1}
+ cursor="nwse-resize"
+ onMouseDown={(e) => handleMouseDown(e, "tl")}
+ onMouseUp={handleMouseUp}
+ onMouseMove={handleMouseMove}
+ onMouseLeave={(e) => {
+ setResize("none");
+ }}
+ />
+ <rect
+ x={props.areaData.x + props.areaData.width - 6}
+ y={props.areaData.y - 6}
+ width={32}
+ height={32}
+ fill="lightblue"
+ stroke="blue"
+ strokeWidth={1}
+ cursor="nesw-resize"
+ onMouseDown={(e) => handleMouseDown(e, "tr")}
+ onMouseUp={handleMouseUp}
+ onMouseMove={handleMouseMove}
+ onMouseLeave={(e) => {
+ setResize("none");
+ }}
/>
- <circle
- cx={props.areaData.x}
- cy={props.areaData.y + props.areaData.height}
- r={5}
- fill="blue"
+ <rect
+ x={props.areaData.x - 6}
+ y={props.areaData.y + props.areaData.height - 6}
+ width={32}
+ height={32}
+ fill="lightblue"
+ stroke="blue"
+ strokeWidth={1}
+ cursor="nesw-resize"
+ onMouseDown={(e) => handleMouseDown(e, "bl")}
+ onMouseUp={handleMouseUp}
+ onMouseMove={handleMouseMove}
+ onMouseLeave={(e) => {
+ setResize("none");
+ }}
/>
- <circle
- cx={props.areaData.x + size.width}
- cy={props.areaData.y + size.height}
- r={5}
- fill="blue"
- cursor="pointer"
- onMouseDown={(e) => {}}
+ <rect
+ x={props.areaData.x + props.areaData.width - 6}
+ y={props.areaData.y + props.areaData.height - 6}
+ width={32}
+ height={32}
+ fill="lightblue"
+ stroke="blue"
+ strokeWidth={1}
+ cursor="nwse-resize"
+ onMouseDown={(e) => handleMouseDown(e, "br")}
+ onMouseUp={handleMouseUp}
+ onMouseMove={handleMouseMove}
+ onMouseLeave={(e) => {
+ setResize("none");
+ }}
/>
</g>
);
diff --git a/src/components/canvas.jsx b/src/components/canvas.jsx
index 6633f9d2..9ded02cf 100644
--- a/src/components/canvas.jsx
+++ b/src/components/canvas.jsx
@@ -283,6 +283,8 @@ export default function Canvas(props) {
key={a.id}
areaData={a}
onMouseDown={(e) => handleMouseDownRect(e, a.id, ObjectType.AREA)}
+ setPanning={setPanning}
+ setAreas={props.setAreas}
></Area>
))}
{props.tables.map((table, i) => (