import { JSX, ReactElement } from 'react'; import * as Yup from 'yup'; import { AutocompleteRenderOptionState } from '@mui/material/Autocomplete'; import { GridColDef, GridFilterModel, GridSortModel } from '@mui/x-data-grid'; import { DateView } from '@mui/x-date-pickers'; import { Control, FieldErrors, UseFormGetValues, UseFormSetValue } from 'react-hook-form'; import { SxProps, Theme } from '@mui/material/styles'; import { OnEditModelType } from '../context/APIWrapperContext'; import { ServerEndPoint } from '../context/DRFReactBySchemaContext'; import { AlertColor } from '@mui/material/Alert'; export type Id = string | number | null; export type IdNotNull = string | number; export type GenericValue = any; type TypedFieldKey = Extract; export type FieldKey = T extends void ? string : NoInfer>; export type TField = Record | void; export type Item = T extends void ? Record : T; export type PartialItem = T extends void ? Record : Partial]> & { id?: Id; }>; export type AutocompleteItem = { id: IdNotNull; label: string; }; export type OptionsACItem = AutocompleteItem | ChoiceItem; export type FieldOptionsAC = OptionsACItem[]; type BaseOptionsAC = Record; type TypedOptionsAC = Partial, FieldOptionsAC>>; export type OptionsAC = T extends void ? BaseOptionsAC : TypedOptionsAC; type BaseOptionsACWithLoaders = Record Promise)>; type TypedOptionsACWithLoaders = Partial, FieldOptionsAC | (() => Promise)>>; export type OptionsACWithLoaders = T extends void ? BaseOptionsACWithLoaders : TypedOptionsACWithLoaders; interface BasePaginatedResult { count: number; next: number; previous: number; sum_rows: null | Record; results: Item[]; } interface TypedPaginatedResult { count: number; next: number; previous: number; sum_rows: null | Partial, number>>; results: T[]; } export type PaginatedResult = T extends void ? BasePaginatedResult : TypedPaginatedResult; export interface PaginationModel { page: number; pageSize: number; filter?: GridFilterModel; sort?: GridSortModel; queryParams?: string[]; } type BaseSchemaType = Record; type TypedSchemaType = Partial, Field>>; export type SchemaType = T extends void ? BaseSchemaType : TypedSchemaType; export interface SchemaOptionsType { schema: SchemaType; verbose_name: string; verbose_name_plural: string; } export type SchemaOptionsSingleActionType = Omit & { action: { POST: SchemaType; }; }; export type ModelOptionsType = Omit, 'actions' | 'renders' | 'parses'>; export type SchemaLoader = () => Promise<{ default: SchemaOptionsType; }>; export type SchemasType = Record; export type ChoiceValue = IdNotNull; /** Minimal metadata extracted from a model schema. */ export interface ModelMeta { verboseName: string; verboseNamePlural: string; } interface BaseChoiceItem { value: ChoiceValue; display_name: string; } interface TypedChoiceItem { value: T; display_name: string; } export type ChoiceItem = T extends void ? BaseChoiceItem : TypedChoiceItem; type FieldChild = { children?: SchemaType; choices?: ChoiceItem[]; }; type FieldType = 'string' | 'email' | 'date' | 'datetime' | 'nested object' | 'field' | 'choice' | 'boolean' | 'decimal' | 'float' | 'file' | 'file upload' | 'image' | 'image upload' | 'number' | 'integer' | 'password' | 'array' | 'list' | 'slug' | 'multiple choice' | 'point' | 'polygon' | 'multipoint' | 'multipolygon' | 'geometrycollection'; export type GeometryFieldType = Extract; /** A tile-layer configuration for the geometry map picker. */ export interface LayerConfig { title: string; url: string; attribution: string; } export interface Field { type: FieldType; label: string; child?: FieldChild; children?: SchemaType; model_default?: GenericValue; model_required?: boolean; choices?: ChoiceItem[]; max_length?: number | string; max_digits?: number; decimal_places?: number; read_only?: boolean; is_currency?: boolean; prefix?: string; suffix?: string; related_editable?: boolean; validators_regex?: Item[]; many?: boolean; date_views?: DateView[]; required?: boolean; ui_required?: boolean; disabled?: boolean; help_text?: string; model_multiline?: boolean; max_file_size?: number; allowed_mime_types?: string[]; style?: Record; pattern_format?: string; conditional_visible?: string[] | string[][]; } export type GridEnrichedBySchemaColDef = Omit>, 'field'> & { field: FieldKey; isIndexField?: boolean; creatable?: boolean; disabled?: boolean; orderable?: boolean; patternFormat?: string; uiRequired?: boolean; }; export type CustomColumnOperations = (p: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef | Promise>; type BaseMinWidthFields = Record; type TypedMinWidthFields = Partial, number>> & { actions?: number; }; export type MinWidthFields = T extends void ? BaseMinWidthFields : TypedMinWidthFields; type BaseSumRowsTotals = Record; type TypedSumRowsTotals = Partial, number>>; export type SumRowsTotals = T extends void ? BaseSumRowsTotals : TypedSumRowsTotals; export interface DataSchemaColumnsType { data: Item[]; schema: SchemaType; modelOptions: ModelOptionsType; rowCount?: number; sumRowsTotals?: null | SumRowsTotals; columns?: GridEnrichedBySchemaColDef[]; } export interface ItemSchemaColumnsType { data: Item; schema: SchemaType; modelOptions: ModelOptionsType; columns?: GridEnrichedBySchemaColDef[]; } export interface CommonFieldProps { value?: GenericValue; multiline?: boolean; setValue?: UseFormSetValue>; getValues?: UseFormGetValues>; fieldKey?: FieldKey; labelKey?: FieldKey; index?: number; optionsAC?: OptionsAC; optionsModel?: FieldKey; getOptionLabel?: (option: Item | string) => string; renderOption?: (props: React.HTMLAttributes, option: Item, state: AutocompleteRenderOptionState) => React.ReactNode; onEditModel?: (x: OnEditModelType) => void; fieldsLayout?: FormFieldLayout[]; multiple?: boolean; sx?: SxProps; options?: Item[]; isSemaphoric?: boolean; label?: string; onValueChange?: (x: GenericValue) => void; decimalScale?: number; type?: React.HTMLInputTypeAttribute; autoComplete?: string; minRows?: number; optionIdKey?: string; optionLabelKey?: string; disabled?: boolean; } type BaseFieldsProps = Record; type TypedFieldsProps = Partial, CommonFieldProps>>; export type FieldsProps = T extends void ? BaseFieldsProps : TypedFieldsProps; type BaseDetailFieldsProps = Record; type TypedDetailFieldsProps = Partial, DetailCommonFieldProps>>; export type DetailFieldsProps = T extends void ? BaseDetailFieldsProps : TypedDetailFieldsProps; export type FieldBySchemaProps = Omit, 'value' | 'onEditModel'> & { onEditModel?: (x: OnEditModelType) => void; name: FieldKey; schema: SchemaType; control: Control, GenericValue, Item>; errors: FieldErrors>; autoFocus?: boolean; }; export interface DetailFieldBySchemaProps extends ExtraSxCommonFieldProps { fieldKey: FieldKey; fieldSchema?: Field; value: FormattedItemValue; optionIdKey?: string; optionLabelKey?: string; } type LinkProps = { to: string | object; href?: string; state?: object; className?: string; style?: React.CSSProperties; children?: React.ReactNode; } & React.AnchorHTMLAttributes; export type LinkComponentType = React.ComponentType; export type FieldList = T extends void ? string[] : Extract[]; export type AddParametersToEnd GenericValue, TParameters extends [...args: GenericValue]> = (...args: [...Parameters, ...TParameters]) => ReturnType; export type ActionType = 'editInline' | 'remove' | 'edit' | 'view'; /** * A custom per-row action supplied directly in the `actions` prop, as an object * (icon + click handler) instead of one of the built-in string action types. * When rendered in the grid's actions column it becomes a single icon button * that calls `handleClick(rowItem)` when clicked. Works for any list/grid, * regardless of whether row selection (checkboxes) is enabled. */ export interface CustomRowAction { icon: ReactElement; label?: string; handleClick: (item: Item | undefined) => void; } /** Actions accepted by the grid's actions column: built-in strings or a custom * row action object. */ export type RowAction = ActionType | CustomRowAction; /** Read-only grid actions: navigation 'edit'/'view' or a custom row action (no 'editInline'/'remove'). */ export type NonEditableRowAction = 'edit' | 'view' | CustomRowAction; export interface CustomAction { key: string; icon: ReactElement; label: string; handleClick: (item: Item | undefined) => undefined; } export type BulkUpdateData = (newData: Item[]) => Promise<{ id: Id; success: boolean; }[]>; export type BulkDeleteData = (ids: Id[]) => Promise<{ id: Id; success: boolean; }[]>; export type OnSelectActionCustom = (selectedData: Item[], bulkUpdateData: BulkUpdateData) => void; export type OnSelectActionTypes = OnSelectActionCustom | 'bulkDelete' | 'bulkCreate'; export type OnSelectActions = { title: string; action: OnSelectActionTypes; }; interface BaseCustomFormField { key: string; CustomElement: (x: CommonFieldProps) => JSX.Element; } interface TypedCustomFormField { key: FieldKey; CustomElement: (x: CommonFieldProps) => JSX.Element; } export type CustomFormField = T extends void ? BaseCustomFormField : TypedCustomFormField; interface BaseFormFieldLayout { title?: string; rows?: (string | (string | CustomFormField)[] | CustomFormField)[]; customLabels?: Record; CustomElement?: React.ReactNode; } interface TypedFormFieldLayout { title?: string; rows?: (FieldKey | (FieldKey | CustomFormField)[] | CustomFormField)[]; customLabels?: Partial, string>>; CustomElement?: React.ReactNode; } export type FormFieldLayout = T extends void ? BaseFormFieldLayout : TypedFormFieldLayout; type BaseCustomFormFieldLayouts = Record; type TypedCustomFormFieldLayouts = Partial, BaseFormFieldLayout[]>>; export type CustomFormFieldLayouts = T extends void ? BaseCustomFormFieldLayouts : TypedCustomFormFieldLayouts; export declare enum FormSaveActions { EXIT_ON_SAVE = "exitOnSave", SAVE_AND_CONTINUE = "saveAndContinue", SAVE_AND_CREATE_NEW = "saveAndCreateNew" } export interface ExtraSxCommonFieldProps { sxSection?: SxProps; sxSectionTitle?: SxProps; sxRow?: SxProps; sxRowMultiple?: SxProps; sxField?: SxProps; sxLabel?: SxProps; sxValue?: SxProps; sxValueList?: SxProps; sxValueListItem?: SxProps; sxValueListItemText?: SxProps; } export type DetailCommonFieldProps = CommonFieldProps & ExtraSxCommonFieldProps; interface CustomDetailField { key: FieldKey; CustomElement: (x: DetailCommonFieldProps) => JSX.Element; } export type DetailFieldLayoutRows = (FieldKey | (FieldKey | CustomDetailField)[] | CustomDetailField)[]; export interface DetailFieldLayout extends ExtraSxCommonFieldProps { title?: string; rows?: DetailFieldLayoutRows; CustomElement?: React.ReactNode; isAccordion?: boolean; isAccordionOpen?: boolean; } export interface DetailBySchemaProps extends ExtraSxCommonFieldProps { values: Item; schema: SchemaType; columns: GridEnrichedBySchemaColDef[]; loading?: boolean; editLink?: string; editLabel?: string; fieldsLayout?: DetailFieldLayout[]; hiddenFields?: FieldList; fieldsProps?: DetailFieldsProps; elevation?: number; } export type OnSuccessEvent = React.MouseEventHandler; export interface TargetApiParams { path: string; serverEndPoint: ServerEndPoint | null; data: Item; id: Id; contentType?: 'application/json' | 'multipart/form-data'; } export type TargetApiParamsLocal = Omit, 'serverEndPoint'>; export type TargetApiPostParams = Omit, 'id'>; export type TargetApiPostParamsLocal = Omit, 'serverEndPoint'>; interface BaseSumRowsType { rows: SumRowsItem[]; severity?: AlertColor; } interface TypedSumRowsType { rows: SumRowsItem[]; severity?: AlertColor; } export type SumRowsType = T extends void ? BaseSumRowsType : TypedSumRowsType; interface SumRowsItem { field: FieldKey; prefix?: string; suffix?: string; isCount?: boolean; } export interface GetGenericModelListProps { model: string; serverEndPoint: ServerEndPoint | null; id?: Id; relatedModel?: string; relatedModelId?: Id; columnFields?: FieldList; creatableFields?: FieldList; disabledFields?: FieldList; isInBatches?: boolean; loadedSchema?: SchemaType; loadedModelOptions?: ModelOptionsType; page?: number; filter?: GridFilterModel; queryParams?: string[]; sort?: GridSortModel; sumRows?: SumRowsType; schemas?: SchemasType; } export type GetGenericModelListPropsLocal = Omit, 'serverEndPoint'>; export type GetGenericModelProps = { model: string; serverEndPoint: ServerEndPoint | null; id?: Id; relatedModel?: string; relatedModelId?: string; schemas?: SchemasType; }; export type GetGenericModelPropsLocal = Omit; export type FormattedItemValue = { title: string; valueStr: string; value: GenericValue; }; export type FormattedItem = Record; export type formattedData = { item: FormattedItem; id: Id; }[]; export interface MobileListRenderItemInfo { item: FormattedItem; index: number; id: Id; } export type MobileListRenderItemType = (info: MobileListRenderItemInfo) => ReactElement | null; export type GenericYupValidator = Yup.StringSchema | Yup.NumberSchema | Yup.AnyObjectSchema | Yup.MixedSchema | Yup.DateSchema | Yup.BooleanSchema | Yup.ArraySchema; type BaseExtraValidators = Record; type TypedExtraValidators = Partial, GenericYupValidator>>; export type ExtraValidators = T extends void ? BaseExtraValidators : TypedExtraValidators; export type ConditionalVisible = { target: string; source: string; sourceValue: GenericValue; }; export type { OnEditModelType }; export interface UpdateDataBySchema { model: string; modelObjectId: Id; data: Item; schema: SchemaType; path?: string | null; } export type FormWatchObject = T extends void ? Item : Partial; export interface WatchEditingRowValuesProps { rowEditingValues?: Partial>; setRowEditingValues: (p: Partial>) => void; } export type WatchEditingRowValues = (p: WatchEditingRowValuesProps) => void | Promise; //# sourceMappingURL=index.d.ts.map