フィールド型リファレンス

このページ

EmDash はコンテンツスキーマを定義するための 14 種類のフィールド型をサポートします。各型は SQLite の列型にマッピングされ、適切な管理 UI を提供します。

Overview

TypeSQLite ColumnDescription
stringTEXT短い 1 行テキスト入力
textTEXT複数行テキスト
numberREAL小数
integerINTEGER整数
booleanINTEGER真 / 偽
datetimeTEXT日付と時刻
selectTEXTオプションから単一選択
multiSelectJSON複数選択
portableTextJSONリッチテキストコンテンツ
imageTEXT画像参照
fileTEXTファイル参照
referenceTEXT別エントリへの参照
jsonJSON任意の JSON データ
slugTEXTURL 安全な識別子

Text Types

string

短い 1 行テキスト。タイトル、名前、短い値に使います。

{
  slug: "title",
  label: "Title",
  type: "string",
  required: true,
  validation: {
    minLength: 1,
    maxLength: 200,
  },
}

Validation options:

  • minLength — 最小文字数
  • maxLength — 最大文字数
  • pattern — 一致させる正規表現パターン

Widget options:

  • 固有のものなし

text

複数行のプレーンテキスト。説明、抜粋、長めのプレーンテキスト向け。

{
  slug: "excerpt",
  label: "Excerpt",
  type: "text",
  options: {
    rows: 3,
  },
}

Validation options:

  • minLength — 最小文字数
  • maxLength — 最大文字数

Widget options:

  • rows — textarea の行数(デフォルト: 3)

slug

URL 安全な識別子。別フィールドから自動生成するか手入力します。

{
  slug: "slug",
  label: "URL Slug",
  type: "slug",
  required: true,
  unique: true,
}

slug は自動的に正規化されます(小文字化、スペースをハイフンに、特殊文字除去)。

Number Types

number

小数。価格、評価、計測値向け。

{
  slug: "price",
  label: "Price",
  type: "number",
  required: true,
  validation: {
    min: 0,
    max: 999999.99,
  },
}

Validation options:

  • min — 最小値
  • max — 最大値

SQLite REAL(64 ビット浮動小数点)として保存。

integer

整数。数量、件数、並び順の値向け。

{
  slug: "quantity",
  label: "Quantity",
  type: "integer",
  defaultValue: 1,
  validation: {
    min: 0,
    max: 1000,
  },
}

Validation options:

  • min — 最小値
  • max — 最大値

SQLite INTEGER として保存。

boolean

真または偽。トグルやフラグ向け。

{
  slug: "featured",
  label: "Featured",
  type: "boolean",
  defaultValue: false,
}

SQLite INTEGER(0 または 1)として保存。

Date and Time

datetime

日付と時刻。ISO 8601 形式で保存。

{
  slug: "publishedAt",
  label: "Published At",
  type: "datetime",
}

Validation options:

  • min — 最小日付(ISO 文字列)
  • max — 最大日付(ISO 文字列)

Storage format: 2025-01-24T12:00:00.000Z

Selection Types

select

事前定義されたオプションからの単一選択。

{
  slug: "status",
  label: "Status",
  type: "select",
  required: true,
  defaultValue: "draft",
  validation: {
    options: ["draft", "published", "archived"],
  },
}

Validation options:

  • options — 許可値の配列(必須)

選択値を含む TEXT として保存。

multiSelect

事前定義されたオプションからの複数選択。

{
  slug: "tags",
  label: "Tags",
  type: "multiSelect",
  validation: {
    options: ["news", "tutorial", "review", "opinion"],
  },
}

Validation options:

  • options — 許可値の配列(必須)

JSON 配列として保存: ["news", "tutorial"]

Rich Content

portableText

Portable Text 形式のリッチテキスト。見出し、リスト、リンク、画像、カスタムブロックをサポート。

{
  slug: "content",
  label: "Content",
  type: "portableText",
  required: true,
}

Portable Text ブロックの JSON 配列として保存:

[
	{
		"_type": "block",
		"style": "normal",
		"children": [{ "_type": "span", "text": "Hello world" }]
	}
]

プラグインはエディターにカスタムブロック型(埋め込み、ウィジェットなど)を追加できます。スラッシュコマンドメニューに表示され、サイト上で自動レンダリングされます。参照: Creating Plugins — Portable Text Block Types.

Media Types

image

アップロード画像への参照。寸法や alt テキストなどのメタデータを含みます。

{
  slug: "featuredImage",
  label: "Featured Image",
  type: "image",
  options: {
    showPreview: true,
  },
}

Widget options:

  • showPreview — 管理画面で画像プレビューを表示(デフォルト: true)

Stored value:

{
	"id": "01HXK5MZSN...",
	"url": "https://cdn.example.com/image.jpg",
	"alt": "Description",
	"width": 1920,
	"height": 1080
}

file

アップロードファイル(文書、PDF など)への参照。

{
  slug: "document",
  label: "Document",
  type: "file",
}

Stored value:

{
	"id": "01HXK5MZSN...",
	"url": "https://cdn.example.com/doc.pdf",
	"filename": "report.pdf",
	"mimeType": "application/pdf",
	"size": 102400
}

Relational Types

reference

別のコンテンツエントリへの参照。

{
  slug: "author",
  label: "Author",
  type: "reference",
  required: true,
  options: {
    collection: "authors",
  },
}

Widget options:

  • collection — 対象コレクションの slug(必須)
  • allowMultiple — 複数参照を許可(デフォルト: false)

Single reference stored value:

"01HXK5MZSN..."

Multiple references stored value:

["01HXK5MZSN...", "01HXK6NATS..."]

Flexible Types

json

任意の JSON データ。入れ子構造、サードパーティ連携、固定スキーマのないデータ向け。

{
  slug: "metadata",
  label: "Metadata",
  type: "json",
}

SQLite の JSON 列にそのまま保存。

Field Properties

すべてのフィールドで次の共通プロパティを利用できます:

PropertyTypeDescription
slugstring一意の識別子(必須)
labelstring表示名(必須)
typeFieldTypeフィールド型(必須)
requiredboolean値を必須にする(デフォルト: false)
uniqueboolean一意性を強制(デフォルト: false)
defaultValueunknown新規エントリのデフォルト値
validationobject型固有のバリデーションルール
widgetstringカスタムウィジェットの上書き
optionsobjectウィジェット設定
sortOrdernumber管理画面での表示順

Reserved Field Slugs

次の slug は予約されており使用できません:

  • id
  • slug
  • status
  • author_id
  • created_at
  • updated_at
  • published_at
  • deleted_at
  • version

TypeScript Types

プログラムから使うためにフィールド型をインポート:

import type { FieldType, Field, CreateFieldInput } from "emdash";

const fieldTypes: FieldType[] = [
	"string",
	"text",
	"number",
	"integer",
	"boolean",
	"datetime",
	"select",
	"multiSelect",
	"portableText",
	"image",
	"file",
	"reference",
	"json",
	"slug",
];