UNPKG

4.76 kBTypeScriptView Raw
1import type { MetaSysProps, MetaLinkProps, DefaultElements, MakeRequest } from '../common-types';
2import type { DefinedParameters } from './widget-parameters';
3interface WidgetConfig {
4 /**
5 * Type of the widget used
6 */
7 widgetNamespace?: string;
8 /**
9 * ID of the widget used
10 */
11 widgetId?: string;
12 /**
13 * Instance parameter values
14 */
15 settings?: DefinedParameters;
16}
17export interface Control extends WidgetConfig {
18 /**
19 * ID of the customized field
20 */
21 fieldId: string;
22}
23export interface GroupControl extends WidgetConfig {
24 /**
25 * ID of the customized field group
26 */
27 groupId: string;
28}
29export interface FieldGroupItem {
30 groupId: string;
31 name: string;
32 items: EditorLayoutItem[];
33}
34export interface FieldItem {
35 fieldId: string;
36}
37export type EditorLayoutItem = FieldItem | FieldGroupItem;
38export interface Editor {
39 /**
40 * Type of the widget used
41 */
42 widgetNamespace: string;
43 /**
44 * ID of the widget used
45 */
46 widgetId: string;
47 /**
48 * Widget will be enabled if disabled property is missing
49 */
50 disabled?: boolean;
51 /**
52 * Instance parameter values
53 */
54 settings?: DefinedParameters;
55}
56export interface SidebarItem {
57 /**
58 * Type of the widget used
59 */
60 widgetNamespace: string;
61 /**
62 * ID of the widget used
63 */
64 widgetId: string;
65 /**
66 * Widget will be enabled if disabled property is missing
67 */
68 disabled?: boolean;
69 /**
70 * Instance parameter values
71 */
72 settings?: DefinedParameters;
73}
74export type EditorInterfaceProps = {
75 sys: MetaSysProps & {
76 space: {
77 sys: MetaLinkProps;
78 };
79 environment: {
80 sys: MetaLinkProps;
81 };
82 contentType: {
83 sys: MetaLinkProps;
84 };
85 };
86 /**
87 * Array of fields and their associated widgetId
88 */
89 controls?: Control[];
90 /**
91 * Array of field groups and their associated widgetId
92 */
93 groupControls?: GroupControl[];
94 /**
95 * Array of editors. Defaults will be used if property is missing.
96 */
97 editors?: Editor[];
98 /**
99 * Legacy singular editor override
100 */
101 editor?: Editor;
102 /**
103 * Array of editor layout field groups
104 */
105 editorLayout?: FieldGroupItem[];
106 /**
107 * Array of sidebar widgets. Defaults will be used if property is missing.
108 */
109 sidebar?: SidebarItem[];
110};
111export interface EditorInterface extends EditorInterfaceProps, DefaultElements<EditorInterfaceProps> {
112 /**
113 * Gets a control for a specific field
114 * @return control object for specific field
115 * ```javascript
116 * const contentful = require('contentful-management')
117 *
118 * const client = contentful.createClient({
119 * accessToken: '<content_management_api_key>'
120 * })
121 *
122 * client.getSpace('<space_id>')
123 * .then((space) => space.getEnvironment('<environment_id>'))
124 * .then((environment) => environment.getContentType('<contentType_id>'))
125 * .then((contentType) => contentType.getEditorInterface())
126 * .then((editorInterface) => {
127 * control = editorInterface.getControlForField('<field-id>')
128 * console.log(control)
129 * })
130 * .catch(console.error)
131 * ```
132 */
133 getControlForField(id: string): null | Control;
134 /**
135 * Sends an update to the server with any changes made to the object's properties
136 * @return Object returned from the server with updated changes.
137 * ```javascript
138 * const contentful = require('contentful-management')
139 *
140 * const client = contentful.createClient({
141 * accessToken: '<content_management_api_key>'
142 * })
143 *
144 * client.getSpace('<space_id>')
145 * .then((space) => space.getEnvironment('<environment_id>'))
146 * .then((environment) => environment.getContentType('<contentType_id>'))
147 * .then((contentType) => contentType.getEditorInterface())
148 * .then((editorInterface) => {
149 * editorInterface.controls[0] = { "fieldId": "title", "widgetId": "singleLine"}
150 * editorInterface.editors = [
151 * { "widgetId": "custom-widget", "widgetNamespace": "app" }
152 * ]
153 * return editorInterface.update()
154 * })
155 * .catch(console.error)
156 * ```
157 */
158 update(): Promise<EditorInterface>;
159}
160/**
161 * @private
162 */
163export declare function wrapEditorInterface(makeRequest: MakeRequest, data: EditorInterfaceProps): EditorInterface;
164/**
165 * @private
166 */
167export declare const wrapEditorInterfaceCollection: (makeRequest: MakeRequest, data: import("../common-types").CollectionProp<EditorInterfaceProps>) => import("../common-types").Collection<EditorInterface, EditorInterfaceProps>;
168export {};