콘텐츠로 이동

Block Kit

EmDash의 Block Kit은 샌드박스 플러그인이 관리자 UI를 JSON으로 설명할 수 있게 합니다. 호스트가 블록을 렌더링하며, 플러그인이 제공한 JavaScript는 브라우저에서 절대 실행되지 않습니다.

  1. 사용자가 플러그인의 관리자 페이지로 이동합니다.
  2. 관리자가 플러그인의 관리자 경로로 page_load 상호작용을 전송합니다.
  3. 플러그인이 블록 배열을 포함한 BlockResponse를 반환합니다.
  4. 관리자가 BlockRenderer 컴포넌트를 사용하여 블록을 렌더링합니다.
  5. 사용자가 상호작용(버튼 클릭, 폼 제출)할 때, 관리자가 상호작용을 다시 플러그인으로 전송합니다.
  6. 플러그인이 새로운 블록을 반환하고, 이 주기가 반복됩니다.
// Plugin admin route handler
routes: {
admin: {
handler: async (ctx, { request }) => {
const interaction = await request.json();
if (interaction.type === "page_load") {
return {
blocks: [
{ type: "header", text: "My Plugin Settings" },
{
type: "form",
block_id: "settings",
fields: [
{ type: "text_input", action_id: "api_url", label: "API URL" },
{ type: "toggle", action_id: "enabled", label: "Enabled", initial_value: true },
],
submit: { label: "Save", action_id: "save" },
},
],
};
}
if (interaction.type === "form_submit" && interaction.action_id === "save") {
await ctx.kv.set("settings", interaction.values);
return {
blocks: [/* ... 업데이트된 블록 ... */],
toast: { message: "Settings saved", type: "success" },
};
}
},
},
}
타입설명
header큰 굵은 제목
section선택적 액세서리 요소가 있는 텍스트
divider수평 구분선
fields두 열 레이블/값 그리드
table서식, 정렬, 페이지네이션이 있는 데이터 테이블
actions버튼과 컨트롤의 수평 행
stats추세 지표가 있는 대시보드 메트릭 카드
form조건부 가시성과 제출이 있는 입력 필드
image캡션이 있는 블록 수준 이미지
context작은 음영 처리된 도움말 텍스트
columns중첩 블록이 있는 2-3 열 레이아웃
타입설명
button선택적 확인 대화 상자가 있는 액션 버튼
text_input단일 줄 또는 여러 줄 텍스트 입력
number_input최소/최대값이 있는 숫자 입력
select드롭다운 선택
toggle켜기/끄기 스위치
secret_inputAPI 키와 토큰을 위한 마스킹된 입력

@emdash-cms/blocks 패키지는 더 깔끔한 코드를 위한 빌더 헬퍼를 내보냅니다:

import { blocks, elements } from "@emdash-cms/blocks";
const { header, form, section, stats } = blocks;
const { textInput, toggle, select, button } = elements;
return {
blocks: [
header("SEO 설정"),
form({
blockId: "settings",
fields: [
textInput("site_title", "사이트 제목", { initialValue: "내 사이트" }),
toggle("generate_sitemap", "사이트맵 생성", { initialValue: true }),
select("robots", "기본 Robots", [
{ label: "Index, Follow", value: "index,follow" },
{ label: "No Index", value: "noindex,follow" },
]),
],
submit: { label: "Save", actionId: "save" },
}),
],
};

폼 필드는 다른 필드 값에 따라 조건부로 표시될 수 있습니다:

{
"type": "toggle",
"action_id": "auth_enabled",
"label": "Enable Authentication"
}
{
"type": "secret_input",
"action_id": "api_key",
"label": "API Key",
"condition": { "field": "auth_enabled", "eq": true }
}

api_key 필드는 auth_enabled가 켜져 있을 때만 나타납니다. 조건은 왕복 없이 클라이언트 측에서 평가됩니다.

Block Playground를 사용하여 블록 레이아웃을 대화형으로 구축하고 테스트하세요.