Files
page-builder/src/app/editor/templates/blogTemplate.ts
T
jaybe a6ef5f01cd
CI / pr_and_merge (push) Blocked by required conditions
CI / test (push) Has been cancelled
에디터 인라인/속성 패널 리팩터링 및 폼 전송 기본 기능 추가
2025-11-20 00:53:39 +09:00

79 lines
2.0 KiB
TypeScript

"use client";
import type { Block, SectionBlockProps, TextBlockProps } from "@/features/editor/state/editorStore";
export function createBlogTemplateBlocks(opts: {
sectionId: string;
createId: () => string;
}): { blocks: Block[]; lastSelectedId: string } {
const { sectionId, createId } = opts;
const columns: SectionBlockProps["columns"] = [
{ id: `${sectionId}_col_1`, span: 4 },
{ id: `${sectionId}_col_2`, span: 4 },
{ id: `${sectionId}_col_3`, span: 4 },
];
const sectionProps: SectionBlockProps = {
background: "default",
paddingY: "lg",
columns,
} as any;
const sectionBlock: Block = {
id: sectionId,
type: "section",
props: sectionProps,
sectionId: null,
columnId: null,
};
const postDefinitions = [
{ title: "블로그 포스트 1", summary: "첫 번째 포스트 요약을 여기에 입력하세요." },
{ title: "블로그 포스트 2", summary: "두 번째 포스트 요약을 여기에 입력하세요." },
{ title: "블로그 포스트 3", summary: "세 번째 포스트 요약을 여기에 입력하세요." },
];
const blogBlocks: Block[] = columns.flatMap((col, index) => {
const post = postDefinitions[index] ?? postDefinitions[0];
const titleId = createId();
const summaryId = createId();
const titleProps: TextBlockProps = {
text: post.title,
align: "left",
size: "lg",
} as any;
const summaryProps: TextBlockProps = {
text: post.summary,
align: "left",
size: "sm",
} as any;
const titleBlock: Block = {
id: titleId,
type: "text",
props: titleProps,
sectionId,
columnId: col.id,
};
const summaryBlock: Block = {
id: summaryId,
type: "text",
props: summaryProps,
sectionId,
columnId: col.id,
};
return [titleBlock, summaryBlock];
});
const blocks: Block[] = [sectionBlock, ...blogBlocks];
const lastSelectedId = blogBlocks[blogBlocks.length - 1]?.id ?? sectionId;
return { blocks, lastSelectedId };
}