Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b781ad1a2f | |||
| adee5c0891 | |||
| dc55449efb | |||
| d21252eb1f |
+463
-40
@@ -1,7 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { CSSProperties } from "react";
|
import type { CSSProperties, ReactNode } from "react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import Link from "next/link";
|
||||||
import {
|
import {
|
||||||
DndContext,
|
DndContext,
|
||||||
PointerSensor,
|
PointerSensor,
|
||||||
@@ -9,6 +10,7 @@ import {
|
|||||||
useSensor,
|
useSensor,
|
||||||
useSensors,
|
useSensors,
|
||||||
DragEndEvent,
|
DragEndEvent,
|
||||||
|
useDroppable,
|
||||||
} from "@dnd-kit/core";
|
} from "@dnd-kit/core";
|
||||||
import {
|
import {
|
||||||
SortableContext,
|
SortableContext,
|
||||||
@@ -17,16 +19,29 @@ import {
|
|||||||
} from "@dnd-kit/sortable";
|
} from "@dnd-kit/sortable";
|
||||||
import { CSS } from "@dnd-kit/utilities";
|
import { CSS } from "@dnd-kit/utilities";
|
||||||
import { useEditorStore } from "@/features/editor/state/editorStore";
|
import { useEditorStore } from "@/features/editor/state/editorStore";
|
||||||
import type { Block } from "@/features/editor/state/editorStore";
|
import type {
|
||||||
|
Block,
|
||||||
|
TextBlockProps,
|
||||||
|
ButtonBlockProps,
|
||||||
|
ImageBlockProps,
|
||||||
|
SectionBlockProps,
|
||||||
|
} from "@/features/editor/state/editorStore";
|
||||||
|
|
||||||
export default function EditorPage() {
|
export default function EditorPage() {
|
||||||
const blocks = useEditorStore((state) => state.blocks);
|
const blocks = useEditorStore((state) => state.blocks);
|
||||||
const selectedBlockId = useEditorStore((state) => state.selectedBlockId);
|
const selectedBlockId = useEditorStore((state) => state.selectedBlockId);
|
||||||
const addTextBlock = useEditorStore((state) => state.addTextBlock);
|
const addTextBlock = useEditorStore((state) => state.addTextBlock);
|
||||||
|
const addButtonBlock = useEditorStore((state) => state.addButtonBlock);
|
||||||
|
const addImageBlock = useEditorStore((state) => state.addImageBlock);
|
||||||
|
const addSectionBlock = useEditorStore((state) => state.addSectionBlock);
|
||||||
|
const addHeroTemplateSection = useEditorStore((state) => state.addHeroTemplateSection);
|
||||||
|
const addFeaturesTemplateSection = useEditorStore((state) => state.addFeaturesTemplateSection);
|
||||||
|
const addCtaTemplateSection = useEditorStore((state) => state.addCtaTemplateSection);
|
||||||
const updateBlock = useEditorStore((state) => state.updateBlock);
|
const updateBlock = useEditorStore((state) => state.updateBlock);
|
||||||
const selectBlock = useEditorStore((state) => state.selectBlock);
|
const selectBlock = useEditorStore((state) => state.selectBlock);
|
||||||
const replaceBlocks = useEditorStore((state) => state.replaceBlocks);
|
const replaceBlocks = useEditorStore((state) => state.replaceBlocks);
|
||||||
const reorderBlocks = useEditorStore((state) => state.reorderBlocks);
|
const reorderBlocks = useEditorStore((state) => state.reorderBlocks);
|
||||||
|
const moveBlock = useEditorStore((state) => state.moveBlock);
|
||||||
|
|
||||||
const [editingBlockId, setEditingBlockId] = useState<string | null>(null);
|
const [editingBlockId, setEditingBlockId] = useState<string | null>(null);
|
||||||
const [editingText, setEditingText] = useState("");
|
const [editingText, setEditingText] = useState("");
|
||||||
@@ -147,14 +162,77 @@ export default function EditorPage() {
|
|||||||
const handleDragEnd = (event: DragEndEvent) => {
|
const handleDragEnd = (event: DragEndEvent) => {
|
||||||
const { active, over } = event;
|
const { active, over } = event;
|
||||||
if (!over || active.id === over.id) return;
|
if (!over || active.id === over.id) return;
|
||||||
reorderBlocks(String(active.id), String(over.id));
|
const activeId = String(active.id);
|
||||||
|
const overId = String(over.id);
|
||||||
|
|
||||||
|
// 컬럼 droppable에 드롭한 경우: 해당 섹션/컬럼으로 이동만 수행한다.
|
||||||
|
if (overId.startsWith("column:")) {
|
||||||
|
const [, sectionId, columnId] = overId.split(":");
|
||||||
|
moveBlock(activeId, sectionId || null, columnId || null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeBlock = blocks.find((b) => b.id === activeId);
|
||||||
|
const overBlock = blocks.find((b) => b.id === overId);
|
||||||
|
|
||||||
|
if (!activeBlock || !overBlock) {
|
||||||
|
reorderBlocks(activeId, overId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const activeSectionId = activeBlock.sectionId ?? null;
|
||||||
|
const activeColumnId = activeBlock.columnId ?? null;
|
||||||
|
const overSectionId = overBlock.sectionId ?? null;
|
||||||
|
const overColumnId = overBlock.columnId ?? null;
|
||||||
|
|
||||||
|
// 같은 섹션/컬럼 내에서는 순서만 변경한다.
|
||||||
|
if (activeSectionId === overSectionId && activeColumnId === overColumnId) {
|
||||||
|
reorderBlocks(activeId, overId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 다른 컬럼/섹션으로 이동: 위치를 변경한 뒤, 블록 기준 드롭이면 순서 재배치까지 진행한다.
|
||||||
|
moveBlock(activeId, overSectionId, overColumnId);
|
||||||
|
reorderBlocks(activeId, overId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const rootBlocks = blocks.filter((block) => !block.sectionId);
|
||||||
|
|
||||||
|
const renderBlocks = (targetBlocks: Block[]) =>
|
||||||
|
targetBlocks.map((block) => {
|
||||||
|
const isSelected = block.id === selectedBlockId;
|
||||||
|
const isEditing = block.id === editingBlockId;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SortableEditorBlock
|
||||||
|
key={block.id}
|
||||||
|
block={block}
|
||||||
|
isSelected={isSelected}
|
||||||
|
isEditing={isEditing}
|
||||||
|
editingText={editingText}
|
||||||
|
startEditing={startEditing}
|
||||||
|
commitEditing={commitEditing}
|
||||||
|
setEditingText={setEditingText}
|
||||||
|
selectBlock={selectBlock}
|
||||||
|
allBlocks={blocks}
|
||||||
|
renderBlocks={renderBlocks}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen flex flex-col bg-slate-950 text-slate-50">
|
<main className="min-h-screen flex flex-col bg-slate-950 text-slate-50">
|
||||||
<header className="border-b border-slate-800 px-6 py-4 flex items-center justify-between">
|
<header className="border-b border-slate-800 px-6 py-4 flex items-center justify-between">
|
||||||
|
<div className="flex items-baseline gap-3">
|
||||||
<h1 className="text-xl font-semibold">Page Editor</h1>
|
<h1 className="text-xl font-semibold">Page Editor</h1>
|
||||||
<p className="text-xs text-slate-400">빌더 MVP용 에디터 페이지 골격</p>
|
<p className="text-xs text-slate-400">빌더 MVP용 에디터 페이지 골격</p>
|
||||||
|
</div>
|
||||||
|
<Link
|
||||||
|
href="/preview"
|
||||||
|
className="inline-flex items-center rounded border border-slate-700 bg-slate-900 px-3 py-1 text-xs text-slate-100 hover:bg-slate-800"
|
||||||
|
>
|
||||||
|
프리뷰 열기
|
||||||
|
</Link>
|
||||||
</header>
|
</header>
|
||||||
<section className="flex flex-1 overflow-hidden">
|
<section className="flex flex-1 overflow-hidden">
|
||||||
<aside className="w-60 border-r border-slate-800 p-4 text-sm space-y-3">
|
<aside className="w-60 border-r border-slate-800 p-4 text-sm space-y-3">
|
||||||
@@ -166,6 +244,51 @@ export default function EditorPage() {
|
|||||||
>
|
>
|
||||||
텍스트 블록 추가
|
텍스트 블록 추가
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-3 py-2 text-left text-xs hover:bg-slate-800"
|
||||||
|
onClick={addButtonBlock}
|
||||||
|
>
|
||||||
|
버튼 블록 추가
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-3 py-2 text-left text-xs hover:bg-slate-800"
|
||||||
|
onClick={addImageBlock}
|
||||||
|
>
|
||||||
|
이미지 블록 추가
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-3 py-2 text-left text-xs hover:bg-slate-800"
|
||||||
|
onClick={addSectionBlock}
|
||||||
|
>
|
||||||
|
섹션 블록 추가
|
||||||
|
</button>
|
||||||
|
<div className="pt-3 border-t border-slate-800 mt-3 space-y-2">
|
||||||
|
<h3 className="text-[11px] font-medium text-slate-300">템플릿</h3>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="w-full rounded border border-sky-700 bg-sky-950 px-3 py-2 text-left text-xs text-sky-100 hover:bg-sky-900"
|
||||||
|
onClick={addHeroTemplateSection}
|
||||||
|
>
|
||||||
|
Hero 템플릿 추가
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-3 py-2 text-left text-xs hover:bg-slate-800"
|
||||||
|
onClick={addFeaturesTemplateSection}
|
||||||
|
>
|
||||||
|
Features 템플릿 추가
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-3 py-2 text-left text-xs hover:bg-slate-800"
|
||||||
|
onClick={addCtaTemplateSection}
|
||||||
|
>
|
||||||
|
CTA 템플릿 추가
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<p className="text-xs text-slate-500">
|
<p className="text-xs text-slate-500">
|
||||||
Text / Image / Button / Section 블록을 이 영역에서 추가할 수 있습니다.
|
Text / Image / Button / Section 블록을 이 영역에서 추가할 수 있습니다.
|
||||||
</p>
|
</p>
|
||||||
@@ -188,24 +311,7 @@ export default function EditorPage() {
|
|||||||
items={blocks.map((b) => b.id)}
|
items={blocks.map((b) => b.id)}
|
||||||
strategy={verticalListSortingStrategy}
|
strategy={verticalListSortingStrategy}
|
||||||
>
|
>
|
||||||
{blocks.map((block) => {
|
{renderBlocks(rootBlocks)}
|
||||||
const isSelected = block.id === selectedBlockId;
|
|
||||||
const isEditing = block.id === editingBlockId;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SortableEditorBlock
|
|
||||||
key={block.id}
|
|
||||||
block={block}
|
|
||||||
isSelected={isSelected}
|
|
||||||
isEditing={isEditing}
|
|
||||||
editingText={editingText}
|
|
||||||
startEditing={startEditing}
|
|
||||||
commitEditing={commitEditing}
|
|
||||||
setEditingText={setEditingText}
|
|
||||||
selectBlock={selectBlock}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</SortableContext>
|
</SortableContext>
|
||||||
</DndContext>
|
</DndContext>
|
||||||
)}
|
)}
|
||||||
@@ -214,18 +320,24 @@ export default function EditorPage() {
|
|||||||
<h2 className="font-medium mb-2">속성 패널</h2>
|
<h2 className="font-medium mb-2">속성 패널</h2>
|
||||||
{selectedBlockId ? (
|
{selectedBlockId ? (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
|
{(() => {
|
||||||
|
const selectedBlock = blocks.find((b) => b.id === selectedBlockId);
|
||||||
|
if (!selectedBlock) return null;
|
||||||
|
|
||||||
|
if (selectedBlock.type === "text") {
|
||||||
|
const textProps = selectedBlock.props as TextBlockProps;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<p className="text-xs text-slate-400">선택한 텍스트 블록 내용</p>
|
<p className="text-xs text-slate-400">선택한 텍스트 블록 내용</p>
|
||||||
<textarea
|
<textarea
|
||||||
className="w-full min-h-[80px] rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
className="w-full min-h-[80px] rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
aria-label="선택한 텍스트 블록 내용"
|
aria-label="선택한 텍스트 블록 내용"
|
||||||
value={
|
value={textProps.text}
|
||||||
blocks.find((b) => b.id === selectedBlockId)?.props.text ?? ""
|
|
||||||
}
|
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = e.target.value;
|
const value = e.target.value;
|
||||||
updateBlock(selectedBlockId, { text: value });
|
updateBlock(selectedBlockId, { text: value });
|
||||||
// 인라인 편집과의 상태 차이를 막기 위해, 현재 인라인 편집 중인 블록이라면 로컬 상태도 동기화한다.
|
|
||||||
if (editingBlockId === selectedBlockId) {
|
if (editingBlockId === selectedBlockId) {
|
||||||
setEditingText(value);
|
setEditingText(value);
|
||||||
}
|
}
|
||||||
@@ -239,9 +351,7 @@ export default function EditorPage() {
|
|||||||
<select
|
<select
|
||||||
className="rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
className="rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
aria-label="정렬"
|
aria-label="정렬"
|
||||||
value={
|
value={textProps.align}
|
||||||
blocks.find((b) => b.id === selectedBlockId)?.props.align ?? "left"
|
|
||||||
}
|
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = e.target.value as "left" | "center" | "right";
|
const value = e.target.value as "left" | "center" | "right";
|
||||||
updateBlock(selectedBlockId, { align: value });
|
updateBlock(selectedBlockId, { align: value });
|
||||||
@@ -260,9 +370,7 @@ export default function EditorPage() {
|
|||||||
<select
|
<select
|
||||||
className="rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
className="rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
aria-label="글자 크기"
|
aria-label="글자 크기"
|
||||||
value={
|
value={textProps.size}
|
||||||
blocks.find((b) => b.id === selectedBlockId)?.props.size ?? "base"
|
|
||||||
}
|
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const value = e.target.value as "sm" | "base" | "lg";
|
const value = e.target.value as "sm" | "base" | "lg";
|
||||||
updateBlock(selectedBlockId, { size: value });
|
updateBlock(selectedBlockId, { size: value });
|
||||||
@@ -274,6 +382,176 @@ export default function EditorPage() {
|
|||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedBlock.type === "image") {
|
||||||
|
const imageProps = selectedBlock.props as ImageBlockProps;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
||||||
|
<span>이미지 URL</span>
|
||||||
|
<input
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="이미지 URL"
|
||||||
|
value={imageProps.src}
|
||||||
|
onChange={(e) => {
|
||||||
|
updateBlock(selectedBlockId, { src: e.target.value } as any);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
||||||
|
<span>대체 텍스트</span>
|
||||||
|
<input
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="대체 텍스트"
|
||||||
|
value={imageProps.alt}
|
||||||
|
onChange={(e) => {
|
||||||
|
updateBlock(selectedBlockId, { alt: e.target.value } as any);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedBlock.type === "section") {
|
||||||
|
const sectionProps = selectedBlock.props as SectionBlockProps;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
||||||
|
<span>레이아웃</span>
|
||||||
|
<select
|
||||||
|
className="rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="섹션 레이아웃"
|
||||||
|
value={(() => {
|
||||||
|
const cols = sectionProps.columns ?? [];
|
||||||
|
if (cols.length === 1 && cols[0].span === 12) return "1col";
|
||||||
|
if (cols.length === 2 && cols[0].span === 6 && cols[1].span === 6) return "2col";
|
||||||
|
if (
|
||||||
|
cols.length === 3 &&
|
||||||
|
cols[0].span === 4 &&
|
||||||
|
cols[1].span === 4 &&
|
||||||
|
cols[2].span === 4
|
||||||
|
)
|
||||||
|
return "3col";
|
||||||
|
return "custom";
|
||||||
|
})()}
|
||||||
|
onChange={(e) => {
|
||||||
|
const preset = e.target.value;
|
||||||
|
if (preset === "custom") return;
|
||||||
|
|
||||||
|
const cols =
|
||||||
|
preset === "1col"
|
||||||
|
? [{ id: `${selectedBlock.id}_col_1`, span: 12 }]
|
||||||
|
: preset === "2col"
|
||||||
|
? [
|
||||||
|
{ id: `${selectedBlock.id}_col_1`, span: 6 },
|
||||||
|
{ id: `${selectedBlock.id}_col_2`, span: 6 },
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
{ id: `${selectedBlock.id}_col_1`, span: 4 },
|
||||||
|
{ id: `${selectedBlock.id}_col_2`, span: 4 },
|
||||||
|
{ id: `${selectedBlock.id}_col_3`, span: 4 },
|
||||||
|
];
|
||||||
|
|
||||||
|
updateBlock(selectedBlockId, { columns: cols } as any);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="1col">1열 (100%)</option>
|
||||||
|
<option value="2col">2열 (50 / 50)</option>
|
||||||
|
<option value="3col">3열 (33 / 33 / 33)</option>
|
||||||
|
<option value="custom" disabled>
|
||||||
|
사용자 정의
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
||||||
|
<span>배경색</span>
|
||||||
|
<select
|
||||||
|
className="rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="섹션 배경색"
|
||||||
|
value={sectionProps.background}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value as SectionBlockProps["background"];
|
||||||
|
updateBlock(selectedBlockId, { background: value } as any);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="default">기본</option>
|
||||||
|
<option value="muted">Muted</option>
|
||||||
|
<option value="primary">Primary</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
||||||
|
<span>세로 패딩</span>
|
||||||
|
<select
|
||||||
|
className="rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="섹션 세로 패딩"
|
||||||
|
value={sectionProps.paddingY}
|
||||||
|
onChange={(e) => {
|
||||||
|
const value = e.target.value as SectionBlockProps["paddingY"];
|
||||||
|
updateBlock(selectedBlockId, { paddingY: value } as any);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="sm">작게</option>
|
||||||
|
<option value="md">보통</option>
|
||||||
|
<option value="lg">크게</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedBlock.type === "button") {
|
||||||
|
const buttonProps = selectedBlock.props as ButtonBlockProps;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
||||||
|
<span>버튼 텍스트</span>
|
||||||
|
<input
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="버튼 텍스트"
|
||||||
|
value={buttonProps.label}
|
||||||
|
onChange={(e) => {
|
||||||
|
updateBlock(selectedBlockId, { label: e.target.value } as any);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-1">
|
||||||
|
<label className="flex flex-col gap-1 text-xs text-slate-400">
|
||||||
|
<span>버튼 링크</span>
|
||||||
|
<input
|
||||||
|
className="w-full rounded border border-slate-700 bg-slate-900 px-2 py-1 text-xs outline-none focus:border-sky-500"
|
||||||
|
aria-label="버튼 링크"
|
||||||
|
value={buttonProps.href}
|
||||||
|
onChange={(e) => {
|
||||||
|
updateBlock(selectedBlockId, { href: e.target.value } as any);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
})()}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-xs text-slate-500">
|
<p className="text-xs text-slate-500">
|
||||||
@@ -395,6 +673,8 @@ interface SortableEditorBlockProps {
|
|||||||
commitEditing: () => void;
|
commitEditing: () => void;
|
||||||
setEditingText: (value: string) => void;
|
setEditingText: (value: string) => void;
|
||||||
selectBlock: (id: string) => void;
|
selectBlock: (id: string) => void;
|
||||||
|
allBlocks: Block[];
|
||||||
|
renderBlocks: (targetBlocks: Block[]) => ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SortableEditorBlock({
|
function SortableEditorBlock({
|
||||||
@@ -406,6 +686,8 @@ function SortableEditorBlock({
|
|||||||
commitEditing,
|
commitEditing,
|
||||||
setEditingText,
|
setEditingText,
|
||||||
selectBlock,
|
selectBlock,
|
||||||
|
allBlocks,
|
||||||
|
renderBlocks,
|
||||||
}: SortableEditorBlockProps) {
|
}: SortableEditorBlockProps) {
|
||||||
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
|
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
|
||||||
id: block.id,
|
id: block.id,
|
||||||
@@ -416,19 +698,36 @@ function SortableEditorBlock({
|
|||||||
transition,
|
transition,
|
||||||
};
|
};
|
||||||
|
|
||||||
const alignClass =
|
let alignClass = "";
|
||||||
block.props.align === "center"
|
let sizeClass = "";
|
||||||
|
|
||||||
|
if (block.type === "text") {
|
||||||
|
const textProps = block.props as TextBlockProps;
|
||||||
|
alignClass =
|
||||||
|
textProps.align === "center"
|
||||||
? "text-center"
|
? "text-center"
|
||||||
: block.props.align === "right"
|
: textProps.align === "right"
|
||||||
? "text-right"
|
? "text-right"
|
||||||
: "text-left";
|
: "text-left";
|
||||||
|
|
||||||
const sizeClass =
|
sizeClass =
|
||||||
block.props.size === "sm"
|
textProps.size === "sm"
|
||||||
? "text-sm"
|
? "text-sm"
|
||||||
: block.props.size === "lg"
|
: textProps.size === "lg"
|
||||||
? "text-lg"
|
? "text-lg"
|
||||||
: "text-base";
|
: "text-base";
|
||||||
|
} else if (block.type === "button") {
|
||||||
|
// 버튼 블록은 기본 텍스트 스타일만 적용
|
||||||
|
alignClass = "text-left";
|
||||||
|
sizeClass = "text-base";
|
||||||
|
} else if (block.type === "image") {
|
||||||
|
alignClass = "text-left";
|
||||||
|
sizeClass = "text-base";
|
||||||
|
} else {
|
||||||
|
// 섹션 블록: 텍스트 크기 대신 섹션 자체에 패딩/배경을 입히므로 텍스트 클래스는 기본값만
|
||||||
|
alignClass = "text-left";
|
||||||
|
sizeClass = "text-base";
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -441,7 +740,12 @@ function SortableEditorBlock({
|
|||||||
isSelected ? "border-sky-500 bg-slate-900/80" : "border-slate-700 bg-slate-900"
|
isSelected ? "border-sky-500 bg-slate-900/80" : "border-slate-700 bg-slate-900"
|
||||||
}`}
|
}`}
|
||||||
onClick={() => selectBlock(block.id)}
|
onClick={() => selectBlock(block.id)}
|
||||||
onDoubleClick={() => startEditing(block.id, block.props.text)}
|
onDoubleClick={() => {
|
||||||
|
if (block.type === "text") {
|
||||||
|
const textProps = block.props as TextBlockProps;
|
||||||
|
startEditing(block.id, textProps.text);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="flex items-start gap-2">
|
<div className="flex items-start gap-2">
|
||||||
<button
|
<button
|
||||||
@@ -454,7 +758,8 @@ function SortableEditorBlock({
|
|||||||
≡
|
≡
|
||||||
</button>
|
</button>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
{isEditing ? (
|
{block.type === "text" && (
|
||||||
|
isEditing ? (
|
||||||
<textarea
|
<textarea
|
||||||
className="w-full bg-transparent outline-none resize-none text-sm"
|
className="w-full bg-transparent outline-none resize-none text-sm"
|
||||||
aria-label="텍스트 블록 내용 편집"
|
aria-label="텍스트 블록 내용 편집"
|
||||||
@@ -471,10 +776,128 @@ function SortableEditorBlock({
|
|||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div>{block.props.text}</div>
|
<div>{(block.props as TextBlockProps).text}</div>
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
|
{block.type === "button" && (() => {
|
||||||
|
const buttonProps = block.props as ButtonBlockProps;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="inline-flex items-center justify-center rounded border border-slate-600 bg-slate-800 px-3 py-1 text-xs font-medium text-slate-50 hover:bg-slate-700"
|
||||||
|
aria-label={buttonProps.label}
|
||||||
|
onClick={(e) => {
|
||||||
|
// 에디터 내 버튼 클릭은 선택만 유지하고 실제 이동은 막는다.
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{buttonProps.label}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
{block.type === "image" && (() => {
|
||||||
|
const imageProps = block.props as ImageBlockProps;
|
||||||
|
const hasSrc = imageProps.src.trim().length > 0;
|
||||||
|
return (
|
||||||
|
<div className="w-full border border-dashed border-slate-700 bg-slate-900/40 rounded flex items-center justify-center overflow-hidden">
|
||||||
|
{hasSrc ? (
|
||||||
|
// eslint-disable-next-line @next/next/no-img-element
|
||||||
|
<img
|
||||||
|
src={imageProps.src}
|
||||||
|
alt={imageProps.alt}
|
||||||
|
className="max-w-full h-auto object-contain"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="text-[10px] text-slate-500 px-2 py-4">
|
||||||
|
이미지 URL을 속성 패널에서 입력하세요.
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
{block.type === "section" && (() => {
|
||||||
|
const sectionProps = block.props as SectionBlockProps;
|
||||||
|
|
||||||
|
const bgClass =
|
||||||
|
sectionProps.background === "muted"
|
||||||
|
? "bg-slate-950/40"
|
||||||
|
: sectionProps.background === "primary"
|
||||||
|
? "bg-sky-950/40 border-sky-900/60"
|
||||||
|
: "bg-slate-900/60";
|
||||||
|
|
||||||
|
const pyClass =
|
||||||
|
sectionProps.paddingY === "sm"
|
||||||
|
? "py-4"
|
||||||
|
: sectionProps.paddingY === "lg"
|
||||||
|
? "py-10"
|
||||||
|
: "py-6";
|
||||||
|
|
||||||
|
const columns = sectionProps.columns && sectionProps.columns.length > 0
|
||||||
|
? sectionProps.columns
|
||||||
|
: [{ id: `${block.id}_col_fallback`, span: 12 }];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`w-full ${bgClass} ${pyClass} rounded border border-dashed border-slate-700`}
|
||||||
|
>
|
||||||
|
<div className="flex gap-3">
|
||||||
|
{columns.map((col) => {
|
||||||
|
const basis = `${(col.span / 12) * 100}%`;
|
||||||
|
const columnBlocks = allBlocks.filter(
|
||||||
|
(b) => b.sectionId === block.id && b.columnId === col.id,
|
||||||
|
);
|
||||||
|
const droppableId = `column:${block.id}:${col.id}`;
|
||||||
|
return (
|
||||||
|
<ColumnDroppable
|
||||||
|
key={col.id}
|
||||||
|
id={droppableId}
|
||||||
|
sectionId={block.id}
|
||||||
|
columnId={col.id}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="border border-slate-800/80 bg-slate-950/40 rounded flex flex-col gap-2 items-stretch justify-start px-2 py-2"
|
||||||
|
style={{ flexBasis: basis }}
|
||||||
|
>
|
||||||
|
{columnBlocks.length === 0 ? (
|
||||||
|
<span className="text-[11px] text-slate-500 px-2 text-center">
|
||||||
|
컬럼 영역 (span {col.span}/12)
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
{renderBlocks(columnBlocks)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</ColumnDroppable>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ColumnDroppableProps {
|
||||||
|
id: string;
|
||||||
|
sectionId: string;
|
||||||
|
columnId: string;
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ColumnDroppable({ id, sectionId, columnId, children }: ColumnDroppableProps) {
|
||||||
|
const { setNodeRef } = useDroppable({ id });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={setNodeRef}
|
||||||
|
data-section-id={sectionId}
|
||||||
|
data-column-id={columnId}
|
||||||
|
className="flex-1"
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEditorStore } from "@/features/editor/state/editorStore";
|
||||||
|
import { PublicPageRenderer } from "@/features/editor/components/PublicPageRenderer";
|
||||||
|
|
||||||
|
export default function PreviewPage() {
|
||||||
|
const blocks = useEditorStore((state) => state.blocks);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="min-h-screen flex flex-col bg-slate-950 text-slate-50">
|
||||||
|
<header className="border-b border-slate-800 px-6 py-4 flex items-center justify-between">
|
||||||
|
<h1 className="text-xl font-semibold">Page Preview</h1>
|
||||||
|
<p className="text-xs text-slate-400">빌더로 만든 페이지를 미리 보는 화면</p>
|
||||||
|
</header>
|
||||||
|
{/* 에디터 크롬 없이 순수 페이지 형태로 블록들을 렌더링 */}
|
||||||
|
<PublicPageRenderer blocks={blocks} />
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import type { Block, TextBlockProps, ButtonBlockProps, ImageBlockProps, SectionBlockProps } from "@/features/editor/state/editorStore";
|
||||||
|
|
||||||
|
// 에디터 크롬 없이 실제 랜딩 페이지처럼 블록들을 렌더링하는 컴포넌트
|
||||||
|
interface PublicPageRendererProps {
|
||||||
|
blocks: Block[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PublicPageRenderer({ blocks }: PublicPageRendererProps) {
|
||||||
|
const sectionBlocks = blocks.filter((b) => b.type === "section");
|
||||||
|
const rootBlocks = blocks.filter((b) => !b.sectionId && b.type !== "section");
|
||||||
|
|
||||||
|
const renderBlock = (block: Block) => {
|
||||||
|
if (block.type === "text") {
|
||||||
|
const props = block.props as TextBlockProps;
|
||||||
|
|
||||||
|
const alignClass =
|
||||||
|
props.align === "center" ? "text-center" : props.align === "right" ? "text-right" : "text-left";
|
||||||
|
const sizeClass = props.size === "sm" ? "text-sm" : props.size === "lg" ? "text-2xl" : "text-base";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<p key={block.id} className={`${alignClass} ${sizeClass} text-slate-50 leading-relaxed`}>
|
||||||
|
{props.text}
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block.type === "button") {
|
||||||
|
const props = block.props as ButtonBlockProps;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
key={block.id}
|
||||||
|
href={props.href}
|
||||||
|
className="inline-flex items-center justify-center rounded-md bg-sky-600 px-4 py-2 text-sm font-medium text-white hover:bg-sky-500 transition-colors"
|
||||||
|
>
|
||||||
|
{props.label}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (block.type === "image") {
|
||||||
|
const props = block.props as ImageBlockProps;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={block.id} className="w-full flex justify-center">
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img src={props.src || ""} alt={props.alt} className="max-w-full h-auto object-contain" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderSection = (section: Block) => {
|
||||||
|
const props = section.props as SectionBlockProps;
|
||||||
|
|
||||||
|
const bgClass =
|
||||||
|
props.background === "muted" ? "bg-slate-900" : props.background === "primary" ? "bg-sky-900" : "bg-slate-950";
|
||||||
|
|
||||||
|
const pyClass = props.paddingY === "sm" ? "py-8" : props.paddingY === "lg" ? "py-20" : "py-12";
|
||||||
|
|
||||||
|
const columns = props.columns && props.columns.length > 0 ? props.columns : [{ id: `${section.id}_col`, span: 12 }];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section key={section.id} className={`${bgClass} ${pyClass}`}>
|
||||||
|
<div className="mx-auto max-w-5xl px-4">
|
||||||
|
<div className="flex gap-8">
|
||||||
|
{columns.map((col) => {
|
||||||
|
const basis = `${(col.span / 12) * 100}%`;
|
||||||
|
const columnBlocks = blocks.filter((b) => b.sectionId === section.id && b.columnId === col.id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={col.id} className="flex flex-col gap-4" style={{ flexBasis: basis }}>
|
||||||
|
{columnBlocks.map((b) => (
|
||||||
|
<div key={b.id}>{renderBlock(b)}</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex-1 flex flex-col bg-slate-950 text-slate-50">
|
||||||
|
{/* 루트 텍스트/버튼/이미지 블록들이 있다면 페이지 상단에 노출 */}
|
||||||
|
{rootBlocks.length > 0 && (
|
||||||
|
<section className="bg-slate-950 py-12">
|
||||||
|
<div className="mx-auto max-w-3xl px-4 flex flex-col gap-4">
|
||||||
|
{rootBlocks.map((b) => (
|
||||||
|
<div key={b.id}>{renderBlock(b)}</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 섹션 블록들 */}
|
||||||
|
{sectionBlocks.map((section) => renderSection(section))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { createStore } from "zustand";
|
import { createStore } from "zustand";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
// 블록 타입 정의: 1단계에서는 텍스트 블록만 사용
|
// 블록 타입 정의: 텍스트/버튼/이미지/섹션 블록
|
||||||
export type BlockType = "text"; // 이후 image/button/section 으로 확장 예정
|
export type BlockType = "text" | "button" | "image" | "section";
|
||||||
|
|
||||||
// 텍스트 블록 속성
|
// 텍스트 블록 속성
|
||||||
export interface TextBlockProps {
|
export interface TextBlockProps {
|
||||||
@@ -13,11 +13,38 @@ export interface TextBlockProps {
|
|||||||
size: "sm" | "base" | "lg";
|
size: "sm" | "base" | "lg";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 버튼 블록 속성
|
||||||
|
export interface ButtonBlockProps {
|
||||||
|
label: string;
|
||||||
|
href: string;
|
||||||
|
// TODO: variant, size 등은 추후 확장
|
||||||
|
}
|
||||||
|
|
||||||
|
// 이미지 블록 속성
|
||||||
|
export interface ImageBlockProps {
|
||||||
|
src: string;
|
||||||
|
alt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 섹션 블록 속성
|
||||||
|
export interface SectionBlockProps {
|
||||||
|
background: "default" | "muted" | "primary";
|
||||||
|
paddingY: "sm" | "md" | "lg";
|
||||||
|
// 레이아웃 컬럼 정의 (12 그리드 기준 span)
|
||||||
|
columns: Array<{
|
||||||
|
id: string;
|
||||||
|
span: number;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
// 공통 블록 모델
|
// 공통 블록 모델
|
||||||
export interface Block {
|
export interface Block {
|
||||||
id: string;
|
id: string;
|
||||||
type: BlockType;
|
type: BlockType;
|
||||||
props: TextBlockProps;
|
props: TextBlockProps | ButtonBlockProps | ImageBlockProps | SectionBlockProps;
|
||||||
|
// 레이아웃 트리 상 위치 정보 (루트 텍스트/버튼/이미지 블록은 null)
|
||||||
|
sectionId?: string | null;
|
||||||
|
columnId?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 에디터 상태 인터페이스
|
// 에디터 상태 인터페이스
|
||||||
@@ -25,10 +52,17 @@ export interface EditorState {
|
|||||||
blocks: Block[];
|
blocks: Block[];
|
||||||
selectedBlockId: string | null;
|
selectedBlockId: string | null;
|
||||||
addTextBlock: () => void;
|
addTextBlock: () => void;
|
||||||
updateBlock: (id: string, partial: Partial<TextBlockProps>) => void;
|
addButtonBlock: () => void;
|
||||||
|
addImageBlock: () => void;
|
||||||
|
addSectionBlock: () => void;
|
||||||
|
addHeroTemplateSection: () => void;
|
||||||
|
addFeaturesTemplateSection: () => void;
|
||||||
|
addCtaTemplateSection: () => void;
|
||||||
|
updateBlock: (id: string, partial: Partial<TextBlockProps & ButtonBlockProps>) => void;
|
||||||
selectBlock: (id: string | null) => void;
|
selectBlock: (id: string | null) => void;
|
||||||
replaceBlocks: (blocks: Block[]) => void;
|
replaceBlocks: (blocks: Block[]) => void;
|
||||||
reorderBlocks: (activeId: string, overId: string) => void;
|
reorderBlocks: (activeId: string, overId: string) => void;
|
||||||
|
moveBlock: (id: string, sectionId: string | null, columnId: string | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 간단한 ID 생성기 (추후 uuid 라이브러리로 교체 가능)
|
// 간단한 ID 생성기 (추후 uuid 라이브러리로 교체 가능)
|
||||||
@@ -44,6 +78,25 @@ const createEditorState = (set: any, get: any): EditorState => ({
|
|||||||
// 텍스트 블록 추가: 기본 텍스트와 함께 생성 후 선택 상태로 만든다
|
// 텍스트 블록 추가: 기본 텍스트와 함께 생성 후 선택 상태로 만든다
|
||||||
addTextBlock: () => {
|
addTextBlock: () => {
|
||||||
const id = createId();
|
const id = createId();
|
||||||
|
|
||||||
|
const { selectedBlockId, blocks } = get();
|
||||||
|
let sectionId: string | null = null;
|
||||||
|
let columnId: string | null = null;
|
||||||
|
|
||||||
|
if (selectedBlockId) {
|
||||||
|
const target = blocks.find((b: Block) => b.id === selectedBlockId);
|
||||||
|
if (target) {
|
||||||
|
if (target.type === "section") {
|
||||||
|
const sProps = target.props as SectionBlockProps;
|
||||||
|
sectionId = target.id;
|
||||||
|
columnId = sProps.columns?.[0]?.id ?? null;
|
||||||
|
} else {
|
||||||
|
sectionId = (target as any).sectionId ?? null;
|
||||||
|
columnId = (target as any).columnId ?? null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const newBlock: Block = {
|
const newBlock: Block = {
|
||||||
id,
|
id,
|
||||||
type: "text",
|
type: "text",
|
||||||
@@ -52,6 +105,8 @@ const createEditorState = (set: any, get: any): EditorState => ({
|
|||||||
align: "left",
|
align: "left",
|
||||||
size: "base",
|
size: "base",
|
||||||
},
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId,
|
||||||
};
|
};
|
||||||
|
|
||||||
set((state: EditorState) => ({
|
set((state: EditorState) => ({
|
||||||
@@ -60,7 +115,308 @@ const createEditorState = (set: any, get: any): EditorState => ({
|
|||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
// 특정 블록의 텍스트 속성을 부분 업데이트
|
// Hero 템플릿 섹션 추가: 섹션 1개와 기본 텍스트/버튼 블록들을 첫 컬럼에 배치한다
|
||||||
|
addHeroTemplateSection: () => {
|
||||||
|
const sectionId = createId();
|
||||||
|
|
||||||
|
// Hero 템플릿용 섹션: 기본 배경/패딩 + 1컬럼(12)
|
||||||
|
const sectionBlock: Block = {
|
||||||
|
id: sectionId,
|
||||||
|
type: "section",
|
||||||
|
props: {
|
||||||
|
background: "default",
|
||||||
|
paddingY: "lg",
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: `${sectionId}_col_1`,
|
||||||
|
span: 12,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sectionId: null,
|
||||||
|
columnId: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const firstColumnId = `${sectionId}_col_1`;
|
||||||
|
|
||||||
|
// Hero 텍스트 블록 (예: 헤드라인)
|
||||||
|
const heroHeadlineId = createId();
|
||||||
|
const heroHeadline: Block = {
|
||||||
|
id: heroHeadlineId,
|
||||||
|
type: "text",
|
||||||
|
props: {
|
||||||
|
text: "Hero 제목을 여기에 입력하세요",
|
||||||
|
align: "center",
|
||||||
|
size: "lg",
|
||||||
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId: firstColumnId,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Hero 서브텍스트 블록
|
||||||
|
const heroSubId = createId();
|
||||||
|
const heroSub: Block = {
|
||||||
|
id: heroSubId,
|
||||||
|
type: "text",
|
||||||
|
props: {
|
||||||
|
text: "제품이나 서비스를 한 문장으로 설명하는 서브텍스트입니다.",
|
||||||
|
align: "center",
|
||||||
|
size: "base",
|
||||||
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId: firstColumnId,
|
||||||
|
};
|
||||||
|
|
||||||
|
// CTA 버튼 블록
|
||||||
|
const heroButtonId = createId();
|
||||||
|
const heroButton: Block = {
|
||||||
|
id: heroButtonId,
|
||||||
|
type: "button",
|
||||||
|
props: {
|
||||||
|
label: "지금 시작하기",
|
||||||
|
href: "#",
|
||||||
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId: firstColumnId,
|
||||||
|
};
|
||||||
|
|
||||||
|
set((state: EditorState) => {
|
||||||
|
const newBlocks = [...state.blocks, sectionBlock, heroHeadline, heroSub, heroButton];
|
||||||
|
|
||||||
|
return {
|
||||||
|
blocks: newBlocks,
|
||||||
|
selectedBlockId: heroButtonId,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// Features 템플릿 섹션 추가: 3컬럼(4/4/4) 섹션과 각 컬럼의 제목/설명 텍스트를 생성한다
|
||||||
|
addFeaturesTemplateSection: () => {
|
||||||
|
const sectionId = createId();
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{ id: `${sectionId}_col_1`, span: 4 },
|
||||||
|
{ id: `${sectionId}_col_2`, span: 4 },
|
||||||
|
{ id: `${sectionId}_col_3`, span: 4 },
|
||||||
|
];
|
||||||
|
|
||||||
|
const sectionBlock: Block = {
|
||||||
|
id: sectionId,
|
||||||
|
type: "section",
|
||||||
|
props: {
|
||||||
|
background: "muted",
|
||||||
|
paddingY: "md",
|
||||||
|
columns,
|
||||||
|
},
|
||||||
|
sectionId: null,
|
||||||
|
columnId: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const featureBlocks: Block[] = columns.flatMap((col, index) => {
|
||||||
|
const titleId = createId();
|
||||||
|
const descId = createId();
|
||||||
|
|
||||||
|
const title: Block = {
|
||||||
|
id: titleId,
|
||||||
|
type: "text",
|
||||||
|
props: {
|
||||||
|
text: `Feature ${index + 1} 제목`,
|
||||||
|
align: "left",
|
||||||
|
size: "lg",
|
||||||
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId: col.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
const description: Block = {
|
||||||
|
id: descId,
|
||||||
|
type: "text",
|
||||||
|
props: {
|
||||||
|
text: "해당 기능을 간단히 설명하는 텍스트입니다.",
|
||||||
|
align: "left",
|
||||||
|
size: "sm",
|
||||||
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId: col.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
return [title, description];
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastBlockId = featureBlocks[featureBlocks.length - 1].id;
|
||||||
|
|
||||||
|
set((state: EditorState) => {
|
||||||
|
const newBlocks = [...state.blocks, sectionBlock, ...featureBlocks];
|
||||||
|
|
||||||
|
return {
|
||||||
|
blocks: newBlocks,
|
||||||
|
selectedBlockId: lastBlockId,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// CTA 템플릿 섹션 추가: 텍스트와 버튼이 포함된 1컬럼 섹션을 생성한다
|
||||||
|
addCtaTemplateSection: () => {
|
||||||
|
const sectionId = createId();
|
||||||
|
|
||||||
|
const sectionBlock: Block = {
|
||||||
|
id: sectionId,
|
||||||
|
type: "section",
|
||||||
|
props: {
|
||||||
|
background: "primary",
|
||||||
|
paddingY: "md",
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: `${sectionId}_col_1`,
|
||||||
|
span: 12,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sectionId: null,
|
||||||
|
columnId: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const firstColumnId = `${sectionId}_col_1`;
|
||||||
|
|
||||||
|
const textId = createId();
|
||||||
|
const textBlock: Block = {
|
||||||
|
id: textId,
|
||||||
|
type: "text",
|
||||||
|
props: {
|
||||||
|
text: "지금 바로 행동을 유도하는 CTA 텍스트를 입력하세요.",
|
||||||
|
align: "center",
|
||||||
|
size: "base",
|
||||||
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId: firstColumnId,
|
||||||
|
};
|
||||||
|
|
||||||
|
const buttonId = createId();
|
||||||
|
const buttonBlock: Block = {
|
||||||
|
id: buttonId,
|
||||||
|
type: "button",
|
||||||
|
props: {
|
||||||
|
label: "CTA 버튼",
|
||||||
|
href: "#",
|
||||||
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId: firstColumnId,
|
||||||
|
};
|
||||||
|
|
||||||
|
set((state: EditorState) => {
|
||||||
|
const newBlocks = [...state.blocks, sectionBlock, textBlock, buttonBlock];
|
||||||
|
|
||||||
|
return {
|
||||||
|
blocks: newBlocks,
|
||||||
|
selectedBlockId: buttonId,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 이미지 블록 추가: 기본 플레이스홀더와 함께 생성 후 선택 상태로 만든다
|
||||||
|
addImageBlock: () => {
|
||||||
|
const id = createId();
|
||||||
|
|
||||||
|
const { selectedBlockId, blocks } = get();
|
||||||
|
let sectionId: string | null = null;
|
||||||
|
let columnId: string | null = null;
|
||||||
|
|
||||||
|
if (selectedBlockId) {
|
||||||
|
const target = blocks.find((b: Block) => b.id === selectedBlockId);
|
||||||
|
if (target) {
|
||||||
|
if (target.type === "section") {
|
||||||
|
const sProps = target.props as SectionBlockProps;
|
||||||
|
sectionId = target.id;
|
||||||
|
columnId = sProps.columns?.[0]?.id ?? null;
|
||||||
|
} else {
|
||||||
|
sectionId = (target as any).sectionId ?? null;
|
||||||
|
columnId = (target as any).columnId ?? null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newBlock: Block = {
|
||||||
|
id,
|
||||||
|
type: "image",
|
||||||
|
props: {
|
||||||
|
src: "",
|
||||||
|
alt: "이미지 설명",
|
||||||
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId,
|
||||||
|
};
|
||||||
|
|
||||||
|
set((state: EditorState) => ({
|
||||||
|
blocks: [...state.blocks, newBlock],
|
||||||
|
selectedBlockId: id,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
|
// 섹션 블록 추가: 배경/패딩 기본값과 함께 생성 후 선택 상태로 만든다
|
||||||
|
addSectionBlock: () => {
|
||||||
|
const id = createId();
|
||||||
|
const newBlock: Block = {
|
||||||
|
id,
|
||||||
|
type: "section",
|
||||||
|
props: {
|
||||||
|
background: "default",
|
||||||
|
paddingY: "md",
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
id: `${id}_col_1`,
|
||||||
|
span: 12,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sectionId: null,
|
||||||
|
columnId: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
set((state: EditorState) => ({
|
||||||
|
blocks: [...state.blocks, newBlock],
|
||||||
|
selectedBlockId: id,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
|
// 버튼 블록 추가: 기본 라벨/링크와 함께 생성 후 선택 상태로 만든다
|
||||||
|
addButtonBlock: () => {
|
||||||
|
const id = createId();
|
||||||
|
|
||||||
|
const { selectedBlockId, blocks } = get();
|
||||||
|
let sectionId: string | null = null;
|
||||||
|
let columnId: string | null = null;
|
||||||
|
|
||||||
|
if (selectedBlockId) {
|
||||||
|
const target = blocks.find((b: Block) => b.id === selectedBlockId);
|
||||||
|
if (target) {
|
||||||
|
if (target.type === "section") {
|
||||||
|
const sProps = target.props as SectionBlockProps;
|
||||||
|
sectionId = target.id;
|
||||||
|
columnId = sProps.columns?.[0]?.id ?? null;
|
||||||
|
} else {
|
||||||
|
sectionId = (target as any).sectionId ?? null;
|
||||||
|
columnId = (target as any).columnId ?? null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const newBlock: Block = {
|
||||||
|
id,
|
||||||
|
type: "button",
|
||||||
|
props: {
|
||||||
|
label: "버튼",
|
||||||
|
href: "#",
|
||||||
|
},
|
||||||
|
sectionId,
|
||||||
|
columnId,
|
||||||
|
};
|
||||||
|
|
||||||
|
set((state: EditorState) => ({
|
||||||
|
blocks: [...state.blocks, newBlock],
|
||||||
|
selectedBlockId: id,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
|
// 특정 블록의 속성을 부분 업데이트 (텍스트/버튼 공통 사용)
|
||||||
updateBlock: (id, partial) => {
|
updateBlock: (id, partial) => {
|
||||||
set((state: EditorState) => ({
|
set((state: EditorState) => ({
|
||||||
blocks: state.blocks.map((block: Block) =>
|
blocks: state.blocks.map((block: Block) =>
|
||||||
@@ -109,6 +465,19 @@ const createEditorState = (set: any, get: any): EditorState => ({
|
|||||||
return { blocks: updated };
|
return { blocks: updated };
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
moveBlock: (id, sectionId, columnId) => {
|
||||||
|
set((state: EditorState) => ({
|
||||||
|
blocks: state.blocks.map((block: Block) =>
|
||||||
|
block.id === id
|
||||||
|
? {
|
||||||
|
...block,
|
||||||
|
sectionId,
|
||||||
|
columnId,
|
||||||
|
}
|
||||||
|
: block,
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// React 컴포넌트에서 사용하는 전역 훅 스토어
|
// React 컴포넌트에서 사용하는 전역 훅 스토어
|
||||||
|
|||||||
@@ -229,3 +229,110 @@ test("블록 드래그앤드롭으로 순서를 변경할 수 있어야 한다",
|
|||||||
await expect(reorderedBlocks.nth(0)).toContainText("블록 B");
|
await expect(reorderedBlocks.nth(0)).toContainText("블록 B");
|
||||||
await expect(reorderedBlocks.nth(1)).toContainText("블록 A");
|
await expect(reorderedBlocks.nth(1)).toContainText("블록 A");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("버튼 블록을 추가하고 라벨과 링크를 수정할 수 있어야 한다", async ({ page }) => {
|
||||||
|
await page.goto("/editor");
|
||||||
|
|
||||||
|
const canvas = page.getByTestId("editor-canvas");
|
||||||
|
|
||||||
|
// 버튼 블록을 추가한다.
|
||||||
|
await page.getByRole("button", { name: "버튼 블록 추가" }).click();
|
||||||
|
|
||||||
|
// 캔버스에 기본 버튼이 렌더되어야 한다.
|
||||||
|
const button = canvas.getByRole("button", { name: "버튼" });
|
||||||
|
await expect(button).toBeVisible();
|
||||||
|
|
||||||
|
// 속성 패널에서 버튼 텍스트와 링크를 수정한다.
|
||||||
|
const labelInput = page.getByRole("textbox", { name: "버튼 텍스트" });
|
||||||
|
const hrefInput = page.getByRole("textbox", { name: "버튼 링크" });
|
||||||
|
|
||||||
|
await labelInput.fill("자세히 보기");
|
||||||
|
await hrefInput.fill("https://example.com");
|
||||||
|
|
||||||
|
// 캔버스의 버튼 텍스트가 변경되어야 한다.
|
||||||
|
const updatedButton = canvas.getByRole("button", { name: "자세히 보기" });
|
||||||
|
await expect(updatedButton).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("2컬럼 섹션에서 블록을 다른 컬럼 영역으로 드래그하면 컬럼이 변경되어야 한다", async ({ page }) => {
|
||||||
|
await page.goto("/editor");
|
||||||
|
|
||||||
|
const canvas = page.getByTestId("editor-canvas");
|
||||||
|
|
||||||
|
// 섹션을 하나 추가하고 레이아웃을 2컬럼으로 변경한다.
|
||||||
|
await page.getByRole("button", { name: "섹션 블록 추가" }).click();
|
||||||
|
|
||||||
|
// 섹션을 선택한다 (캔버스 첫 블록).
|
||||||
|
const sectionBlock = canvas.getByTestId("editor-block").nth(0);
|
||||||
|
await sectionBlock.click();
|
||||||
|
|
||||||
|
const layoutSelect = page.getByRole("combobox", { name: "섹션 레이아웃" });
|
||||||
|
await layoutSelect.selectOption("2col");
|
||||||
|
|
||||||
|
// 왼쪽 컬럼에 텍스트 블록을 하나 추가한다.
|
||||||
|
await page.getByRole("button", { name: "텍스트 블록 추가" }).click();
|
||||||
|
|
||||||
|
const leftColumn = canvas.locator('[data-section-id][data-column-id]').nth(0);
|
||||||
|
const rightColumn = canvas.locator('[data-section-id][data-column-id]').nth(1);
|
||||||
|
|
||||||
|
// 왼쪽 컬럼 안에 텍스트 블록이 존재하는지 확인한다.
|
||||||
|
const leftBlocks = leftColumn.getByTestId("editor-block");
|
||||||
|
await expect(leftBlocks).toHaveCount(1);
|
||||||
|
|
||||||
|
// 왼쪽 컬럼의 첫 블록을 오른쪽 컬럼 droppable 영역으로 드래그한다.
|
||||||
|
const leftBlock = leftBlocks.nth(0);
|
||||||
|
const handle = leftBlock.getByRole("button", { name: "블록 드래그 핸들" });
|
||||||
|
await handle.dragTo(rightColumn);
|
||||||
|
|
||||||
|
// 드래그 이후, 오른쪽 컬럼 안에 블록이 존재해야 하고 왼쪽 컬럼은 비어 있어야 한다.
|
||||||
|
const rightBlocks = rightColumn.getByTestId("editor-block");
|
||||||
|
await expect(rightBlocks).toHaveCount(1);
|
||||||
|
|
||||||
|
// 왼쪽 컬럼에는 더 이상 블록이 없어야 한다.
|
||||||
|
await expect(leftColumn.getByTestId("editor-block")).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Hero 템플릿 버튼을 클릭하면 섹션과 기본 텍스트/버튼 블록이 캔버스에 생성되어야 한다", async ({ page }) => {
|
||||||
|
await page.goto("/editor");
|
||||||
|
|
||||||
|
const canvas = page.getByTestId("editor-canvas");
|
||||||
|
|
||||||
|
// Hero 템플릿을 추가한다.
|
||||||
|
await page.getByRole("button", { name: "Hero 템플릿 추가" }).click();
|
||||||
|
|
||||||
|
// 섹션/블록이 하나 이상 존재해야 한다.
|
||||||
|
const blocks = canvas.getByTestId("editor-block");
|
||||||
|
await expect(blocks.first()).toBeVisible();
|
||||||
|
|
||||||
|
// Hero 헤드라인 텍스트가 포함된 블록이 보여야 한다.
|
||||||
|
await expect(canvas.getByText("Hero 제목을 여기에 입력하세요")).toBeVisible();
|
||||||
|
|
||||||
|
// CTA 버튼도 렌더되어 있어야 한다.
|
||||||
|
const ctaButton = canvas.getByRole("button", { name: "지금 시작하기" });
|
||||||
|
await expect(ctaButton).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Features 템플릿 버튼을 클릭하면 3개의 Feature 항목(제목/설명)이 생성되어야 한다", async ({ page }) => {
|
||||||
|
await page.goto("/editor");
|
||||||
|
|
||||||
|
const canvas = page.getByTestId("editor-canvas");
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Features 템플릿 추가" }).click();
|
||||||
|
|
||||||
|
// Feature 제목들이 렌더되어야 한다.
|
||||||
|
await expect(canvas.getByText("Feature 1 제목")).toBeVisible();
|
||||||
|
await expect(canvas.getByText("Feature 2 제목")).toBeVisible();
|
||||||
|
await expect(canvas.getByText("Feature 3 제목")).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("CTA 템플릿 버튼을 클릭하면 CTA 텍스트와 버튼이 생성되어야 한다", async ({ page }) => {
|
||||||
|
await page.goto("/editor");
|
||||||
|
|
||||||
|
const canvas = page.getByTestId("editor-canvas");
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "CTA 템플릿 추가" }).click();
|
||||||
|
|
||||||
|
await expect(canvas.getByText("지금 바로 행동을 유도하는 CTA 텍스트를 입력하세요.")).toBeVisible();
|
||||||
|
const ctaButton = canvas.getByRole("button", { name: "CTA 버튼" });
|
||||||
|
await expect(ctaButton).toBeVisible();
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
import { test, expect } from "@playwright/test";
|
||||||
|
|
||||||
|
// 프리뷰/뷰 모드 TDD: 먼저 실패하는 E2E부터 작성한다.
|
||||||
|
|
||||||
|
test("/preview 페이지는 에디터 크롬 없이 컨텐츠만 보여야 한다", async ({ page }) => {
|
||||||
|
// 프리뷰 페이지로 이동한다.
|
||||||
|
await page.goto("/preview");
|
||||||
|
|
||||||
|
// 프리뷰 전용 헤더가 있어야 한다.
|
||||||
|
await expect(page.getByRole("heading", { name: "Page Preview" })).toBeVisible();
|
||||||
|
|
||||||
|
// 에디터 좌측 패널용 버튼들은 나타나지 않아야 한다.
|
||||||
|
await expect(page.getByRole("button", { name: "텍스트 블록 추가" })).toHaveCount(0);
|
||||||
|
await expect(page.getByRole("button", { name: "Hero 템플릿 추가" })).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("에디터에서 Hero 템플릿을 추가하면 프리뷰에서 동일한 Hero 콘텐츠가 보여야 한다", async ({ page }) => {
|
||||||
|
// 에디터에서 Hero 템플릿을 추가한다.
|
||||||
|
await page.goto("/editor");
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Hero 템플릿 추가" }).click();
|
||||||
|
|
||||||
|
// 헤드라인과 CTA 버튼이 에디터에서 생성되었는지 한 번 확인한다.
|
||||||
|
const editorCanvas = page.getByTestId("editor-canvas");
|
||||||
|
await expect(editorCanvas.getByText("Hero 제목을 여기에 입력하세요")).toBeVisible();
|
||||||
|
await expect(editorCanvas.getByRole("button", { name: "지금 시작하기" })).toBeVisible();
|
||||||
|
|
||||||
|
// 헤더의 프리뷰 열기 링크를 통해 /preview 로 이동한다 (클라이언트 내 내비게이션 유지).
|
||||||
|
await page.getByRole("link", { name: "프리뷰 열기" }).click();
|
||||||
|
|
||||||
|
// 프리뷰 헤더가 보여야 한다.
|
||||||
|
await expect(page.getByRole("heading", { name: "Page Preview" })).toBeVisible();
|
||||||
|
|
||||||
|
// 프리뷰에서도 Hero 헤드라인과 CTA 버튼이 그대로 보여야 한다.
|
||||||
|
await expect(page.getByText("Hero 제목을 여기에 입력하세요")).toBeVisible();
|
||||||
|
// 프리뷰에서는 CTA를 실제 링크(<a>)로 렌더링하므로 텍스트 기준으로만 검증한다.
|
||||||
|
await expect(page.getByText("지금 시작하기")).toBeVisible();
|
||||||
|
|
||||||
|
// 프리뷰 화면에는 에디터용 "텍스트 블록 추가" 버튼이 없어야 한다.
|
||||||
|
await expect(page.getByRole("button", { name: "텍스트 블록 추가" })).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("에디터에서 Features 템플릿을 추가하면 프리뷰에서 3개의 Feature 섹션이 보여야 한다", async ({ page }) => {
|
||||||
|
await page.goto("/editor");
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Features 템플릿 추가" }).click();
|
||||||
|
|
||||||
|
const editorCanvas = page.getByTestId("editor-canvas");
|
||||||
|
await expect(editorCanvas.getByText("Feature 1 제목")).toBeVisible();
|
||||||
|
await expect(editorCanvas.getByText("Feature 2 제목")).toBeVisible();
|
||||||
|
await expect(editorCanvas.getByText("Feature 3 제목")).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByRole("link", { name: "프리뷰 열기" }).click();
|
||||||
|
|
||||||
|
await expect(page.getByRole("heading", { name: "Page Preview" })).toBeVisible();
|
||||||
|
|
||||||
|
await expect(page.getByText("Feature 1 제목")).toBeVisible();
|
||||||
|
await expect(page.getByText("Feature 2 제목")).toBeVisible();
|
||||||
|
await expect(page.getByText("Feature 3 제목")).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("에디터에서 CTA 템플릿을 추가하면 프리뷰에서 CTA 텍스트와 버튼이 보여야 한다", async ({ page }) => {
|
||||||
|
await page.goto("/editor");
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "CTA 템플릿 추가" }).click();
|
||||||
|
|
||||||
|
const editorCanvas = page.getByTestId("editor-canvas");
|
||||||
|
await expect(editorCanvas.getByText("지금 바로 행동을 유도하는 CTA 텍스트를 입력하세요.")).toBeVisible();
|
||||||
|
await expect(editorCanvas.getByRole("button", { name: "CTA 버튼" })).toBeVisible();
|
||||||
|
|
||||||
|
await page.getByRole("link", { name: "프리뷰 열기" }).click();
|
||||||
|
|
||||||
|
await expect(page.getByRole("heading", { name: "Page Preview" })).toBeVisible();
|
||||||
|
|
||||||
|
await expect(page.getByText("지금 바로 행동을 유도하는 CTA 텍스트를 입력하세요.")).toBeVisible();
|
||||||
|
await expect(page.getByText("CTA 버튼")).toBeVisible();
|
||||||
|
});
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { createEditorStore } from "@/features/editor/state/editorStore";
|
import {
|
||||||
|
createEditorStore,
|
||||||
|
type TextBlockProps,
|
||||||
|
type ButtonBlockProps,
|
||||||
|
} from "@/features/editor/state/editorStore";
|
||||||
|
|
||||||
// 에디터 상태 스토어에 대한 첫 TDD: 텍스트 블록 추가
|
// 에디터 상태 스토어에 대한 첫 TDD: 텍스트 블록 추가
|
||||||
|
|
||||||
@@ -13,7 +17,8 @@ describe("editorStore", () => {
|
|||||||
|
|
||||||
expect(blocks).toHaveLength(1);
|
expect(blocks).toHaveLength(1);
|
||||||
expect(blocks[0].type).toBe("text");
|
expect(blocks[0].type).toBe("text");
|
||||||
expect(blocks[0].props.text).toBe("새 텍스트");
|
const textProps = blocks[0].props as TextBlockProps;
|
||||||
|
expect(textProps.text).toBe("새 텍스트");
|
||||||
expect(selectedBlockId).toBe(blocks[0].id);
|
expect(selectedBlockId).toBe(blocks[0].id);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -39,6 +44,242 @@ describe("editorStore", () => {
|
|||||||
blocks = store.getState().blocks;
|
blocks = store.getState().blocks;
|
||||||
|
|
||||||
expect(blocks.map((b) => b.id)).toEqual([bId, aId, cId]);
|
expect(blocks.map((b) => b.id)).toEqual([bId, aId, cId]);
|
||||||
expect(blocks.map((b) => b.props.text)).toEqual(["블록 B", "블록 A", "블록 C"]);
|
expect(blocks.map((b) => (b.props as TextBlockProps).text)).toEqual([
|
||||||
|
"블록 B",
|
||||||
|
"블록 A",
|
||||||
|
"블록 C",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("버튼 블록을 추가하고 라벨/링크를 업데이트할 수 있어야 한다", () => {
|
||||||
|
const store = createEditorStore();
|
||||||
|
|
||||||
|
// 텍스트 블록 외에 버튼 블록을 추가하는 액션을 호출한다고 가정한다.
|
||||||
|
store.getState().addButtonBlock();
|
||||||
|
|
||||||
|
const { blocks, selectedBlockId } = store.getState();
|
||||||
|
|
||||||
|
expect(blocks).toHaveLength(1);
|
||||||
|
expect(blocks[0].type).toBe("button");
|
||||||
|
const buttonProps = blocks[0].props as ButtonBlockProps;
|
||||||
|
expect(buttonProps.label).toBe("버튼");
|
||||||
|
expect(buttonProps.href).toBe("#");
|
||||||
|
|
||||||
|
// 버튼 라벨과 링크를 업데이트한다.
|
||||||
|
store.getState().updateBlock(blocks[0].id, {
|
||||||
|
label: "자세히 보기",
|
||||||
|
href: "https://example.com",
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
const { blocks: updatedBlocks } = store.getState();
|
||||||
|
const updatedButtonProps = updatedBlocks[0].props as ButtonBlockProps;
|
||||||
|
expect(updatedButtonProps.label).toBe("자세히 보기");
|
||||||
|
expect(updatedButtonProps.href).toBe("https://example.com");
|
||||||
|
expect(selectedBlockId).toBe(updatedBlocks[0].id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("섹션이 선택된 상태에서 텍스트 블록을 추가하면 해당 섹션의 첫 컬럼에 배치되어야 한다", () => {
|
||||||
|
const store = createEditorStore();
|
||||||
|
|
||||||
|
// 섹션 블록을 하나 추가하고 기본 1컬럼 레이아웃을 사용한다.
|
||||||
|
store.getState().addSectionBlock();
|
||||||
|
|
||||||
|
const { blocks: afterSection } = store.getState();
|
||||||
|
expect(afterSection).toHaveLength(1);
|
||||||
|
const sectionBlock = afterSection[0];
|
||||||
|
expect(sectionBlock.type).toBe("section");
|
||||||
|
|
||||||
|
const sectionProps = sectionBlock.props as any;
|
||||||
|
expect(Array.isArray(sectionProps.columns)).toBe(true);
|
||||||
|
expect(sectionProps.columns.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
// 섹션을 선택한 후 텍스트 블록을 추가한다.
|
||||||
|
store.getState().selectBlock(sectionBlock.id);
|
||||||
|
store.getState().addTextBlock();
|
||||||
|
|
||||||
|
const { blocks: finalBlocks } = store.getState();
|
||||||
|
expect(finalBlocks).toHaveLength(2);
|
||||||
|
|
||||||
|
const textBlock = finalBlocks.find((b) => b.type === "text")!;
|
||||||
|
|
||||||
|
// 새 텍스트 블록의 sectionId/columnId가 선택된 섹션과 첫 컬럼을 가리켜야 한다.
|
||||||
|
expect((textBlock as any).sectionId).toBe(sectionBlock.id);
|
||||||
|
expect((textBlock as any).columnId).toBe(sectionProps.columns[0].id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("블록이 선택된 상태에서 새 텍스트 블록을 추가하면 동일한 섹션/컬럼에 배치되어야 한다", () => {
|
||||||
|
const store = createEditorStore();
|
||||||
|
|
||||||
|
// 섹션 + 텍스트 블록을 만든다.
|
||||||
|
store.getState().addSectionBlock();
|
||||||
|
const { blocks: afterSection } = store.getState();
|
||||||
|
const sectionBlock = afterSection[0];
|
||||||
|
const sectionProps = sectionBlock.props as any;
|
||||||
|
|
||||||
|
store.getState().selectBlock(sectionBlock.id);
|
||||||
|
store.getState().addTextBlock();
|
||||||
|
|
||||||
|
let { blocks } = store.getState();
|
||||||
|
const firstText = blocks.find((b) => b.type === "text")!;
|
||||||
|
|
||||||
|
// 첫 텍스트 블록의 위치를 기준으로 한다.
|
||||||
|
store.getState().selectBlock(firstText.id);
|
||||||
|
store.getState().addTextBlock();
|
||||||
|
|
||||||
|
blocks = store.getState().blocks;
|
||||||
|
const textBlocks = blocks.filter((b) => b.type === "text");
|
||||||
|
expect(textBlocks).toHaveLength(2);
|
||||||
|
|
||||||
|
const [t1, t2] = textBlocks as any[];
|
||||||
|
|
||||||
|
// 두 번째 텍스트 블록도 같은 섹션/컬럼에 있어야 한다.
|
||||||
|
expect(t1.sectionId).toBe(sectionBlock.id);
|
||||||
|
expect(t2.sectionId).toBe(sectionBlock.id);
|
||||||
|
expect(t1.columnId).toBe(sectionProps.columns[0].id);
|
||||||
|
expect(t2.columnId).toBe(sectionProps.columns[0].id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("moveBlock 호출 시 블록의 sectionId/columnId가 변경되어야 한다", () => {
|
||||||
|
const store = createEditorStore();
|
||||||
|
|
||||||
|
// 섹션 + 텍스트 블록 1개를 만든다.
|
||||||
|
store.getState().addSectionBlock();
|
||||||
|
const { blocks: afterSection } = store.getState();
|
||||||
|
const sectionBlock = afterSection[0];
|
||||||
|
const sectionProps = sectionBlock.props as any;
|
||||||
|
|
||||||
|
store.getState().selectBlock(sectionBlock.id);
|
||||||
|
store.getState().addTextBlock();
|
||||||
|
|
||||||
|
let { blocks } = store.getState();
|
||||||
|
const textBlock = blocks.find((b) => b.type === "text") as any;
|
||||||
|
|
||||||
|
// 초기 위치는 섹션의 첫 컬럼이어야 한다.
|
||||||
|
expect(textBlock.sectionId).toBe(sectionBlock.id);
|
||||||
|
expect(textBlock.columnId).toBe(sectionProps.columns[0].id);
|
||||||
|
|
||||||
|
// 섹션 레이아웃을 2컬럼으로 바꾸고 두 번째 컬럼으로 이동시킨다.
|
||||||
|
const updatedColumns = [
|
||||||
|
{ id: `${sectionBlock.id}_col_1`, span: 6 },
|
||||||
|
{ id: `${sectionBlock.id}_col_2`, span: 6 },
|
||||||
|
];
|
||||||
|
|
||||||
|
store.getState().updateBlock(sectionBlock.id, { columns: updatedColumns } as any);
|
||||||
|
|
||||||
|
store.getState().moveBlock(textBlock.id, sectionBlock.id, updatedColumns[1].id);
|
||||||
|
|
||||||
|
blocks = store.getState().blocks;
|
||||||
|
const moved = blocks.find((b) => b.id === textBlock.id) as any;
|
||||||
|
|
||||||
|
expect(moved.sectionId).toBe(sectionBlock.id);
|
||||||
|
expect(moved.columnId).toBe(updatedColumns[1].id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Hero 템플릿 섹션을 추가하면 섹션과 기본 텍스트/버튼 블록들이 한번에 생성되어야 한다", () => {
|
||||||
|
const store = createEditorStore();
|
||||||
|
|
||||||
|
// 템플릿 액션을 호출한다고 가정한다.
|
||||||
|
// Hero 템플릿은 기본적으로 1개의 섹션과 최소 1개의 텍스트/1개의 버튼 블록을 생성한다고 정의한다.
|
||||||
|
// (구체적인 props 내용은 구현에서 맞춰가되, 타입/개수/섹션/컬럼 배치만 검증한다.)
|
||||||
|
store.getState().addHeroTemplateSection();
|
||||||
|
|
||||||
|
const { blocks, selectedBlockId } = store.getState();
|
||||||
|
|
||||||
|
// 섹션 1개 + 텍스트/버튼 블록이 최소 1개씩 존재해야 한다.
|
||||||
|
const sectionBlocks = blocks.filter((b) => b.type === "section");
|
||||||
|
const textBlocks = blocks.filter((b) => b.type === "text");
|
||||||
|
const buttonBlocks = blocks.filter((b) => b.type === "button");
|
||||||
|
|
||||||
|
expect(sectionBlocks).toHaveLength(1);
|
||||||
|
expect(textBlocks.length).toBeGreaterThanOrEqual(1);
|
||||||
|
expect(buttonBlocks.length).toBeGreaterThanOrEqual(1);
|
||||||
|
|
||||||
|
const section = sectionBlocks[0] as any;
|
||||||
|
|
||||||
|
// 템플릿에서 생성된 텍스트/버튼 블록은 모두 동일 섹션의 첫 컬럼에 배치된다고 가정한다.
|
||||||
|
const columns = (section.props as any).columns;
|
||||||
|
expect(Array.isArray(columns)).toBe(true);
|
||||||
|
expect(columns.length).toBeGreaterThanOrEqual(1);
|
||||||
|
|
||||||
|
const firstColumnId = columns[0].id;
|
||||||
|
|
||||||
|
textBlocks.forEach((tb: any) => {
|
||||||
|
expect(tb.sectionId).toBe(section.id);
|
||||||
|
expect(tb.columnId).toBe(firstColumnId);
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonBlocks.forEach((bb: any) => {
|
||||||
|
expect(bb.sectionId).toBe(section.id);
|
||||||
|
expect(bb.columnId).toBe(firstColumnId);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 마지막으로 생성된 블록(예: CTA 버튼)이 선택되어 있다고 가정한다.
|
||||||
|
expect(selectedBlockId).toBe(blocks[blocks.length - 1].id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Features 템플릿 섹션을 추가하면 3컬럼 섹션과 각 컬럼의 제목/설명 텍스트가 생성되어야 한다", () => {
|
||||||
|
const store = createEditorStore();
|
||||||
|
|
||||||
|
// Features 템플릿 액션을 호출한다고 가정한다.
|
||||||
|
store.getState().addFeaturesTemplateSection();
|
||||||
|
|
||||||
|
const { blocks, selectedBlockId } = store.getState();
|
||||||
|
|
||||||
|
const sectionBlocks = blocks.filter((b) => b.type === "section");
|
||||||
|
expect(sectionBlocks).toHaveLength(1);
|
||||||
|
|
||||||
|
const section = sectionBlocks[0] as any;
|
||||||
|
const columns = (section.props as any).columns;
|
||||||
|
expect(Array.isArray(columns)).toBe(true);
|
||||||
|
expect(columns.length).toBe(3);
|
||||||
|
|
||||||
|
const textBlocks = blocks.filter((b) => b.type === "text") as any[];
|
||||||
|
// 최소 3개의 feature 항목(제목/설명)을 가정하고, 각 컬럼에는 2개의 텍스트(제목+설명)가 있다고 본다.
|
||||||
|
expect(textBlocks.length).toBeGreaterThanOrEqual(6);
|
||||||
|
|
||||||
|
// 모든 텍스트 블록이 동일 섹션에 속하는지 확인한다.
|
||||||
|
textBlocks.forEach((tb) => {
|
||||||
|
expect(tb.sectionId).toBe(section.id);
|
||||||
|
expect(columns.some((col: any) => col.id === tb.columnId)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(selectedBlockId).toBe(blocks[blocks.length - 1].id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("CTA 템플릿 섹션을 추가하면 텍스트와 버튼이 포함된 섹션이 생성되어야 한다", () => {
|
||||||
|
const store = createEditorStore();
|
||||||
|
|
||||||
|
// CTA 템플릿 액션을 호출한다고 가정한다.
|
||||||
|
store.getState().addCtaTemplateSection();
|
||||||
|
|
||||||
|
const { blocks, selectedBlockId } = store.getState();
|
||||||
|
|
||||||
|
const sectionBlocks = blocks.filter((b) => b.type === "section");
|
||||||
|
expect(sectionBlocks).toHaveLength(1);
|
||||||
|
|
||||||
|
const section = sectionBlocks[0] as any;
|
||||||
|
const columns = (section.props as any).columns;
|
||||||
|
expect(Array.isArray(columns)).toBe(true);
|
||||||
|
expect(columns.length).toBeGreaterThanOrEqual(1);
|
||||||
|
|
||||||
|
const firstColumnId = columns[0].id;
|
||||||
|
|
||||||
|
const textBlocks = blocks.filter((b) => b.type === "text") as any[];
|
||||||
|
const buttonBlocks = blocks.filter((b) => b.type === "button") as any[];
|
||||||
|
|
||||||
|
expect(textBlocks.length).toBeGreaterThanOrEqual(1);
|
||||||
|
expect(buttonBlocks.length).toBeGreaterThanOrEqual(1);
|
||||||
|
|
||||||
|
textBlocks.forEach((tb) => {
|
||||||
|
expect(tb.sectionId).toBe(section.id);
|
||||||
|
expect(tb.columnId).toBe(firstColumnId);
|
||||||
|
});
|
||||||
|
|
||||||
|
buttonBlocks.forEach((bb) => {
|
||||||
|
expect(bb.sectionId).toBe(section.id);
|
||||||
|
expect(bb.columnId).toBe(firstColumnId);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(selectedBlockId).toBe(blocks[blocks.length - 1].id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user