UNPKG

tinacms

Version:

[![GitHub license](https://img.shields.io/github/license/tinacms/tinacms?color=blue)](https://github.com/tinacms/tinacms/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/tinacms.svg?style=flat)](https://www.npmjs.com/package/tinacms) [![Bui

100 lines (99 loc) 2.79 kB
import { Form } from './react-tinacms'; import { TinaCMS } from './tina-cms'; type FormListItem = { type: 'document'; path: string; formId: string; subItems: FormListItem[]; } | { type: 'list'; label: string; }; type FormList = { label: string; id: string; items: FormListItem[]; formIds: string[]; }; type Breadcrumb = { label: string; formId: string; formName: string; namespace: string[]; }; export type TinaAction = { type: 'forms:add'; value: Form; } | { type: 'forms:remove'; value: string; } | { type: 'forms:clear'; } | { type: 'form-lists:add'; value: FormList; } | { type: 'form-lists:remove'; value: string; } | { type: 'forms:set-active-form-id'; value: string; } | { type: 'forms:set-active-field-name'; value: { formId: string; fieldName: string; }; } | { type: 'form-lists:clear'; } | { type: 'set-edit-mode'; value: 'visual' | 'basic'; } | { type: 'increment-operation-index'; } | { type: 'set-quick-editing-supported'; value: boolean; } | { type: 'set-quick-editing-enabled'; value?: boolean; } | { type: 'toggle-quick-editing-enabled'; } | { type: 'toggle-edit-state'; } | { type: 'sidebar:set-display-state'; value: TinaState['sidebarDisplayState'] | 'openOrFull'; } | { type: 'sidebar:set-loading-state'; value: boolean; }; export interface TinaState { breadcrumbs: Breadcrumb[]; activeFormId: string | null; /** * Forms are wrapped here because we need `activeFieldName` to be reactive, so adding it as a propery * on the Form class won't work, unfortunately. So "form" at this level means tinaForm + activeFieldName * * The activeFieldName should probably not be in global state, and having it here means that forms * only work if they're registered as part of this top-level state. At the risk of touching too much code * all at once, putting state this high up at least allows us to not have to touch the Form class too much. * Longer term, replaceing Form with something stateful seems like the right approach */ forms: { activeFieldName?: string | null; tinaForm: Form; }[]; formLists: FormList[]; editingMode: 'visual' | 'basic'; isLoadingContent: boolean; quickEditSupported: boolean; sidebarDisplayState: 'closed' | 'open' | 'fullscreen'; } export declare const initialState: (cms: TinaCMS) => TinaState; export declare function tinaReducer(state: TinaState, action: TinaAction): TinaState; export declare function calculateBreadcrumbs(forms: { activeFieldName?: string | null; tinaForm: Form; }[], activeFormId: string, activeFieldName?: string): Breadcrumb[]; export {};