merge ts-final
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-use-before-define */
|
||||
import { CSSProperties } from 'react';
|
||||
import { PayloadRequest } from '../../express/types/payloadRequest';
|
||||
import { Access } from '../../config/types';
|
||||
@@ -10,41 +11,19 @@ export type FieldHook = (args: {
|
||||
operation?: 'create' | 'update',
|
||||
req?: PayloadRequest}) => Promise<any> | any;
|
||||
|
||||
export type Field = {
|
||||
type FieldBase = {
|
||||
name: string;
|
||||
label: string;
|
||||
slug?: string;
|
||||
label?: string;
|
||||
type:
|
||||
| 'number'
|
||||
| 'text'
|
||||
| 'email'
|
||||
| 'textarea'
|
||||
| 'richText'
|
||||
| 'code'
|
||||
| 'radio'
|
||||
| 'checkbox'
|
||||
| 'date'
|
||||
| 'upload'
|
||||
| 'relationship'
|
||||
| 'row'
|
||||
| 'array'
|
||||
| 'group'
|
||||
| 'select'
|
||||
| 'blocks';
|
||||
localized?: boolean;
|
||||
hidden?: boolean;
|
||||
required?: boolean;
|
||||
unique?: boolean;
|
||||
defaultValue?: any;
|
||||
hidden?: boolean;
|
||||
localized?: boolean;
|
||||
maxLength?: number;
|
||||
height?: number;
|
||||
validate?: (value: any, field: Field) => any;
|
||||
access?: {
|
||||
create?: Access;
|
||||
read?: Access;
|
||||
update?: Access;
|
||||
delete?: Access;
|
||||
};
|
||||
blocks: Field[];
|
||||
relationTo?: string;
|
||||
fields?: Field[];
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
hooks?: {
|
||||
beforeValidate?: FieldHook[];
|
||||
beforeChange?: FieldHook[];
|
||||
@@ -52,11 +31,109 @@ export type Field = {
|
||||
afterRead?: FieldHook[];
|
||||
}
|
||||
admin?: {
|
||||
position?: string;
|
||||
position?: 'sidebar';
|
||||
width?: string;
|
||||
style?: CSSProperties;
|
||||
readOnly?: boolean;
|
||||
disabled?: boolean;
|
||||
condition?: () => any;
|
||||
condition?: (...args: any[]) => any | void;
|
||||
components?: { [key: string]: JSX.Element | (() => JSX.Element) };
|
||||
};
|
||||
access?: {
|
||||
create?: Access;
|
||||
read?: Access;
|
||||
update?: Access;
|
||||
delete?: Access;
|
||||
admin?: Access;
|
||||
unlock?: Access;
|
||||
};
|
||||
}
|
||||
|
||||
export type StandardField = FieldBase & {
|
||||
fields?: Field[];
|
||||
}
|
||||
|
||||
export type NumberField = StandardField & { type: 'number'; };
|
||||
export type TextField = StandardField & { type: 'text'; };
|
||||
export type EmailField = StandardField & { type: 'email'; };
|
||||
export type TextareaField = StandardField & { type: 'textarea'; };
|
||||
export type CodeField = StandardField & { type: 'code'; };
|
||||
export type CheckboxField = StandardField & { type: 'checkbox'; };
|
||||
export type DateField = StandardField & { type: 'date'; };
|
||||
export type GroupField = StandardField & { type: 'group'; };
|
||||
export type RowField = StandardField & { type: 'row'; };
|
||||
|
||||
export type UploadField = FieldBase & {
|
||||
type: 'upload';
|
||||
relationTo: string;
|
||||
}
|
||||
|
||||
export type SelectField = FieldBase & {
|
||||
type: 'select';
|
||||
options: {
|
||||
value: string;
|
||||
label: string;
|
||||
}[];
|
||||
hasMany?: boolean;
|
||||
}
|
||||
|
||||
export type SelectManyField = SelectField & {
|
||||
hasMany: true;
|
||||
}
|
||||
|
||||
type RelationShipSingleField = FieldBase & {
|
||||
type: 'relationship';
|
||||
relationTo: string;
|
||||
hasMany?: false;
|
||||
}
|
||||
|
||||
type RelationShipManyField = FieldBase & {
|
||||
type: 'relationship';
|
||||
relationTo: string[] | string;
|
||||
hasMany: true;
|
||||
}
|
||||
|
||||
export type RelationshipField = RelationShipSingleField | RelationShipManyField;
|
||||
|
||||
type RichTextElements = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'blockquote' | 'ul' | 'ol' | 'link';
|
||||
type RichTextLeaves = 'bold' | 'italic' | 'underline' | 'strikethrough';
|
||||
export type RichTextField = FieldBase & {
|
||||
type: 'richText';
|
||||
admin?: {
|
||||
elements?: RichTextElements[];
|
||||
leaves?: RichTextLeaves[];
|
||||
}
|
||||
}
|
||||
|
||||
export type ArrayField = FieldBase & {
|
||||
type: 'array';
|
||||
minRows?: number;
|
||||
maxRows?: number;
|
||||
fields?: Field[];
|
||||
}
|
||||
|
||||
export type RadioField = FieldBase & {
|
||||
type: 'radio';
|
||||
options: {
|
||||
value: string;
|
||||
label: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
export type Block = {
|
||||
slug: string,
|
||||
labels: {
|
||||
singular: string;
|
||||
plural: string;
|
||||
};
|
||||
fields: Field[],
|
||||
}
|
||||
|
||||
export type BlockField = FieldBase & {
|
||||
type: 'blocks';
|
||||
minRows?: number;
|
||||
maxRows?: number;
|
||||
blocks?: Block[];
|
||||
};
|
||||
|
||||
export type Field = NumberField | TextField | EmailField | TextareaField | CodeField | CheckboxField | DateField | BlockField | RadioField | RelationshipField | ArrayField | RichTextField | GroupField | RowField | SelectField | SelectManyField | UploadField;
|
||||
|
||||
Reference in New Issue
Block a user