151 lines
3.2 KiB
TypeScript
151 lines
3.2 KiB
TypeScript
/**
|
|
* Field Type System inspired by Laravel Nova
|
|
* Defines all available field types and their configurations
|
|
*/
|
|
|
|
export enum FieldType {
|
|
// Text fields
|
|
TEXT = 'text',
|
|
TEXTAREA = 'textarea',
|
|
PASSWORD = 'password',
|
|
EMAIL = 'email',
|
|
|
|
// Numeric fields
|
|
NUMBER = 'number',
|
|
CURRENCY = 'currency',
|
|
|
|
// Selection fields
|
|
SELECT = 'select',
|
|
MULTI_SELECT = 'multiSelect',
|
|
BOOLEAN = 'boolean',
|
|
|
|
// Date/Time fields
|
|
DATE = 'date',
|
|
DATETIME = 'datetime',
|
|
TIME = 'time',
|
|
|
|
// Relationship fields
|
|
BELONGS_TO = 'belongsTo',
|
|
HAS_MANY = 'hasMany',
|
|
MANY_TO_MANY = 'manyToMany',
|
|
|
|
// Rich content
|
|
MARKDOWN = 'markdown',
|
|
CODE = 'code',
|
|
|
|
// File fields
|
|
FILE = 'file',
|
|
IMAGE = 'image',
|
|
|
|
// Other
|
|
URL = 'url',
|
|
COLOR = 'color',
|
|
JSON = 'json',
|
|
}
|
|
|
|
export enum ViewMode {
|
|
LIST = 'list',
|
|
DETAIL = 'detail',
|
|
EDIT = 'edit',
|
|
}
|
|
|
|
export interface FieldOption {
|
|
label: string;
|
|
value: string | number | boolean;
|
|
}
|
|
|
|
export interface FieldValidationRule {
|
|
type: 'required' | 'min' | 'max' | 'email' | 'url' | 'pattern' | 'custom';
|
|
value?: any;
|
|
message?: string;
|
|
}
|
|
|
|
export interface FieldConfig {
|
|
// Basic field properties
|
|
id: string;
|
|
apiName: string;
|
|
label: string;
|
|
type: FieldType;
|
|
|
|
// Display properties
|
|
placeholder?: string;
|
|
helpText?: string;
|
|
defaultValue?: any;
|
|
|
|
// Validation
|
|
isRequired?: boolean;
|
|
isReadOnly?: boolean;
|
|
validationRules?: FieldValidationRule[];
|
|
|
|
// View-specific options
|
|
showOnList?: boolean;
|
|
showOnDetail?: boolean;
|
|
showOnEdit?: boolean;
|
|
sortable?: boolean;
|
|
|
|
// Field type specific options
|
|
options?: FieldOption[]; // For select, multi-select
|
|
rows?: number; // For textarea
|
|
min?: number; // For number, date
|
|
max?: number; // For number, date
|
|
step?: number; // For number
|
|
accept?: string; // For file/image
|
|
relationObject?: string; // For relationship fields
|
|
relationDisplayField?: string; // Which field to display for relations
|
|
|
|
// Formatting
|
|
format?: string; // Date format, number format, etc.
|
|
prefix?: string; // Currency symbol, etc.
|
|
suffix?: string;
|
|
|
|
// Advanced
|
|
dependsOn?: string[]; // Field dependencies
|
|
computedValue?: string; // Formula for computed fields
|
|
}
|
|
|
|
export interface ViewConfig {
|
|
objectApiName: string;
|
|
fields: FieldConfig[];
|
|
mode: ViewMode;
|
|
}
|
|
|
|
export interface ListViewConfig extends ViewConfig {
|
|
mode: ViewMode.LIST;
|
|
pageSize?: number;
|
|
searchable?: boolean;
|
|
filterable?: boolean;
|
|
exportable?: boolean;
|
|
actions?: ViewAction[];
|
|
}
|
|
|
|
export interface DetailViewConfig extends ViewConfig {
|
|
mode: ViewMode.DETAIL;
|
|
sections?: FieldSection[];
|
|
actions?: ViewAction[];
|
|
}
|
|
|
|
export interface EditViewConfig extends ViewConfig {
|
|
mode: ViewMode.EDIT;
|
|
sections?: FieldSection[];
|
|
submitLabel?: string;
|
|
cancelLabel?: string;
|
|
}
|
|
|
|
export interface FieldSection {
|
|
title?: string;
|
|
description?: string;
|
|
fields: string[]; // Field API names
|
|
collapsible?: boolean;
|
|
defaultCollapsed?: boolean;
|
|
}
|
|
|
|
export interface ViewAction {
|
|
id: string;
|
|
label: string;
|
|
icon?: string;
|
|
variant?: 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link';
|
|
confirmation?: string;
|
|
endpoint?: string;
|
|
handler?: () => void | Promise<void>;
|
|
}
|