API reference
Common props for all extensionsAnchor
export interface ExtensionPropsBase {
context: {
project: {
id: string;
name: string;
mgmtApi: string;
mgmtToken: string;
};
environment: {
id: string;
name: string;
endpoint: string;
authToken: string;
};
};
openDialog: OpenDialog;
openAssetPicker: () => Promise<null | (Asset & Record<string, unknown>)>;
showToast: ShowToast;
historyReplace: (url: string | (currentUrl: string) => string) => Promise<void>;
historyPush: (url: string | (currentUrl: string) => string) => Promise<void>;
redirectParent: (location: string | Location) => Promise<void>;
}
Field extensionAnchor
function useFieldExtension(): FieldExtensionProps;
export interface FieldExtensionProps extends ExtensionPropsBase {
name: string;
locale?: string;
entryId: string | null;
isTableCell: boolean;
value: any;
onBlur: <T extends HTMLElement = HTMLElement>(
event?: FocusEvent<T>,
) => Promise<void>;
onChange: <T extends HTMLElement = HTMLElement>(
event: ChangeEvent<T> | any,
) => Promise<void>;
onFocus: <T extends HTMLElement = HTMLElement>(
event?: FocusEvent<T>,
) => Promise<void>;
meta: {
active: boolean;
error: any;
touched: boolean;
};
form: Form;
field: {
id: string;
apiId: string;
description: string | null;
displayName: string;
isList: boolean;
isLocalized?: boolean;
isRequired?: boolean;
isUnique?: boolean;
isPreview: boolean;
type: FieldExtensionType;
};
model: Model;
extension: {
config: Record<string, any>;
fieldConfig: Record<string, any>;
tableConfig: Record<string, any>;
};
isExpanded: boolean;
expand: (expand: boolean | ((isExpanded: boolean) => boolean)) => void;
}
function useFormSidebarExtension(): FormSidebarExtensionProps;
export interface FormSidebarExtensionProps extends ExtensionPropsBase {
extension: {
config: Record<string, any>;
sidebarConfig: Record<string, any>;
};
form: Form;
model: Model;
allLocales: Locale[];
stages: Stage[];
entry?: {
id: string | null;
createdBy?: User;
updatedBy?: User;
createdAt?: string;
updatedAt?: string;
};
}
Additional typesAnchor
interface Model {
apiId: string;
apiIdPlural: string;
id: string;
description: string | null;
displayName: string;
isLocalized: boolean;
}
interface Form {
change: <Value = any>(name: string, value: Value) => Promise<void>;
changeBulk: (values: Record<string, any>) => Promise<void>;
getState: <Values = Record<string, any>>() => Promise<FormState<Values>>;
getFieldState: <Value = any>(fieldName: string) => Promise<FieldState<Value>>;
subscribeToFieldState: <Value = any>(
name: string,
callback: (state: FieldState<Value>) => any,
subscription: FieldSubscription,
) => Promise<() => any>;
subscribeToFormState: <Values = Record<string, any>>(
callback: Subscriber<FormState<Values>>,
subscription: FormSubscription,
) => Promise<() => any>;
setFieldsVisibility: (
arg:
| VisibilityMap
| ((currentVisibilityMap: VisibilityMap) => VisibilityMap),
) => void;
}
interface Locale {
apiId: string;
id: string;
displayName: string;
isDefault: boolean;
}
interface Stage {
id: string;
apiId: string;
color: string;
colorPaletteId: keyof typeof StageColorPalette;
backgroundColor: string;
displayName: string;
description?: string | null | undefined;
isSystem: boolean;
position: number;
}
export const StageColorPalette = {
PINK: 'PINK',
PURPLE: 'PURPLE',
ORANGE: 'ORANGE',
RED: 'RED',
BROWN: 'BROWN',
TEAL: 'TEAL',
GREEN: 'GREEN',
YELLOW: 'YELLOW',
} as const;
interface User {
id: string;
kind: keyof typeof UserKind;
name: string;
picture: string | null;
isActive: boolean;
}
export const UserKind = {
MEMBER: 'MEMBER',
PAT: 'PAT',
PUBLIC: 'PUBLIC',
WEBHOOK: 'WEBHOOK',
} as const;
export type OpenDialog = <
DialogReturn = any,
DialogProps = Record<string, any>,
>(
src: string,
props?: {
disableOverlayClick?: boolean;
maxWidth?: string;
ariaLabel?: string;
} & DialogProps,
) => Promise<DialogReturn | null>;
export type ShowToast = (options: ToastOptions) => Promise<Id>;
export type ToastOptions = {
title: string;
description?: string;
variantColor: keyof typeof ToastVariantColor;
id?: Id;
isClosable?: boolean;
position?: keyof typeof ToastPosition;
duration?: number;
};
type Id = number | string;
export const ToastVariantColor = {
success: 'success',
error: 'error',
warning: 'warning',
info: 'info',
primary: 'primary',
dark: 'dark',
publish: 'publish',
} as const;
export const ToastPosition = {
'top-right': 'top-right',
'top-center': 'top-center',
'top-left': 'top-left',
'bottom-right': 'bottom-right',
'bottom-center': 'bottom-center',
'bottom-left': 'bottom-left',
} as const;