[feat] solution/frontend: 섹션 아이템을 버튼으로 넣는다 — 레트로 템플릿이 기본 구성을 데려온다

시드에 세 아이템을 박아 두니 내용 없는 칸이 목록에 늘 붙어 있었다. 붙여넣기 아이템은
JSON 이 없으면 빈 섹션이라 "쓸 사람만 넣는" 쪽이 맞다.

- canvas/addable.ts: 추가 가능한 섹션 목록. dataSpec 이 단일 출처라 아이템을 만들면 여기 자동으로
  나타난다 — 목록을 따로 들면 만들어 놓고 고를 수 없는 상태가 된다
- SectionListPanel: 하단 [+ 섹션 추가] + 썸네일 목록. 나중에 넣은 섹션만 휴지통으로 뺀다
  (업종 기본 섹션은 스위치로 끄는 것이지 빼는 게 아니다). 내용이 있으면 빼기 전에 한 번 묻는다
- stores/builder: addSection 은 이미 있으면 새로 만들지 않고 켜기만 한다 — 새로 만들면 넣어 둔
  JSON 이 날아간다
- shared/TemplateItem.defaultSectionTypes + 업종마다 레트로 템플릿 하나(옛 항구·옛 다방·노포·시간여행).
  고르면 세 아이템이 함께 들어온다. 넣기만 하고 빼지 않는다 — 템플릿을 눌러 보다 넣어 둔 섹션이
  사라지면 사장님은 그게 템플릿 때문인 줄 모르고 자기가 지웠다고 생각한다
- siteTheme/applyTheme: 저장 payload 에 type 을 싣는다. 시드에 없는 섹션은 id 로 못 찾아 복원 때
  통째로 버려졌다 — 사장님이 채운 JSON 까지 같이 사라지는 자리였다
- industryData: 세 아이템을 시드에서 뺐다

tsc·eslint·vite build 통과(frontend·admin), 추가·삭제·템플릿 연동·저장복원 왕복 12건 확인
This commit is contained in:
minaChoi committed 2026-09-02 08:35:25 +09:00
1 parent 23162783f9
commit e6ffdad888
7 files changed
+317 -30

No files matched your search

@@ -6,12 +6,15 @@ import {
SortableContext, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy,
} from '@dnd-kit/sortable';
import {CSS} from '@dnd-kit/utilities';
import {useState} from 'react';
import type {SectionItem} from '@o2o/shared';
import {GripVertical, Layers, Lock, Shapes} from 'lucide-react';
import {Check, GripVertical, Layers, Lock, Plus, Shapes, Trash2, X} from 'lucide-react';
import {Switch} from '@/components/ui/switch';
import {cn} from '@/lib/utils';
import {useBuilderStore} from '@/stores/builder';
import {ADDABLE_SECTIONS, addableSection} from './canvas/addable';
import {resolveVariant} from './canvas/registry';
import {VariantThumb} from './canvas/thumbs';
interface SectionListPanelProps {
onAfterSelect?: () => void;
@@ -28,7 +31,10 @@ function SortableSection({section, index, onAfterSelect}: SortableSectionProps)
const isSelected = useBuilderStore((s) => s.selectedSectionId === section.id);
const selectSection = useBuilderStore((s) => s.selectSection);
const toggleSection = useBuilderStore((s) => s.toggleSection);
const removeSection = useBuilderStore((s) => s.removeSection);
const variant = resolveVariant(section, industry);
// 업종 기본 섹션은 스위치로 끄는 것이지 빼는 게 아니다 — 뺄 수 있는 건 나중에 넣은 것뿐이다.
const canRemove = Boolean(addableSection(section.type));
const {attributes, listeners, setNodeRef, transform, transition, isDragging} = useSortable({
id: section.id,
});
@@ -131,6 +137,20 @@ function SortableSection({section, index, onAfterSelect}: SortableSectionProps)
</div>
<div className="flex shrink-0 items-center gap-1" onClick={(event) => event.stopPropagation()} role="presentation">
{canRemove && (
<button
type="button"
title={`${section.name} 섹션 빼기`}
aria-label={`${section.name} 섹션 빼기`}
onClick={() => {
if (section.data?.trim() && !window.confirm(`${section.name} 에 넣은 내용도 함께 지워집니다. 뺄까요?`)) return;
removeSection(section.id);
}}
className="rounded p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-destructive/10 hover:text-destructive group-hover:opacity-100 focus-visible:opacity-100"
>
<Trash2 className="size-3.5" />
</button>
)}
{section.isLocked ? (
<span title="SEO·필수 마크업이 달린 섹션이라 끌 수 없습니다." className="p-1 text-muted-foreground">
<Lock className="size-4" />
@@ -144,9 +164,70 @@ function SortableSection({section, index, onAfterSelect}: SortableSectionProps)
);
}
/** [+ 섹션 추가] 가 여는 목록. 이미 들어 있는 것은 '넣음' 으로 표시만 하고 다시 넣지 않는다. */
function AddSectionPicker({onClose, onAfterSelect}: {onClose: () => void; onAfterSelect?: () => void}) {
const sections = useBuilderStore((s) => s.sections);
const addSection = useBuilderStore((s) => s.addSection);
return (
<div className="border-t border-border bg-muted/40 p-2">
<div className="flex items-center justify-between px-1 pb-1.5">
<span className="text-[11px] font-bold">추가할 섹션</span>
<button
type="button"
onClick={onClose}
aria-label="섹션 추가 닫기"
className="rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-foreground"
>
<X className="size-3.5" />
</button>
</div>
<p className="px-1 pb-2 text-[10px] leading-relaxed text-muted-foreground">
내용은 [콘텐츠] 탭에서 프롬프트를 복사해 받은 JSON 을 붙여넣어 채웁니다.
</p>
<ul className="space-y-1.5">
{ADDABLE_SECTIONS.map((item) => {
const already = sections.some((section) => section.type === item.type);
return (
<li key={item.type}>
<button
type="button"
disabled={already}
onClick={() => {
addSection(item.type);
onClose();
onAfterSelect?.();
}}
className={cn(
'flex w-full items-start gap-2 rounded-md border p-2 text-left transition-colors',
already
? 'cursor-default border-border bg-muted/50 text-muted-foreground'
: 'border-border bg-card hover:border-primary hover:bg-primary/5',
)}
>
<VariantThumb thumb={item.thumb} className="mt-0.5 w-9 shrink-0" />
<span className="min-w-0 flex-1">
<span className="flex items-center gap-1 text-[11px] font-semibold text-foreground">
{item.name}
{already && <Check className="size-3 text-muted-foreground" />}
</span>
<span className="mt-0.5 block text-[10px] leading-relaxed text-muted-foreground">
{already ? '이미 목록에 있습니다' : item.description}
</span>
</span>
</button>
</li>
);
})}
</ul>
</div>
);
}
export function SectionListPanel({onAfterSelect}: SectionListPanelProps) {
const sections = useBuilderStore((s) => s.sections);
const reorderSection = useBuilderStore((s) => s.reorderSection);
const [isPickerOpen, setPickerOpen] = useState(false);
const sensors = useSensors(
useSensor(PointerSensor, {activationConstraint: {distance: 6}}),
useSensor(KeyboardSensor, {coordinateGetter: sortableKeyboardCoordinates}),
@@ -191,6 +272,19 @@ export function SectionListPanel({onAfterSelect}: SectionListPanelProps) {
</SortableContext>
</DndContext>
{isPickerOpen ? (
<AddSectionPicker onClose={() => setPickerOpen(false)} onAfterSelect={onAfterSelect} />
) : (
<button
type="button"
onClick={() => setPickerOpen(true)}
className="flex items-center justify-center gap-1.5 border-t border-border bg-card p-2.5 text-[11px] font-semibold text-muted-foreground transition-colors hover:bg-primary/5 hover:text-primary"
>
<Plus className="size-3.5" />
섹션 추가
</button>
)}
<p className="border-t border-border bg-muted/30 p-2.5 text-center text-[10px] text-muted-foreground">
* 자물쇠 항목은 검색·AI 노출에 필요한 마크업이 달려 있어 고정입니다.
</p>
@@ -0,0 +1,51 @@
/**
* 나중에 넣을 수 있는 섹션 — [+ 섹션 추가] 가 고르는 목록.
*
* 업종 시드(industryData)는 "처음부터 있는 것"이고 여기는 "필요하면 넣는 것"이다.
* 붙여넣기 아이템은 내용이 없으면 빈 섹션이라, 시드에 박아 두면 아무도 안 쓰는 칸이 늘 붙어 있다.
*/
import type {SectionItem} from '@o2o/shared';
import {SECTION_DATA_SPEC} from './dataSpec';
import {defaultVariant} from './registry';
import type {ThumbKey} from './types';
export interface AddableSection {
type: string;
name: string;
description: string;
thumb: ThumbKey;
}
/**
* 추가할 수 있는 섹션 목록.
*
* ★ dataSpec 이 단일 출처다 — 아이템을 하나 더 만들면 여기에도 자동으로 나타난다.
* 목록을 따로 들면 아이템을 추가하고 이 표를 잊어 "만들었는데 고를 수가 없는" 상태가 된다.
*/
export const ADDABLE_SECTIONS: AddableSection[] = Object.values(SECTION_DATA_SPEC).map((spec) => {
const variant = defaultVariant(spec.kind);
return {
type: spec.kind,
name: spec.label,
description: variant?.description ?? '',
thumb: variant?.thumb ?? 'cards',
};
});
export function addableSection(type: string): AddableSection | undefined {
return ADDABLE_SECTIONS.find((item) => item.type === type);
}
/** 목록에 새로 넣을 섹션 한 줄. id 는 타입과 같다 — 같은 아이템을 두 번 넣지 않는다. */
export function newSectionOf(type: string): SectionItem | undefined {
const addable = addableSection(type);
if (!addable) return undefined;
return {
id: type,
type,
name: addable.name,
description: addable.description,
isLocked: false,
isEnabled: true,
};
}