static-cms/core/src/interface.ts

902 lines
21 KiB
TypeScript
Raw Normal View History

import type { LanguageName } from '@uiw/codemirror-extensions-langs';
2022-10-20 11:57:30 -04:00
import type { PropertiesSchema } from 'ajv/dist/types/json-schema';
import type {
ComponentType,
FunctionComponent,
JSXElementConstructor,
ReactElement,
ReactNode,
} from 'react';
2022-09-28 20:04:00 -06:00
import type { t, TranslateProps as ReactPolyglotTranslateProps } from 'react-polyglot';
2022-10-20 11:57:30 -04:00
import type { MediaFile as BackendMediaFile } from './backend';
import type { EditorControlProps } from './components/Editor/EditorControlPane/EditorControl';
import type {
SORT_DIRECTION_ASCENDING,
SORT_DIRECTION_DESCENDING,
SORT_DIRECTION_NONE,
} from './constants';
2022-10-20 11:57:30 -04:00
import type { formatExtensions } from './formats/formats';
import type { I18N_STRUCTURE } from './lib/i18n';
import type { AllowedEvent } from './lib/registry';
2022-09-28 20:04:00 -06:00
import type Cursor from './lib/util/Cursor';
2022-10-20 11:57:30 -04:00
import type AssetProxy from './valueObjects/AssetProxy';
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export interface Pages {
[collection: string]: { isFetching?: boolean; page?: number; ids: string[] };
}
2022-09-28 20:04:00 -06:00
2022-11-05 11:37:39 -04:00
export type SortableField<EF extends BaseField = UnknownField> =
2022-10-20 11:57:30 -04:00
| {
key: string;
name: string;
label: string;
}
| ({
key: string;
2022-11-05 11:37:39 -04:00
} & Field<EF>);
2022-10-20 11:57:30 -04:00
export interface SortObject {
key: string;
direction: SortDirection;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export type SortMap = Record<string, SortObject>;
export type Sort = Record<string, SortMap>;
export type FilterMap = ViewFilter & { active?: boolean };
export type GroupMap = ViewGroup & { active?: boolean };
export type Filter = Record<string, Record<string, FilterMap>>; // collection.field.active
export type Group = Record<string, Record<string, GroupMap>>; // collection.field.active
export interface GroupOfEntries {
id: string;
label: string;
value: string | boolean | undefined;
paths: Set<string>;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export type ObjectValue = {
[key: string]: ValueOrNestedValue;
2022-09-28 20:04:00 -06:00
};
2022-10-20 11:57:30 -04:00
export type ValueOrNestedValue =
| string
| number
| boolean
| string[]
2022-11-04 17:41:12 -04:00
| (string | number)[]
2022-10-20 11:57:30 -04:00
| null
| undefined
| ObjectValue
| ObjectValue[];
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export type EntryData = ObjectValue | undefined | null;
export interface Entry<T = ObjectValue> {
2022-10-20 11:57:30 -04:00
collection: string;
2022-09-28 20:04:00 -06:00
slug: string;
2022-10-20 11:57:30 -04:00
path: string;
partial: boolean;
2022-09-28 20:04:00 -06:00
raw: string;
data: T | undefined | null;
2022-10-20 11:57:30 -04:00
label: string | null;
isModification: boolean | null;
mediaFiles: MediaFile[];
author: string;
updatedOn: string;
status?: string;
newRecord?: boolean;
isFetching?: boolean;
isPersisting?: boolean;
isDeleting?: boolean;
error?: string;
i18n?: {
[locale: string]: {
data: EntryData;
};
};
}
export type Entities = Record<string, Entry>;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export interface FieldError {
type: string;
message?: string;
}
export interface FieldsErrors {
[field: string]: FieldError[];
}
2022-11-05 12:30:54 -04:00
export interface FieldValidationMethodProps<T = unknown, F extends BaseField = UnknownField> {
2022-10-20 11:57:30 -04:00
field: F;
value: T | undefined | null;
t: t;
}
2022-11-05 12:30:54 -04:00
export type FieldValidationMethod<T = unknown, F extends BaseField = UnknownField> = (
2022-10-20 11:57:30 -04:00
props: FieldValidationMethodProps<T, F>,
) => false | FieldError | Promise<false | FieldError>;
export interface EntryDraft {
entry: Entry;
fieldsErrors: FieldsErrors;
}
export interface FilterRule {
value: string;
field: string;
}
export interface EditorConfig {
preview?: boolean;
frame?: boolean;
}
2022-11-05 11:37:39 -04:00
export interface CollectionFile<EF extends BaseField = UnknownField> {
2022-10-20 11:57:30 -04:00
name: string;
label: string;
file: string;
2022-11-05 11:37:39 -04:00
fields: Field<EF>[];
2022-10-20 11:57:30 -04:00
label_singular?: string;
description?: string;
media_folder?: string;
public_folder?: string;
i18n?: boolean | I18nInfo;
editor?: EditorConfig;
2022-10-20 11:57:30 -04:00
}
interface Nested {
summary?: string;
depth: number;
}
export interface I18nSettings {
currentLocale: string;
defaultLocale: string;
locales: string[];
}
export type Format = keyof typeof formatExtensions;
2022-11-05 11:37:39 -04:00
export interface i18nCollection<EF extends BaseField = UnknownField>
extends Omit<Collection<EF>, 'i18n'> {
i18n: Required<Collection<EF>>['i18n'];
2022-10-20 11:57:30 -04:00
}
export interface BaseCollection {
2022-10-20 11:57:30 -04:00
name: string;
description?: string;
icon?: string;
isFetching?: boolean;
summary?: string;
filter?: FilterRule;
label_singular?: string;
label: string;
sortable_fields?: SortableFields;
view_filters?: ViewFilter[];
view_groups?: ViewGroup[];
i18n?: boolean | I18nInfo;
hide?: boolean;
editor?: EditorConfig;
identifier_field?: string;
path?: string;
2022-10-20 11:57:30 -04:00
extension?: string;
format?: Format;
frontmatter_delimiter?: string | [string, string];
slug?: string;
media_folder?: string;
public_folder?: string;
}
export interface FilesCollection<EF extends BaseField = UnknownField> extends BaseCollection {
files: CollectionFile<EF>[];
}
export interface FolderCollection<EF extends BaseField = UnknownField> extends BaseCollection {
folder: string;
fields: Field<EF>[];
2022-10-20 11:57:30 -04:00
create?: boolean;
delete?: boolean;
nested?: Nested;
}
export type Collection<EF extends BaseField = UnknownField> =
| FilesCollection<EF>
| FolderCollection<EF>;
2022-11-05 11:37:39 -04:00
export type Collections<EF extends BaseField = UnknownField> = Record<string, Collection<EF>>;
2022-10-20 11:57:30 -04:00
export interface MediaLibraryInstance {
show: (args: {
id?: string;
value?: string | string[];
config: Record<string, unknown>;
allowMultiple?: boolean;
imagesOnly?: boolean;
}) => void;
hide?: () => void;
onClearControl?: (args: { id: string }) => void;
onRemoveControl?: (args: { id: string }) => void;
enableStandalone: () => boolean;
}
export type MediaFile = BackendMediaFile & { key?: string };
export interface DisplayURLState {
isFetching: boolean;
url?: string;
err?: Error;
}
export type TranslatedProps<T> = T & ReactPolyglotTranslateProps;
export type GetAssetFunction<F extends BaseField = UnknownField> = (
path: string,
field?: F,
) => Promise<AssetProxy>;
2022-10-20 11:57:30 -04:00
2022-11-05 12:30:54 -04:00
export interface WidgetControlProps<T, F extends BaseField = UnknownField> {
collection: Collection<F>;
config: Config<F>;
2022-10-20 11:57:30 -04:00
entry: Entry;
field: F;
fieldsErrors: FieldsErrors;
submitted: boolean;
forList: boolean;
getAsset: GetAssetFunction<F>;
2022-10-20 11:57:30 -04:00
isDisabled: boolean;
isFieldDuplicate: EditorControlProps['isFieldDuplicate'];
isFieldHidden: EditorControlProps['isFieldHidden'];
label: string;
locale: string | undefined;
mediaPaths: Record<string, string | string[]>;
onChange: (value: T | null | undefined) => void;
clearMediaControl: EditorControlProps['clearMediaControl'];
openMediaLibrary: EditorControlProps['openMediaLibrary'];
removeInsertedMedia: EditorControlProps['removeInsertedMedia'];
removeMediaControl: EditorControlProps['removeMediaControl'];
i18n: I18nSettings | undefined;
hasErrors: boolean;
2022-09-28 20:04:00 -06:00
path: string;
2022-10-20 11:57:30 -04:00
query: EditorControlProps['query'];
t: t;
value: T | undefined | null;
}
2022-09-28 20:04:00 -06:00
export interface WidgetPreviewProps<T = unknown, F extends BaseField = UnknownField> {
2022-11-05 12:30:54 -04:00
config: Config<F>;
collection: Collection<F>;
2022-10-20 11:57:30 -04:00
entry: Entry;
field: RenderedField<F>;
getAsset: GetAssetFunction<F>;
2022-10-20 11:57:30 -04:00
value: T | undefined | null;
}
2022-09-28 20:04:00 -06:00
export type WidgetPreviewComponent<T = unknown, F extends BaseField = UnknownField> =
2022-10-20 11:57:30 -04:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| ReactElement<unknown, string | JSXElementConstructor<any>>
2022-11-05 12:30:54 -04:00
| ComponentType<WidgetPreviewProps<T, F>>;
2022-09-28 20:04:00 -06:00
export type WidgetsFor<P = EntryData> = <K extends keyof P>(
name: K,
) => P[K] extends Array<infer U>
? {
data: U | null;
widgets: Record<keyof U, ReactNode>;
}[]
: {
data: P[K] | null;
widgets: Record<keyof P[K], ReactNode>;
};
2022-11-05 12:30:54 -04:00
export interface TemplatePreviewProps<T = EntryData, EF extends BaseField = UnknownField> {
2022-11-05 11:37:39 -04:00
collection: Collection<EF>;
fields: Field<EF>[];
entry: Entry<T>;
document: Document | undefined | null;
window: Window | undefined | null;
getAsset: GetAssetFunction<Field<EF>>;
widgetFor: (name: T extends EntryData ? string : keyof T) => ReactNode;
widgetsFor: WidgetsFor<T>;
}
export type TemplatePreviewComponent<
T = EntryData,
EF extends BaseField = UnknownField,
> = ComponentType<TemplatePreviewProps<T, EF>>;
2022-09-28 20:04:00 -06:00
2022-11-05 12:30:54 -04:00
export interface WidgetOptions<T = unknown, F extends BaseField = UnknownField> {
2022-10-20 11:57:30 -04:00
validator?: Widget<T, F>['validator'];
getValidValue?: Widget<T, F>['getValidValue'];
2022-12-06 08:31:07 -05:00
getDefaultValue?: Widget<T, F>['getDefaultValue'];
2022-10-20 11:57:30 -04:00
schema?: Widget<T, F>['schema'];
}
2022-09-28 20:04:00 -06:00
2022-11-05 12:30:54 -04:00
export interface Widget<T = unknown, F extends BaseField = UnknownField> {
control: ComponentType<WidgetControlProps<T, F>>;
preview?: WidgetPreviewComponent<T, F>;
2022-10-20 11:57:30 -04:00
validator: FieldValidationMethod<T, F>;
getValidValue: (value: T | undefined | null) => T | undefined | null;
2022-12-06 08:31:07 -05:00
getDefaultValue?: (defaultValue: T | undefined | null, field: F) => T;
2022-10-20 11:57:30 -04:00
schema?: PropertiesSchema<unknown>;
}
2022-11-05 12:30:54 -04:00
export interface WidgetParam<T = unknown, F extends BaseField = UnknownField> {
2022-09-28 20:04:00 -06:00
name: string;
2022-11-05 12:30:54 -04:00
controlComponent: Widget<T, F>['control'];
previewComponent?: Widget<T, F>['preview'];
2022-10-20 11:57:30 -04:00
options?: WidgetOptions<T, F>;
}
export interface PersistOptions {
newEntry?: boolean;
commitMessage: string;
collectionName?: string;
status?: string;
}
2022-09-28 20:04:00 -06:00
export interface ImplementationEntry {
data: string;
file: { path: string; label?: string; id?: string | null; author?: string; updatedOn?: string };
}
2022-10-20 11:57:30 -04:00
export interface DisplayURLObject {
id: string;
2022-09-28 20:04:00 -06:00
path: string;
2022-10-20 11:57:30 -04:00
}
export type DisplayURL = DisplayURLObject | string;
2022-09-28 20:04:00 -06:00
export interface ImplementationMediaFile {
name: string;
id: string;
size?: number;
displayURL?: DisplayURL;
path: string;
draft?: boolean;
url?: string;
file?: File;
2022-10-20 11:57:30 -04:00
field?: Field;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface DataFile {
path: string;
slug: string;
raw: string;
newPath?: string;
}
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export interface BackendEntry {
dataFiles: DataFile[];
assets: AssetProxy[];
}
export interface Credentials {
token: string | {};
refresh_token?: string;
}
export type User = Credentials & {
backendName?: string;
login?: string;
name?: string;
avatar_url?: string;
2022-09-28 20:04:00 -06:00
};
2022-10-20 11:57:30 -04:00
export interface ImplementationFile {
id?: string | null | undefined;
label?: string;
path: string;
}
export interface AuthenticatorConfig {
site_id?: string;
base_url?: string;
auth_endpoint?: string;
auth_token_endpoint?: string;
auth_url?: string;
app_id?: string;
clearHash?: () => void;
}
export abstract class BackendClass {
// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor(_config: Config, _options: BackendInitializerOptions) {}
abstract authComponent(): (props: TranslatedProps<AuthenticationPageProps>) => JSX.Element;
abstract restoreUser(user: User): Promise<User>;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
abstract authenticate(credentials: Credentials): Promise<User>;
abstract logout(): Promise<void> | void | null;
abstract getToken(): Promise<string | null>;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
abstract getEntry(path: string): Promise<ImplementationEntry>;
abstract entriesByFolder(
2022-09-28 20:04:00 -06:00
folder: string,
extension: string,
depth: number,
2022-10-20 11:57:30 -04:00
): Promise<ImplementationEntry[]>;
abstract entriesByFiles(files: ImplementationFile[]): Promise<ImplementationEntry[]>;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
abstract getMediaDisplayURL(displayURL: DisplayURL): Promise<string>;
abstract getMedia(folder?: string): Promise<ImplementationMediaFile[]>;
abstract getMediaFile(path: string): Promise<ImplementationMediaFile>;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
abstract persistEntry(entry: BackendEntry, opts: PersistOptions): Promise<void>;
abstract persistMedia(file: AssetProxy, opts: PersistOptions): Promise<ImplementationMediaFile>;
abstract deleteFiles(paths: string[], commitMessage: string): Promise<unknown>;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
abstract allEntriesByFolder(
2022-09-28 20:04:00 -06:00
folder: string,
extension: string,
depth: number,
2022-10-20 11:57:30 -04:00
): Promise<ImplementationEntry[]>;
abstract traverseCursor(
2022-09-28 20:04:00 -06:00
cursor: Cursor,
action: string,
2022-10-20 11:57:30 -04:00
): Promise<{ entries: ImplementationEntry[]; cursor: Cursor }>;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
abstract isGitBackend(): boolean;
abstract status(): Promise<{
2022-09-28 20:04:00 -06:00
auth: { status: boolean };
api: { status: boolean; statusPage: string };
}>;
}
2022-10-20 11:57:30 -04:00
export interface LocalePhrasesRoot {
[property: string]: LocalePhrases;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export type LocalePhrases = string | { [property: string]: LocalePhrases };
2022-09-28 20:04:00 -06:00
2022-11-04 17:41:12 -04:00
export type CustomIcon = FunctionComponent;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export type WidgetValueSerializer = {
serialize: (value: ValueOrNestedValue) => ValueOrNestedValue;
deserialize: (value: ValueOrNestedValue) => ValueOrNestedValue;
};
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export type MediaLibraryOptions = Record<string, unknown>;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export interface MediaLibraryInitOptions {
options: Record<string, unknown> | undefined;
handleInsert: (url: string | string[]) => void;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface MediaLibraryExternalLibrary {
name: string;
config?: MediaLibraryOptions;
init: ({ options, handleInsert }: MediaLibraryInitOptions) => Promise<MediaLibraryInstance>;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface MediaLibraryInternalOptions {
allow_multiple?: boolean;
choose_url?: boolean;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export type MediaLibrary = MediaLibraryExternalLibrary | MediaLibraryInternalOptions;
2022-11-04 17:41:12 -04:00
export type BackendType = 'git-gateway' | 'github' | 'gitlab' | 'bitbucket' | 'test-repo' | 'proxy';
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export type MapWidgetType = 'Point' | 'LineString' | 'Polygon';
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export interface SelectWidgetOptionObject {
2022-09-28 20:04:00 -06:00
label: string;
2022-10-20 11:57:30 -04:00
value: string;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export type AuthScope = 'repo' | 'public_repo';
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export type SlugEncoding = 'unicode' | 'ascii';
2022-09-28 20:04:00 -06:00
2022-11-05 23:55:37 -04:00
export type RenderedField<F extends BaseField = UnknownField> = Omit<F, 'fields'> & {
fields?: ReactNode[];
};
2022-10-20 11:57:30 -04:00
export interface BaseField {
2022-09-28 20:04:00 -06:00
name: string;
label?: string;
required?: boolean;
hint?: string;
pattern?: [string, string];
i18n?: boolean | 'translate' | 'duplicate' | 'none';
comment?: string;
widget: string;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface BooleanField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'boolean';
default?: boolean;
}
2022-10-20 11:57:30 -04:00
export interface CodeField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'code';
2022-10-20 11:57:30 -04:00
default?: string | { [key: string]: string };
2022-09-28 20:04:00 -06:00
default_language?: string;
allow_language_selection?: boolean;
keys?: { code: string; lang: string };
output_code_only?: boolean;
2022-10-20 11:57:30 -04:00
code_mirror_config: {
extra_keys?: Record<string, string>;
} & Record<string, unknown>;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface ColorField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'color';
default?: string;
2022-10-20 11:57:30 -04:00
allow_input?: boolean;
enable_alpha?: boolean;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface DateTimeField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'datetime';
default?: string;
format?: string;
date_format?: boolean | string;
time_format?: boolean | string;
picker_utc?: boolean;
2022-10-20 11:57:30 -04:00
}
export interface FileOrImageField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'file' | 'image';
default?: string;
2022-10-20 11:57:30 -04:00
media_library?: MediaLibrary;
media_folder?: string;
public_folder?: string;
2022-09-28 20:04:00 -06:00
}
2022-11-05 11:37:39 -04:00
export interface ObjectField<EF extends BaseField = UnknownField> extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'object';
collapsed?: boolean;
summary?: string;
2022-11-05 11:37:39 -04:00
fields: Field<EF>[];
2022-09-28 20:04:00 -06:00
}
2022-11-05 11:37:39 -04:00
export interface ListField<EF extends BaseField = UnknownField> extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'list';
2022-10-20 11:57:30 -04:00
default?: ObjectValue[];
2022-09-28 20:04:00 -06:00
allow_add?: boolean;
collapsed?: boolean;
summary?: string;
label_singular?: string;
2022-11-05 11:37:39 -04:00
fields?: Field<EF>[];
2022-09-28 20:04:00 -06:00
max?: number;
min?: number;
add_to_top?: boolean;
2022-10-20 11:57:30 -04:00
types?: ObjectField[];
2022-11-02 15:42:21 -04:00
type_key?: string;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface MapField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'map';
default?: string;
decimals?: number;
2022-10-20 11:57:30 -04:00
type?: MapWidgetType;
height?: string;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface MarkdownField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'markdown';
default?: string;
2022-10-20 11:57:30 -04:00
media_library?: MediaLibrary;
media_folder?: string;
public_folder?: string;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface NumberField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'number';
default?: string | number;
value_type?: 'int' | 'float' | string;
min?: number;
max?: number;
step?: number;
}
2022-10-20 11:57:30 -04:00
export interface SelectField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'select';
2022-11-04 17:41:12 -04:00
default?: string | number | (string | number)[];
2022-09-28 20:04:00 -06:00
2022-11-04 17:41:12 -04:00
options: (string | number)[] | SelectWidgetOptionObject[];
2022-09-28 20:04:00 -06:00
multiple?: boolean;
min?: number;
max?: number;
}
2022-10-20 11:57:30 -04:00
export interface RelationField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'relation';
default?: string | string[];
collection: string;
value_field: string;
search_fields: string[];
file?: string;
display_fields?: string[];
multiple?: boolean;
2022-10-20 11:57:30 -04:00
min?: number;
max?: number;
2022-09-28 20:04:00 -06:00
options_length?: number;
2022-10-20 11:57:30 -04:00
}
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export interface HiddenField extends BaseField {
2022-09-28 20:04:00 -06:00
widget: 'hidden';
2022-10-20 11:57:30 -04:00
default?: ValueOrNestedValue;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface StringOrTextField extends BaseField {
2022-09-28 20:04:00 -06:00
// This is the default widget, so declaring its type is optional.
widget: 'string' | 'text';
2022-09-28 20:04:00 -06:00
default?: string;
}
2022-11-05 11:37:39 -04:00
export interface UnknownField extends BaseField {
widget: 'unknown';
}
export type Field<EF extends BaseField = UnknownField> =
2022-10-20 11:57:30 -04:00
| BooleanField
| CodeField
| ColorField
| DateTimeField
| FileOrImageField
| ListField
| MapField
| MarkdownField
| NumberField
| ObjectField
| RelationField
| SelectField
| HiddenField
2022-11-05 11:37:39 -04:00
| StringOrTextField
| EF;
2022-09-28 20:04:00 -06:00
export interface ViewFilter {
id: string;
label: string;
field: string;
pattern: string;
}
export interface ViewGroup {
id: string;
label: string;
field: string;
pattern?: string;
}
export type SortDirection =
| typeof SORT_DIRECTION_ASCENDING
| typeof SORT_DIRECTION_DESCENDING
| typeof SORT_DIRECTION_NONE;
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export interface SortableFieldsDefault {
2022-09-28 20:04:00 -06:00
field: string;
2022-09-28 22:10:31 -04:00
direction?: SortDirection;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface SortableFields {
default?: SortableFieldsDefault;
2022-09-28 20:04:00 -06:00
fields: string[];
}
2022-10-20 11:57:30 -04:00
export interface Backend {
name: BackendType;
2022-09-28 20:04:00 -06:00
repo?: string;
branch?: string;
api_root?: string;
site_domain?: string;
base_url?: string;
auth_endpoint?: string;
app_id?: string;
auth_type?: 'implicit' | 'pkce';
proxy_url?: string;
2022-10-20 11:57:30 -04:00
large_media_url?: string;
login?: boolean;
use_large_media_transforms_in_media_library?: boolean;
identity_url?: string;
gateway_url?: string;
2022-11-04 17:41:12 -04:00
auth_scope?: AuthScope;
2022-09-28 20:04:00 -06:00
commit_messages?: {
create?: string;
update?: string;
delete?: string;
uploadMedia?: string;
deleteMedia?: string;
};
}
2022-10-20 11:57:30 -04:00
export interface Slug {
encoding?: SlugEncoding;
2022-09-28 20:04:00 -06:00
clean_accents?: boolean;
sanitize_replacement?: string;
}
2022-10-20 11:57:30 -04:00
export interface LocalBackend {
2022-09-28 20:04:00 -06:00
url?: string;
allowed_hosts?: string[];
}
2022-11-05 11:37:39 -04:00
export interface Config<EF extends BaseField = UnknownField> {
2022-10-20 11:57:30 -04:00
backend: Backend;
2022-11-05 11:37:39 -04:00
collections: Collection<EF>[];
2022-09-28 20:04:00 -06:00
locale?: string;
2022-10-20 11:57:30 -04:00
site_id?: string;
2022-09-28 20:04:00 -06:00
site_url?: string;
display_url?: string;
2022-10-20 11:57:30 -04:00
base_url?: string;
2022-09-28 20:04:00 -06:00
logo_url?: string;
media_folder?: string;
public_folder?: string;
media_folder_relative?: boolean;
2022-10-20 11:57:30 -04:00
media_library?: MediaLibrary;
2022-09-28 20:04:00 -06:00
load_config_file?: boolean;
2022-10-20 11:57:30 -04:00
integrations?: Integration[];
slug?: Slug;
i18n?: I18nInfo;
local_backend?: boolean | LocalBackend;
editor?: EditorConfig;
2022-09-28 20:04:00 -06:00
search?: boolean;
}
2022-11-05 11:37:39 -04:00
export interface InitOptions<EF extends BaseField = UnknownField> {
config: Config<EF>;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface BackendInitializerOptions {
updateUserCredentials: (credentials: Credentials) => void;
}
2022-09-28 20:04:00 -06:00
2022-10-20 11:57:30 -04:00
export interface BackendInitializer {
init: (config: Config, options: BackendInitializerOptions) => BackendClass;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export interface EventData {
entry: Entry;
author: { login: string | undefined; name: string };
}
2022-11-04 17:41:12 -04:00
export type EventListenerOptions = Record<string, unknown>;
export type EventListenerHandler = (
data: EventData,
options: EventListenerOptions,
) => Promise<EntryData | undefined | null | void>;
2022-10-20 11:57:30 -04:00
export interface EventListener {
name: AllowedEvent;
2022-11-04 17:41:12 -04:00
handler: EventListenerHandler;
2022-10-20 11:57:30 -04:00
}
2022-11-04 17:41:12 -04:00
export interface AdditionalLinkOptions {
icon?: string;
2022-11-04 17:41:12 -04:00
}
2022-10-20 11:57:30 -04:00
export interface AdditionalLink {
id: string;
title: string;
2022-11-04 17:41:12 -04:00
data: string | FunctionComponent;
options?: AdditionalLinkOptions;
2022-10-20 11:57:30 -04:00
}
export interface AuthenticationPageProps {
onLogin: (user: User) => void;
inProgress?: boolean;
base_url?: string;
siteId?: string;
authEndpoint?: string;
config: Config;
error?: string | undefined;
clearHash?: () => void;
2022-09-28 20:04:00 -06:00
}
2022-10-20 11:57:30 -04:00
export type Integration = {
collections?: '*' | string[];
2022-11-04 17:41:12 -04:00
} & AlgoliaIntegration;
2022-10-20 11:57:30 -04:00
export type SearchIntegrationProvider = 'algolia';
export interface AlgoliaIntegration extends AlgoliaConfig {
provider: 'algolia';
}
export interface AlgoliaConfig {
hooks: ['search' | 'listEntries'];
applicationID: string;
apiKey: string;
indexPrefix?: string;
}
export interface SearchResponse {
entries: Entry[];
pagination: number;
}
export interface SearchQueryResponse {
hits: Entry[];
query: string;
}
export interface EditorPersistOptions {
createNew?: boolean;
duplicate?: boolean;
}
export interface I18nInfo {
locales: string[];
defaultLocale: string;
structure?: I18N_STRUCTURE;
}
export interface ProcessedCodeLanguage {
label: string;
identifiers: string[];
codemirror_mode: LanguageName;
2022-10-20 11:57:30 -04:00
codemirror_mime_type: string;
}
export interface FileMetadata {
2022-10-20 11:57:30 -04:00
author: string;
updatedOn: string;
}
export interface PreviewStyleOptions {
raw?: boolean;
}
export interface PreviewStyle {
value: string;
raw: boolean;
}
export interface MarkdownPluginFactoryProps {
2022-11-05 12:30:54 -04:00
config: Config<MarkdownField>;
field: MarkdownField;
mode: 'editor' | 'preview';
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type MarkdownPluginFactory = (props: MarkdownPluginFactoryProps) => any;
export interface MarkdownToolbarItemsFactoryProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
imageToolbarButton: any;
}
export type MarkdownToolbarItemsFactory = (
props: MarkdownToolbarItemsFactoryProps,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) => (string | any)[][];
export interface MarkdownEditorOptions {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
initialEditType?: any;
height?: string;
toolbarItems?: MarkdownToolbarItemsFactory;
plugins?: MarkdownPluginFactory[];
}
export enum CollectionType {
FOLDER,
FILES,
}
2022-12-04 22:15:59 -05:00
export type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;