diff --git a/app/board/[boardId]/_components/selection-box.tsx b/app/board/[boardId]/_components/selection-box.tsx
index 7e62326..9c667ef 100644
--- a/app/board/[boardId]/_components/selection-box.tsx
+++ b/app/board/[boardId]/_components/selection-box.tsx
@@ -8,199 +8,95 @@ import { useSelectionBounds } from "@/hooks/use-selection-bounds";
interface SelectionBoxProps {
onResizeHandlePointerDown: (corner: Side, initialBounds: XYWH) => void;
-};
+}
const HANDLE_WIDTH = 8;
-export const SelectionBox = memo(({
- onResizeHandlePointerDown,
-}: SelectionBoxProps) => {
- const soleLayerId = useSelf((me) =>
- me.presence.selection.length === 1 ? me.presence.selection[0] : null
- );
+export const SelectionBox = memo(
+ ({ onResizeHandlePointerDown }: SelectionBoxProps) => {
+ const soleLayerId = useSelf((me) =>
+ me.presence.selection.length === 1 ? me.presence.selection[0] : null
+ );
- const isShowingHandles = useStorage((root) =>
- soleLayerId && root.layers.get(soleLayerId)?.type !== LayerType.Path
- );
+ const isShowingHandles = useStorage(
+ (root) =>
+ soleLayerId && root.layers.get(soleLayerId)?.type !== LayerType.Path
+ );
- const bounds = useSelectionBounds();
+ const bounds = useSelectionBounds();
- if (!bounds) {
- return null;
- }
+ if (!bounds) {
+ return null;
+ }
+
+ const rect = {
+ cardinal: ["nwse", "ns", "nesw", "ew", "nwse", "ns", "nesw", "ew"],
+ boundsX: [
+ bounds.x - HANDLE_WIDTH / 2,
+ bounds.x + bounds.width / 2 - HANDLE_WIDTH / 2,
+ bounds.x + bounds.width - HANDLE_WIDTH / 2,
+ bounds.x + bounds.width - HANDLE_WIDTH / 2,
+ bounds.x + bounds.width - HANDLE_WIDTH / 2,
+ bounds.x + bounds.width / 2 - HANDLE_WIDTH / 2,
+ bounds.x - HANDLE_WIDTH / 2,
+ bounds.x - HANDLE_WIDTH / 2,
+ ],
+ boundsY: [
+ bounds.y - HANDLE_WIDTH / 2,
+ bounds.y - HANDLE_WIDTH / 2,
+ bounds.y - HANDLE_WIDTH / 2,
+ bounds.y + bounds.height / 2 - HANDLE_WIDTH / 2,
+ bounds.y + bounds.height - HANDLE_WIDTH / 2,
+ bounds.y + bounds.height - HANDLE_WIDTH / 2,
+ bounds.y + bounds.height - HANDLE_WIDTH / 2,
+ bounds.y + bounds.height / 2 - HANDLE_WIDTH / 2,
+ ],
+ resizeSide: [
+ Side.Top + Side.Left,
+ Side.Top,
+ Side.Top + Side.Right,
+ Side.Right,
+ Side.Bottom + Side.Right,
+ Side.Bottom,
+ Side.Bottom + Side.Left,
+ Side.Left,
+ ],
+ };
- return (
- <>
-
- {isShowingHandles && (
- <>
- {
- e.stopPropagation();
- onResizeHandlePointerDown(Side.Top + Side.Left, bounds);
- }}
- />
- {
- e.stopPropagation();
- onResizeHandlePointerDown(Side.Top, bounds);
- }}
- />
- {
- e.stopPropagation();
- onResizeHandlePointerDown(Side.Top + Side.Right, bounds);
- }}
- />
- {
- e.stopPropagation();
- onResizeHandlePointerDown(Side.Right, bounds);
- }}
- />
- {
- e.stopPropagation();
- onResizeHandlePointerDown(Side.Bottom + Side.Right, bounds);
- }}
- />
- {
- e.stopPropagation();
- onResizeHandlePointerDown(Side.Bottom, bounds);
- }}
- />
- {
- e.stopPropagation();
- onResizeHandlePointerDown(Side.Bottom + Side.Left, bounds);
- }}
- />
- {
- e.stopPropagation();
- onResizeHandlePointerDown(Side.Left, bounds);
- }}
- />
- >
- )}
- >
- );
-});
+ return (
+ <>
+
+ {isShowingHandles &&
+ rect.cardinal.map((direction, i) => (
+ {
+ e.stopPropagation();
+ onResizeHandlePointerDown(rect.resizeSide[i], bounds);
+ }}
+ />
+ ))}
+ >
+ );
+ }
+);
-SelectionBox.displayName = "SelectionBox";
\ No newline at end of file
+SelectionBox.displayName = "SelectionBox";