Skip to content

Commit f2eca7c

Browse files
committed
๐Ÿ—๏ธ refactor: ๋…ธ๋“œ ์œ„์น˜ ๋ฐ์ดํ„ฐ ๋ชจ๋ธ์„ x, y ์ขŒํ‘œ๋กœ ๋‹จ์ผํ™”
1 parent a827ce6 commit f2eca7c

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

โ€Žapps/editor/src/widgets/right-sidebar/ui/sections/PositionSection.tsxโ€Ž

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { WcxNode } from "@repo/ui/types/nodes";
4-
import { useUpdateNode } from "@/stores/useEditorStore";
4+
import { useUpdateNode, useUpdateNodeLayout } from "@/stores/useEditorStore";
55
import FieldRow from "../atoms/FieldRow";
66
import NumberInput from "../atoms/NumberInput";
77
import SelectInput from "../atoms/SelectInput";
@@ -14,14 +14,20 @@ type PositionType = "relative" | "absolute" | "fixed" | "sticky";
1414

1515
export default function PositionSection({ node }: PositionSectionProps) {
1616
const updateNode = useUpdateNode();
17+
const updateNodeLayout = useUpdateNodeLayout();
1718
const positionType = (node.style.position as PositionType) || "relative";
1819

1920
const handleStyleChange = (key: string, value: any) => {
2021
updateNode(node.id, { style: { ...node.style, [key]: value } });
2122
};
2223

24+
const handleLayoutChange = (key: string, value: any) => {
25+
updateNodeLayout(node.id, { [key]: value });
26+
};
27+
2328
const handlePositionTypeChange = (type: PositionType) => {
2429
if (type === "relative") {
30+
// relative ์ „ํ™˜ ์‹œ ์Šคํƒ€์ผ์—์„œ ์œ„์น˜ ์ •๋ณด ์ œ๊ฑฐ
2531
updateNode(node.id, {
2632
style: {
2733
...node.style,
@@ -32,6 +38,7 @@ export default function PositionSection({ node }: PositionSectionProps) {
3238
left: undefined,
3339
},
3440
});
41+
// x, y ์ขŒํ‘œ๋Š” ์œ ์ง€ํ•˜๊ฑฐ๋‚˜ ํ•„์š”์— ๋”ฐ๋ผ ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ์ผ๋‹จ ์œ ์ง€
3542
} else {
3643
handleStyleChange("position", type);
3744
}
@@ -42,42 +49,30 @@ export default function PositionSection({ node }: PositionSectionProps) {
4249

4350
return (
4451
<>
45-
{/* Absolute / Fixed โ†’ T R B L */}
52+
{/* Absolute / Fixed โ†’ Top(y) / Left(x) (Layout ํ•„๋“œ ์‚ฌ์šฉ) */}
4653
{showOffsets && (
4754
<>
4855
<FieldRow label="Top">
4956
<NumberInput
50-
value={parseInt(String(node.style.top)) || 0}
51-
onChange={(v) => handleStyleChange("top", v)}
52-
/>
53-
</FieldRow>
54-
<FieldRow label="Right">
55-
<NumberInput
56-
value={parseInt(String(node.style.right)) || 0}
57-
onChange={(v) => handleStyleChange("right", v)}
58-
/>
59-
</FieldRow>
60-
<FieldRow label="Bottom">
61-
<NumberInput
62-
value={parseInt(String(node.style.bottom)) || 0}
63-
onChange={(v) => handleStyleChange("bottom", v)}
57+
value={node.layout.y ?? 0}
58+
onChange={(v) => handleLayoutChange("y", v)}
6459
/>
6560
</FieldRow>
6661
<FieldRow label="Left">
6762
<NumberInput
68-
value={parseInt(String(node.style.left)) || 0}
69-
onChange={(v) => handleStyleChange("left", v)}
63+
value={node.layout.x ?? 0}
64+
onChange={(v) => handleLayoutChange("x", v)}
7065
/>
7166
</FieldRow>
7267
</>
7368
)}
7469

75-
{/* Sticky โ†’ Top only */}
70+
{/* Sticky โ†’ Top only (y ์‚ฌ์šฉ) */}
7671
{showStickyTop && (
7772
<FieldRow label="Top">
7873
<NumberInput
79-
value={parseInt(String(node.style.top)) || 0}
80-
onChange={(v) => handleStyleChange("top", v)}
74+
value={node.layout.y ?? 0}
75+
onChange={(v) => handleLayoutChange("y", v)}
8176
/>
8277
</FieldRow>
8378
)}

โ€Žpackages/ui/src/core/EditorNodeWrapper.tsxโ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function EditorNodeWrapper({
3838
};
3939

4040
const { id } = node;
41-
const { width, height, x, y } = node.layout;
41+
const { width, height, x, y, zIndex } = node.layout;
4242
const selectedNodeGuideClasses = {
4343
handle: "bg-white border-2 rounded-full border-rnd-handle !w-2 !h-2 ",
4444
outline: "ring ring-2 ring-rnd-handle",
@@ -50,6 +50,11 @@ export default function EditorNodeWrapper({
5050
<Rnd
5151
size={{ width, height }}
5252
position={{ x, y }}
53+
style={{
54+
...wrapperStyle,
55+
position: node.style.position as any,
56+
zIndex,
57+
}}
5358
scale={canvas.scale}
5459
onDragStart={(e) => e.stopPropagation()}
5560
//TODO-์ผ๋‹จ ์ด๋™์ค‘์— ์Šคํ† ์–ด ์—…๋ฐ์ดํŠธ๋Š” ๋ฏธ๋ฃจ๊ธฐ -> ์„ฑ๋Šฅ ์ด์Šˆ

โ€Žpackages/ui/src/types/nodes.tsโ€Ž

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ export interface BaseNode {
1919
layout: {
2020
x: number;
2121
y: number;
22-
width: number; // ํ˜น์€ string ('100%')
23-
height: number; // ํ˜น์€ string ('auto')
22+
width: number | string; // ์ˆซ์ž(px) ๋˜๋Š” ๋ฌธ์ž์—ด('100%', 'auto')
23+
height: number | string; // ์ˆซ์ž(px) ๋˜๋Š” ๋ฌธ์ž์—ด('100%', 'auto')
24+
widthMode: 'fixed' | 'fill' | 'fit' | 'relative'; // Framer sizing ๋ชจ๋“œ
25+
heightMode: 'fixed' | 'fill' | 'fit' | 'relative'; // Framer sizing ๋ชจ๋“œ
26+
widthUnit: 'px' | '%';
27+
heightUnit: 'px' | '%';
2428
zIndex: number;
2529
};
2630
}

0 commit comments

Comments
ย (0)