2019-12-18 18:16:02 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2019-12-02 12:04:07 +01:00
|
|
|
declare module 'netlify-cms-core' {
|
|
|
|
import React, { ComponentType } from 'react';
|
2020-06-02 09:04:06 +01:00
|
|
|
import { List, Map } from 'immutable';
|
2019-12-02 12:04:07 +01:00
|
|
|
|
2019-12-18 18:16:02 +02:00
|
|
|
export type CmsBackendType = 'git-gateway' | 'github' | 'gitlab' | 'bitbucket' | 'test-repo';
|
2019-12-02 12:04:07 +01:00
|
|
|
|
2019-12-18 18:16:02 +02:00
|
|
|
export type CmsMapWidgetType = 'Point' | 'LineString' | 'Polygon';
|
2019-12-02 12:04:07 +01:00
|
|
|
|
2019-12-18 18:16:02 +02:00
|
|
|
export type CmsMarkdownWidgetButton =
|
|
|
|
| 'bold'
|
2019-12-02 12:04:07 +01:00
|
|
|
| 'italic'
|
|
|
|
| 'code'
|
|
|
|
| 'link'
|
|
|
|
| 'heading-one'
|
|
|
|
| 'heading-two'
|
|
|
|
| 'heading-three'
|
|
|
|
| 'heading-four'
|
|
|
|
| 'heading-five'
|
|
|
|
| 'heading-six'
|
|
|
|
| 'quote'
|
|
|
|
| 'code-block'
|
|
|
|
| 'bulleted-list'
|
|
|
|
| 'numbered-list';
|
|
|
|
|
2020-06-01 09:42:11 +02:00
|
|
|
export interface CmsSelectWidgetOptionObject {
|
|
|
|
label: string;
|
|
|
|
value: any;
|
|
|
|
}
|
2019-12-02 12:04:07 +01:00
|
|
|
|
2019-12-18 18:16:02 +02:00
|
|
|
export type CmsCollectionFormatType =
|
|
|
|
| 'yml'
|
2019-12-02 12:04:07 +01:00
|
|
|
| 'yaml'
|
|
|
|
| 'toml'
|
|
|
|
| 'json'
|
|
|
|
| 'frontmatter'
|
|
|
|
| 'yaml-frontmatter'
|
|
|
|
| 'toml-frontmatter'
|
|
|
|
| 'json-frontmatter';
|
|
|
|
|
|
|
|
export type CmsAuthScope = 'repo' | 'public_repo';
|
|
|
|
|
|
|
|
export type CmsPublishMode = 'simple' | 'editorial_workflow';
|
|
|
|
|
|
|
|
export type CmsSlugEncoding = 'unicode' | 'ascii';
|
|
|
|
|
|
|
|
export interface CmsField {
|
|
|
|
name: string;
|
|
|
|
label?: string;
|
|
|
|
widget?: string;
|
|
|
|
required?: boolean;
|
2020-06-01 09:42:11 +02:00
|
|
|
hint?: string;
|
|
|
|
pattern?: [string, string];
|
|
|
|
default?: any;
|
|
|
|
|
|
|
|
/** If widget === "code" */
|
|
|
|
default_language?: string;
|
|
|
|
allow_language_selection?: boolean;
|
|
|
|
keys?: { code: string; lang: string };
|
|
|
|
output_code_only?: boolean;
|
|
|
|
|
|
|
|
/** If widget === "datetime" */
|
|
|
|
format?: string;
|
|
|
|
dateFormat?: boolean | string;
|
|
|
|
timeFormat?: boolean | string;
|
|
|
|
pickerUtc?: boolean;
|
|
|
|
|
|
|
|
/** If widget === "file" || widget === "image" */
|
|
|
|
media_library?: CmsMediaLibrary;
|
|
|
|
allow_multiple?: boolean;
|
|
|
|
config?: any;
|
|
|
|
|
|
|
|
/** If widget === "object" || widget === "list" */
|
|
|
|
fields?: CmsField[];
|
|
|
|
collapsed?: boolean;
|
|
|
|
|
|
|
|
/** If widget === "list" */
|
|
|
|
field?: CmsField;
|
|
|
|
allow_add?: boolean;
|
|
|
|
summary?: string;
|
|
|
|
minimize_collapsed?: boolean;
|
|
|
|
label_singular?: string;
|
|
|
|
types?: CmsField[];
|
|
|
|
|
|
|
|
/** If widget === "map" */
|
|
|
|
decimals?: number;
|
|
|
|
type?: CmsMapWidgetType;
|
|
|
|
|
|
|
|
/** If widget === "markdown" */
|
|
|
|
minimal?: boolean;
|
|
|
|
buttons?: CmsMarkdownWidgetButton[];
|
|
|
|
editorComponents?: string[];
|
|
|
|
|
|
|
|
/** If widget === "number" */
|
|
|
|
valueType?: 'int' | 'float' | string;
|
|
|
|
step?: number;
|
|
|
|
|
|
|
|
/** If widget === "number" || widget === "select" */
|
|
|
|
min?: number;
|
|
|
|
max?: number;
|
|
|
|
|
|
|
|
/** If widget === "relation" || widget === "select" */
|
|
|
|
multiple?: boolean;
|
|
|
|
|
|
|
|
/** If widget === "relation" */
|
|
|
|
collection?: string;
|
|
|
|
valueField?: string;
|
|
|
|
searchFields?: string[];
|
|
|
|
file?: string;
|
|
|
|
displayFields?: string[];
|
|
|
|
optionsLength?: number;
|
|
|
|
|
|
|
|
/** If widget === "select" */
|
|
|
|
options?: string[] | CmsSelectWidgetOptionObject[];
|
2019-12-02 12:04:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CmsCollectionFile {
|
|
|
|
name: string;
|
|
|
|
label: string;
|
|
|
|
file: string;
|
|
|
|
fields: CmsField[];
|
|
|
|
label_singular?: string;
|
|
|
|
description?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CmsCollection {
|
|
|
|
name: string;
|
|
|
|
label: string;
|
|
|
|
label_singular?: string;
|
|
|
|
description?: string;
|
|
|
|
folder?: string;
|
|
|
|
files?: CmsCollectionFile[];
|
|
|
|
identifier_field?: string;
|
|
|
|
summary?: string;
|
|
|
|
slug?: string;
|
|
|
|
preview_path?: string;
|
|
|
|
preview_path_date_field?: string;
|
|
|
|
create?: boolean;
|
2020-06-01 09:42:11 +02:00
|
|
|
delete?: boolean;
|
2019-12-02 12:04:07 +01:00
|
|
|
editor?: {
|
|
|
|
preview?: boolean;
|
|
|
|
};
|
2020-06-01 09:42:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* It accepts the following values: yml, yaml, toml, json, md, markdown, html
|
|
|
|
*
|
|
|
|
* You may also specify a custom extension not included in the list above, by specifying the format value.
|
|
|
|
*/
|
|
|
|
extension?: string;
|
2019-12-02 12:04:07 +01:00
|
|
|
format?: CmsCollectionFormatType;
|
2020-06-01 09:42:11 +02:00
|
|
|
|
2019-12-02 12:04:07 +01:00
|
|
|
frontmatter_delimiter?: string[] | string;
|
|
|
|
fields?: CmsField[];
|
2020-06-01 09:42:11 +02:00
|
|
|
filter?: { field: string; value: any };
|
|
|
|
path?: string;
|
|
|
|
media_folder?: string;
|
|
|
|
public_folder?: string;
|
|
|
|
sortableFields?: string[];
|
2019-12-02 12:04:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CmsBackend {
|
|
|
|
name: CmsBackendType;
|
|
|
|
auth_scope?: CmsAuthScope;
|
|
|
|
open_authoring?: boolean;
|
2020-04-29 11:52:01 -04:00
|
|
|
repo?: string;
|
|
|
|
branch?: string;
|
|
|
|
api_root?: string;
|
|
|
|
site_domain?: string;
|
|
|
|
base_url?: string;
|
|
|
|
auth_endpoint?: string;
|
2019-12-02 12:04:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CmsSlug {
|
|
|
|
encoding?: CmsSlugEncoding;
|
|
|
|
clean_accents?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CmsConfig {
|
|
|
|
backend: CmsBackend;
|
|
|
|
collections: CmsCollection[];
|
|
|
|
locale?: string;
|
|
|
|
site_url?: string;
|
|
|
|
display_url?: string;
|
|
|
|
logo_url?: string;
|
|
|
|
show_preview_links?: boolean;
|
|
|
|
media_folder?: string;
|
|
|
|
public_folder?: string;
|
|
|
|
media_folder_relative?: boolean;
|
|
|
|
media_library?: CmsMediaLibrary;
|
|
|
|
publish_mode?: CmsPublishMode;
|
|
|
|
slug?: CmsSlug;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface InitOptions {
|
|
|
|
config: CmsConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface EditorComponentField {
|
|
|
|
name: string;
|
|
|
|
label: string;
|
|
|
|
widget: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface EditorComponentOptions {
|
|
|
|
id: string;
|
|
|
|
label: string;
|
|
|
|
fields: EditorComponentField[];
|
|
|
|
pattern: RegExp;
|
2020-06-01 09:42:11 +02:00
|
|
|
fromBlock: (match: RegExpMatchArray) => any;
|
|
|
|
toBlock: (data: any) => string;
|
|
|
|
toPreview: (data: any) => string;
|
2019-12-02 12:04:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface PreviewStyleOptions {
|
|
|
|
raw: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PreviewStyle extends PreviewStyleOptions {
|
|
|
|
value: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type CmsBackendClass = any; // TODO: type properly
|
|
|
|
|
|
|
|
export interface CmsRegistryBackend {
|
|
|
|
init: (args: any) => CmsBackendClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CmsWidgetParam {
|
|
|
|
name: string;
|
2020-04-20 15:15:04 +02:00
|
|
|
controlComponent: ComponentType<any>;
|
|
|
|
previewComponent?: ComponentType<any>;
|
2019-12-02 12:04:07 +01:00
|
|
|
globalStyles: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CmsWidget {
|
2020-04-20 15:15:04 +02:00
|
|
|
control: ComponentType<any>;
|
|
|
|
preview?: ComponentType<any>;
|
2019-12-02 12:04:07 +01:00
|
|
|
globalStyles?: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type CmsWidgetValueSerializer = any; // TODO: type properly
|
|
|
|
|
|
|
|
export type CmsMediaLibraryOptions = any; // TODO: type properly
|
|
|
|
|
|
|
|
export interface CmsMediaLibrary {
|
|
|
|
name: string;
|
|
|
|
config?: CmsMediaLibraryOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type CmsLocalePhrases = any; // TODO: type properly
|
|
|
|
|
|
|
|
export interface CmsRegistry {
|
|
|
|
backends: {
|
|
|
|
[name: string]: CmsRegistryBackend;
|
|
|
|
};
|
|
|
|
templates: {
|
2020-04-20 15:15:04 +02:00
|
|
|
[name: string]: ComponentType<any>;
|
2019-12-02 12:04:07 +01:00
|
|
|
};
|
|
|
|
previewStyles: PreviewStyle[];
|
|
|
|
widgets: {
|
|
|
|
[name: string]: CmsWidget;
|
|
|
|
};
|
2020-04-20 15:15:04 +02:00
|
|
|
editorComponents: Map<string, ComponentType<any>>;
|
2019-12-02 12:04:07 +01:00
|
|
|
widgetValueSerializers: {
|
|
|
|
[name: string]: CmsWidgetValueSerializer;
|
|
|
|
};
|
|
|
|
mediaLibraries: CmsMediaLibrary[];
|
|
|
|
locales: {
|
|
|
|
[name: string]: CmsLocalePhrases;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-01 09:42:11 +02:00
|
|
|
type GetAssetFunction = (
|
|
|
|
asset: string,
|
|
|
|
) => { url: string; path: string; field?: any; fileObj: File };
|
|
|
|
|
|
|
|
export type PreviewTemplateComponentProps = {
|
|
|
|
entry: Map<string, any>;
|
|
|
|
collection: Map<string, any>;
|
|
|
|
widgetFor: (name: any, fields?: any, values?: any, fieldsMetaData?: any) => JSX.Element | null;
|
|
|
|
widgetsFor: (name: any) => any;
|
|
|
|
getAsset: GetAssetFunction;
|
|
|
|
boundGetAsset: (collection: any, path: any) => GetAssetFunction;
|
|
|
|
fieldsMetaData: Map<string, any>;
|
|
|
|
config: Map<string, any>;
|
|
|
|
fields: List<Map<string, any>>;
|
|
|
|
isLoadingAsset: boolean;
|
|
|
|
};
|
|
|
|
|
2019-12-02 12:04:07 +01:00
|
|
|
export interface CMS {
|
|
|
|
getBackend: (name: string) => CmsRegistryBackend | undefined;
|
2020-04-20 15:15:04 +02:00
|
|
|
getEditorComponents: () => Map<string, ComponentType<any>>;
|
2019-12-02 12:04:07 +01:00
|
|
|
getLocale: (locale: string) => CmsLocalePhrases | undefined;
|
|
|
|
getMediaLibrary: (name: string) => CmsMediaLibrary | undefined;
|
|
|
|
getPreviewStyles: () => PreviewStyle[];
|
2020-06-01 09:42:11 +02:00
|
|
|
getPreviewTemplate: (name: string) => ComponentType<PreviewTemplateComponentProps> | undefined;
|
2019-12-02 12:04:07 +01:00
|
|
|
getWidget: (name: string) => CmsWidget | undefined;
|
|
|
|
getWidgetValueSerializer: (widgetName: string) => CmsWidgetValueSerializer | undefined;
|
|
|
|
init: (options?: InitOptions) => void;
|
|
|
|
registerBackend: (name: string, backendClass: CmsBackendClass) => void;
|
|
|
|
registerEditorComponent: (options: EditorComponentOptions) => void;
|
|
|
|
registerLocale: (locale: string, phrases: CmsLocalePhrases) => void;
|
|
|
|
registerMediaLibrary: (mediaLibrary: CmsMediaLibrary, options?: CmsMediaLibraryOptions) => void;
|
|
|
|
registerPreviewStyle: (filePath: string, options?: PreviewStyleOptions) => void;
|
2020-06-01 09:42:11 +02:00
|
|
|
registerPreviewTemplate: (
|
|
|
|
name: string,
|
|
|
|
component: ComponentType<PreviewTemplateComponentProps>,
|
|
|
|
) => void;
|
2019-12-18 18:16:02 +02:00
|
|
|
registerWidget: (
|
|
|
|
widget: string | CmsWidgetParam,
|
2020-04-20 15:15:04 +02:00
|
|
|
control?: ComponentType<any>,
|
|
|
|
preview?: ComponentType<any>,
|
2019-12-18 18:16:02 +02:00
|
|
|
) => void;
|
|
|
|
registerWidgetValueSerializer: (
|
|
|
|
widgetName: string,
|
|
|
|
serializer: CmsWidgetValueSerializer,
|
|
|
|
) => void;
|
2019-12-02 12:04:07 +01:00
|
|
|
resolveWidget: (name: string) => CmsWidget | undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const NetlifyCmsCore: CMS;
|
|
|
|
|
|
|
|
export default NetlifyCmsCore;
|
2019-12-18 18:16:02 +02:00
|
|
|
}
|