EmDash supporta 14 tipi di campo per definire gli schemi di contenuto. Ogni tipo è mappato a un tipo di colonna SQLite e fornisce l’interfaccia di amministrazione appropriata.
Overview
| Type | SQLite Column | Description |
|---|---|---|
string | TEXT | Input di testo breve su una riga |
text | TEXT | Testo su più righe |
number | REAL | Numero decimale |
integer | INTEGER | Numero intero |
boolean | INTEGER | Vero / falso |
datetime | TEXT | Data e ora |
select | TEXT | Scelta singola tra opzioni |
multiSelect | JSON | Scelte multiple |
portableText | JSON | Contenuto di testo arricchito |
image | TEXT | Riferimento a immagine |
file | TEXT | Riferimento a file |
reference | TEXT | Riferimento a un’altra voce |
json | JSON | Dati JSON arbitrari |
slug | TEXT | Identificatore sicuro per URL |
Text Types
string
Testo breve su una sola riga. Per titoli, nomi e valori brevi.
{
slug: "title",
label: "Title",
type: "string",
required: true,
validation: {
minLength: 1,
maxLength: 200,
},
}
Validation options:
minLength— Numero minimo di caratterimaxLength— Numero massimo di caratteripattern— Pattern regex da soddisfare
Widget options:
- Nessuna specifica
text
Testo semplice su più righe. Per descrizioni, estratti e testo semplice più lungo.
{
slug: "excerpt",
label: "Excerpt",
type: "text",
options: {
rows: 3,
},
}
Validation options:
minLength— Numero minimo di caratterimaxLength— Numero massimo di caratteri
Widget options:
rows— Numero di righe nel textarea (predefinito: 3)
slug
Identificatore sicuro per URL. Generato automaticamente da un altro campo o inserito manualmente.
{
slug: "slug",
label: "URL Slug",
type: "slug",
required: true,
unique: true,
}
Gli slug vengono normalizzati automaticamente: minuscole, spazi sostituiti da trattini, caratteri speciali rimossi.
Number Types
number
Numero decimale. Per prezzi, valutazioni e misure.
{
slug: "price",
label: "Price",
type: "number",
required: true,
validation: {
min: 0,
max: 999999.99,
},
}
Validation options:
min— Valore minimomax— Valore massimo
Memorizzato come SQLite REAL (floating point a 64 bit).
integer
Numero intero. Per quantità, conteggi e valori di ordinamento.
{
slug: "quantity",
label: "Quantity",
type: "integer",
defaultValue: 1,
validation: {
min: 0,
max: 1000,
},
}
Validation options:
min— Valore minimomax— Valore massimo
Memorizzato come SQLite INTEGER.
boolean
Vero o falso. Per interruttori e flag.
{
slug: "featured",
label: "Featured",
type: "boolean",
defaultValue: false,
}
Memorizzato come SQLite INTEGER (0 o 1).
Date and Time
datetime
Data e ora. Memorizzate in formato ISO 8601.
{
slug: "publishedAt",
label: "Published At",
type: "datetime",
}
Validation options:
min— Data minima (stringa ISO)max— Data massima (stringa ISO)
Storage format: 2025-01-24T12:00:00.000Z
Selection Types
select
Scelta singola tra opzioni predefinite.
{
slug: "status",
label: "Status",
type: "select",
required: true,
defaultValue: "draft",
validation: {
options: ["draft", "published", "archived"],
},
}
Validation options:
options— Array di valori consentiti (obbligatorio)
Memorizzato come TEXT con il valore selezionato.
multiSelect
Scelte multiple tra opzioni predefinite.
{
slug: "tags",
label: "Tags",
type: "multiSelect",
validation: {
options: ["news", "tutorial", "review", "opinion"],
},
}
Validation options:
options— Array di valori consentiti (obbligatorio)
Memorizzato come array JSON: ["news", "tutorial"]
Rich Content
portableText
Testo arricchito in formato Portable Text. Supporta titoli, elenchi, link, immagini e blocchi personalizzati.
{
slug: "content",
label: "Content",
type: "portableText",
required: true,
}
Memorizzato come array JSON di blocchi Portable Text:
[
{
"_type": "block",
"style": "normal",
"children": [{ "_type": "span", "text": "Hello world" }]
}
]
I plugin possono aggiungere tipi di blocco personalizzati (embed, widget, ecc.) all’editor. Compaiono nel menu comandi slash e vengono renderizzati automaticamente sul sito. Vedi Creating Plugins — Portable Text Block Types.
Media Types
image
Riferimento a un’immagine caricata. Include metadati come dimensioni e testo alternativo.
{
slug: "featuredImage",
label: "Featured Image",
type: "image",
options: {
showPreview: true,
},
}
Widget options:
showPreview— Mostra anteprima immagine nell’admin (predefinito: true)
Stored value:
{
"id": "01HXK5MZSN...",
"url": "https://cdn.example.com/image.jpg",
"alt": "Description",
"width": 1920,
"height": 1080
}
file
Riferimento a un file caricato (documenti, PDF, ecc.).
{
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
Riferimento a un’altra voce di contenuto.
{
slug: "author",
label: "Author",
type: "reference",
required: true,
options: {
collection: "authors",
},
}
Widget options:
collection— Slug della collection di destinazione (obbligatorio)allowMultiple— Consenti più riferimenti (predefinito: false)
Single reference stored value:
"01HXK5MZSN..."
Multiple references stored value:
["01HXK5MZSN...", "01HXK6NATS..."]
Flexible Types
json
Dati JSON arbitrari. Per strutture annidate, integrazioni di terze parti o dati senza schema fisso.
{
slug: "metadata",
label: "Metadata",
type: "json",
}
Memorizzato così com’è nella colonna JSON di SQLite.
Field Properties
Tutti i campi supportano queste proprietà comuni:
| Property | Type | Description |
|---|---|---|
slug | string | Identificatore univoco (obbligatorio) |
label | string | Nome visualizzato (obbligatorio) |
type | FieldType | Tipo di campo (obbligatorio) |
required | boolean | Valore obbligatorio (predefinito: false) |
unique | boolean | Forza unicità (predefinito: false) |
defaultValue | unknown | Valore predefinito per nuove voci |
validation | object | Regole di validazione specifiche per tipo |
widget | string | Override widget personalizzato |
options | object | Configurazione widget |
sortOrder | number | Ordine di visualizzazione nell’admin |
Reserved Field Slugs
Questi slug sono riservati e non possono essere usati:
idslugstatusauthor_idcreated_atupdated_atpublished_atdeleted_atversion
TypeScript Types
Importa i tipi di campo per uso programmatico:
import type { FieldType, Field, CreateFieldInput } from "emdash";
const fieldTypes: FieldType[] = [
"string",
"text",
"number",
"integer",
"boolean",
"datetime",
"select",
"multiSelect",
"portableText",
"image",
"file",
"reference",
"json",
"slug",
];