Skip to content

Commit 6105d3e

Browse files
committed
Feat!: added element rotation and remove booths
1 parent e80b156 commit 6105d3e

File tree

30 files changed

+83
-219
lines changed

30 files changed

+83
-219
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868

6969
- **Miscallaneous**
7070
- Add, move around and scale background images ✓
71-
- Add and move around booths ✓
7271
- Multiple element selection and deselection ✓
7372
- Bring elements to front or back ✓
7473

src/components/controls/image.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const onUploadClick = () => document.getElementById("image-input").click();
1313

1414
type IImageControlProps = Pick<ISTKProps, "options" | "styles">;
1515

16-
const ImageControls = ({ options: { maxImageSize = 1024000 } = {} }: IImageControlProps) => {
16+
const Controls = ({ options: { maxImageSize = 1024000 } = {} }: IImageControlProps) => {
1717
const [file, setFile] = useState(null);
1818

1919
const onUpload = async (e) => {
@@ -68,4 +68,8 @@ const ImageControls = ({ options: { maxImageSize = 1024000 } = {} }: IImageContr
6868
);
6969
};
7070

71-
export default memo(ImageControls);
71+
const ImageControls = memo(Controls);
72+
73+
(ImageControls as any).name = "ImageControls";
74+
75+
export default ImageControls;

src/components/controls/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { toggleControls } from "@/store/reducers/editor";
88
import { ISTKProps } from "@/types";
99
import { AnimatedSwitcher, IconButton } from "../core";
1010
import { Tool } from "../toolbar/data";
11-
import { ElementType } from "../workspace/elements";
1211
import { default as ImageControls } from "./image";
1312
import { default as NoControls } from "./no-controls";
1413
import { default as NoSelectedElement } from "./no-selection";
@@ -37,7 +36,6 @@ const Controls = ({ options, styles }: IControlProps) => {
3736
const firstElementType = document
3837
.getElementById(selectedElementIds[0])
3938
?.getAttribute?.(dataAttributes.elementType);
40-
if (firstElementType === ElementType.Booth) return SelectControls;
4139
if (selectedElementIds.length > 1) {
4240
const same = selectedElementIds.every((id) => {
4341
return document.getElementById(id)?.getAttribute?.(dataAttributes.elementType) === firstElementType;

src/components/controls/select/general.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ const GeneralSelectControls = () => {
1818
max={360}
1919
onChange={(e) => {
2020
selectedElementIds.forEach((id) => {
21-
d3Extended.selectById(id).style("transform", `rotate(${e.target.value}deg)`);
21+
const element = d3Extended.selectById(id);
22+
if (element?.node()?.tagName === "svg") {
23+
element.node().parentElement.style.transform = `rotate(${e.target.value}deg)`;
24+
} else {
25+
element.style("transform", `rotate(${e.target.value}deg)`);
26+
}
2227
});
2328
}}
2429
/>

src/components/controls/select/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Fragment, useMemo } from "react";
1+
import { useMemo } from "react";
22
import { useSelector } from "react-redux";
33
import { ElementType } from "@/components/workspace/elements";
44
import { dataAttributes } from "@/constants";
@@ -21,7 +21,6 @@ const SelectControls = ({ options, styles }: IControlProps) => {
2121
if (firstElementType === ElementType.Shape) return ShapeSelectControls;
2222
if (firstElementType === ElementType.Polyline) return PolylineSelectControls;
2323
if (firstElementType === ElementType.Image) return ImageSelectControls;
24-
if (firstElementType === ElementType.Booth) return Fragment;
2524
return SeatSelectControls;
2625
}, [selectedElementIds]);
2726

src/components/controls/shapes/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ const CursorShape = (Shape) => {
1212
const icon = (props) => (
1313
<Shape
1414
{...props}
15-
className={twMerge(props.className, "fill-transparent")}
15+
className={twMerge(
16+
props.className,
17+
"fill-transparent",
18+
Shape.displayName !== RectangleHorizontal.displayName && "stroke-[0.9]"
19+
)}
1620
size={Shape.displayName === RectangleHorizontal.displayName ? resizableRectangle.width : shapeSize}
1721
strokeWidth={Shape.displayName === RectangleHorizontal.displayName ? 0.25 : shapeStrokeWidth}
1822
/>
@@ -21,7 +25,7 @@ const CursorShape = (Shape) => {
2125
return icon;
2226
};
2327

24-
const ShapeControls = () => {
28+
const Controls = () => {
2529
const [selectedIndex, setSelectedIndex] = useState(0);
2630

2731
const onShapeClick = useCallback((shape, i) => {
@@ -54,4 +58,8 @@ export const selectFirstShape = () =>
5458
store.dispatch(setCursor(CursorShape(shapeList[0])));
5559
});
5660

57-
export default memo(ShapeControls, isEqual);
61+
const ShapeControls = memo(Controls, isEqual);
62+
63+
(ShapeControls as any).name = "ShapeControls";
64+
65+
export default ShapeControls;

src/components/controls/shapes/shape-list.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@ import {
33
ArrowBigLeft,
44
ArrowBigRight,
55
ArrowBigUp,
6+
Codesandbox,
67
Diamond,
78
Hexagon,
89
Octagon,
910
Pentagon,
1011
Play,
12+
RectangleHorizontal,
1113
Square,
1214
Squircle
1315
} from "lucide-react";
1416

1517
export const shapes = {
16-
ArrowBigLeft: ArrowBigLeft,
17-
ArrowBigRight: ArrowBigRight,
18-
ArrowBigDown: ArrowBigDown,
19-
ArrowBigUp: ArrowBigUp,
20-
Play: Play,
21-
Squircle: Squircle,
22-
Pentagon: Pentagon,
23-
Square: Square,
24-
Hexagon: Hexagon,
25-
Octagon: Octagon,
26-
Diamond: Diamond
18+
RectangleHorizontal,
19+
Codesandbox,
20+
ArrowBigLeft,
21+
ArrowBigRight,
22+
ArrowBigDown,
23+
ArrowBigUp,
24+
Play,
25+
Squircle,
26+
Pentagon,
27+
Square,
28+
Hexagon,
29+
Octagon,
30+
Diamond
2731
};
2832

2933
export const shapeList = Object.values(shapes);

src/components/toolbar/data.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
import {
2-
CaseSensitive,
3-
Circle,
4-
Codesandbox,
5-
Image,
6-
MousePointer2,
7-
Move,
8-
PenTool,
9-
Pentagon,
10-
Sparkles,
11-
Square
12-
} from "lucide-react";
1+
import { CaseSensitive, Circle, Image, MousePointer2, Move, PenTool, Pentagon, Sparkles, Square } from "lucide-react";
132
import { twMerge } from "tailwind-merge";
143

154
export enum Tool {
165
Select = "Select",
176
Eraser = "Eraser",
187
Seat = "Seat",
19-
Booth = "Booth",
208
Pen = "Pen",
219
Text = "Text",
2210
Shape = "Shapes",
@@ -57,12 +45,6 @@ export const tools = {
5745
}
5846
]
5947
},
60-
[Tool.Booth]: {
61-
icon: Codesandbox,
62-
iconCursor: (props: any) => <Codesandbox {...props} size={52} strokeWidth={1} />,
63-
shortcut: "B",
64-
description: "Click anywhere to place a booth"
65-
},
6648
[Tool.Pen]: {
6749
icon: PenTool,
6850
iconCursor: (props: any) => (

src/components/workspace/elements/booth.tsx

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/components/workspace/elements/image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const Image: React.FC<IImageProps> = forwardRef(
3131
preserveAspectRatio="none"
3232
style={{
3333
transform: `rotate(${rotation ?? 0}deg)`,
34-
transformOrigin: `${x + width / 2}px ${y + height / 2}px`,
34+
transformOrigin: `center`,
3535
...consumer.styles?.elements?.image?.base?.properties
3636
}}
3737
/>

0 commit comments

Comments
 (0)