datocms-plugin-sdk 0.3.8 → 0.3.24-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/connect.js +20 -8
- package/dist/cjs/connect.js.map +1 -1
- package/dist/cjs/guards.js +2 -1
- package/dist/cjs/guards.js.map +1 -1
- package/dist/esm/connect.d.ts +45 -26
- package/dist/esm/connect.js +21 -9
- package/dist/esm/connect.js.map +1 -1
- package/dist/esm/guards.d.ts +4 -1
- package/dist/esm/guards.js +1 -0
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/types.d.ts +591 -313
- package/dist/types/connect.d.ts +45 -26
- package/dist/types/guards.d.ts +4 -1
- package/dist/types/types.d.ts +591 -313
- package/package.json +2 -2
- package/types.json +3018 -1425
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
|
-
import { Account, Field, Item, ModelBlock, Plugin, PluginAttributes, Role, Site, SsoUser, Upload, User } from './SiteApiSchema';
|
|
1
|
+
import { Account, Field, Item, ModelBlock, Plugin, PluginAttributes, Role, Site, SsoUser, Upload, UploadCreateSchema, User } from './SiteApiSchema';
|
|
2
|
+
export declare type Icon = string | {
|
|
3
|
+
type: 'svg';
|
|
4
|
+
viewBox: string;
|
|
5
|
+
content: string;
|
|
6
|
+
};
|
|
2
7
|
/** A tab to be displayed in the top-bar of the UI */
|
|
3
8
|
export declare type MainNavigationTab = {
|
|
4
9
|
/** Label to be shown. Must be unique. */
|
|
5
10
|
label: string;
|
|
6
|
-
/**
|
|
7
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
|
|
13
|
+
* `"address-book"`) or a custom SVG definition. To maintain visual
|
|
14
|
+
* consistency with the rest of the interface, try to use FontAwesome icons
|
|
15
|
+
* whenever possible.
|
|
16
|
+
*/
|
|
17
|
+
icon: Icon;
|
|
8
18
|
/** ID of the page linked to the tab */
|
|
9
19
|
pointsTo: {
|
|
10
20
|
pageId: string;
|
|
11
21
|
};
|
|
12
22
|
/**
|
|
13
|
-
* Expresses where you want to place the tab in the top-bar. If not specified,
|
|
14
|
-
* will be placed after the standard tabs provided by DatoCMS itself.
|
|
23
|
+
* Expresses where you want to place the tab in the top-bar. If not specified,
|
|
24
|
+
* the tab will be placed after the standard tabs provided by DatoCMS itself.
|
|
15
25
|
*/
|
|
16
|
-
placement?: [
|
|
26
|
+
placement?: [
|
|
27
|
+
'before' | 'after',
|
|
28
|
+
'content' | 'mediaArea' | 'apiExplorer' | 'settings'
|
|
29
|
+
];
|
|
17
30
|
/**
|
|
18
|
-
* If different plugins specify the same `placement` for their tabs, they will
|
|
19
|
-
* displayed by ascending `rank`. If you want to specify an explicit value
|
|
20
|
-
* make sure to offer a way for final users to customize it inside
|
|
21
|
-
* form, otherwise the hardcoded value you choose might
|
|
31
|
+
* If different plugins specify the same `placement` for their tabs, they will
|
|
32
|
+
* be displayed by ascending `rank`. If you want to specify an explicit value
|
|
33
|
+
* for `rank`, make sure to offer a way for final users to customize it inside
|
|
34
|
+
* the plugin's settings form, otherwise the hardcoded value you choose might
|
|
35
|
+
* clash with the one of another plugin! *
|
|
22
36
|
*/
|
|
23
37
|
rank?: number;
|
|
24
38
|
};
|
|
@@ -26,16 +40,22 @@ export declare type MainNavigationTab = {
|
|
|
26
40
|
export declare type SettingsAreaSidebarItem = {
|
|
27
41
|
/** Label to be shown. Must be unique. */
|
|
28
42
|
label: string;
|
|
29
|
-
/**
|
|
30
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
|
|
45
|
+
* `"address-book"`) or a custom SVG definition. To maintain visual
|
|
46
|
+
* consistency with the rest of the interface, try to use FontAwesome icons
|
|
47
|
+
* whenever possible.
|
|
48
|
+
*/
|
|
49
|
+
icon: Icon;
|
|
31
50
|
/** ID of the page linked to the item */
|
|
32
51
|
pointsTo: {
|
|
33
52
|
pageId: string;
|
|
34
53
|
};
|
|
35
54
|
};
|
|
36
55
|
/**
|
|
37
|
-
* The sidebar in the Settings Area presents a number of pages grouped by topic.
|
|
38
|
-
* object represents a new group to be added in the sideebar to the
|
|
56
|
+
* The sidebar in the Settings Area presents a number of pages grouped by topic.
|
|
57
|
+
* This object represents a new group to be added in the sideebar to the
|
|
58
|
+
* standard ones DatoCMS provides.
|
|
39
59
|
*/
|
|
40
60
|
export declare type SettingsAreaSidebarItemGroup = {
|
|
41
61
|
/** Label to be shown. Must be unique. */
|
|
@@ -43,67 +63,80 @@ export declare type SettingsAreaSidebarItemGroup = {
|
|
|
43
63
|
/** The list of items it contains * */
|
|
44
64
|
items: SettingsAreaSidebarItem[];
|
|
45
65
|
/**
|
|
46
|
-
* Expresses where you want the group to be placed inside the sidebar. If not
|
|
47
|
-
* the item will be placed after the standard items provided by
|
|
66
|
+
* Expresses where you want the group to be placed inside the sidebar. If not
|
|
67
|
+
* specified, the item will be placed after the standard items provided by
|
|
68
|
+
* DatoCMS itself.
|
|
48
69
|
*/
|
|
49
70
|
placement?: [
|
|
50
71
|
'before' | 'after',
|
|
51
72
|
('environment' | 'project' | 'permissions' | 'webhooks' | 'deployment' | 'sso' | 'auditLog' | 'usage')
|
|
52
73
|
];
|
|
53
74
|
/**
|
|
54
|
-
* If different plugins specify the same `placement` for their sections, they
|
|
55
|
-
* displayed by ascending `rank`. If you want to specify an explicit
|
|
56
|
-
* make sure to offer a way for final users to customize it
|
|
57
|
-
* form, otherwise the hardcoded value you choose
|
|
75
|
+
* If different plugins specify the same `placement` for their sections, they
|
|
76
|
+
* will be displayed by ascending `rank`. If you want to specify an explicit
|
|
77
|
+
* value for `rank`, make sure to offer a way for final users to customize it
|
|
78
|
+
* inside the plugin's settings form, otherwise the hardcoded value you choose
|
|
79
|
+
* might clash with the one of another plugin! *
|
|
58
80
|
*/
|
|
59
81
|
rank?: number;
|
|
60
82
|
};
|
|
61
83
|
/**
|
|
62
|
-
* The sidebar in the Content Area presents a number of user-defined menu-items.
|
|
63
|
-
* object represents a new item to be added in the sidebar.
|
|
84
|
+
* The sidebar in the Content Area presents a number of user-defined menu-items.
|
|
85
|
+
* This object represents a new item to be added in the sidebar.
|
|
64
86
|
*/
|
|
65
87
|
export declare type ContentAreaSidebarItem = {
|
|
66
88
|
/** Label to be shown. Must be unique. */
|
|
67
89
|
label: string;
|
|
68
|
-
/**
|
|
69
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
|
|
92
|
+
* `"address-book"`) or a custom SVG definition. To maintain visual
|
|
93
|
+
* consistency with the rest of the interface, try to use FontAwesome icons
|
|
94
|
+
* whenever possible.
|
|
95
|
+
*/
|
|
96
|
+
icon: Icon;
|
|
70
97
|
/** ID of the page linked to the item */
|
|
71
98
|
pointsTo: {
|
|
72
99
|
pageId: string;
|
|
73
100
|
};
|
|
74
101
|
/**
|
|
75
|
-
* Expresses where you want the item to be placed inside the sidebar. If not
|
|
76
|
-
* the item will be placed after the standard items provided by
|
|
102
|
+
* Expresses where you want the item to be placed inside the sidebar. If not
|
|
103
|
+
* specified, the item will be placed after the standard items provided by
|
|
104
|
+
* DatoCMS itself.
|
|
77
105
|
*/
|
|
78
106
|
placement?: ['before' | 'after', 'menuItems' | 'settings'];
|
|
79
107
|
/**
|
|
80
|
-
* If different plugins specify the same `placement` for their panels, they
|
|
81
|
-
* displayed by ascending `rank`. If you want to specify an explicit
|
|
82
|
-
* make sure to offer a way for final users to customize it
|
|
83
|
-
* form, otherwise the hardcoded value you choose
|
|
108
|
+
* If different plugins specify the same `placement` for their panels, they
|
|
109
|
+
* will be displayed by ascending `rank`. If you want to specify an explicit
|
|
110
|
+
* value for `rank`, make sure to offer a way for final users to customize it
|
|
111
|
+
* inside the plugin's settings form, otherwise the hardcoded value you choose
|
|
112
|
+
* might clash with the one of another plugin! *
|
|
84
113
|
*/
|
|
85
114
|
rank?: number;
|
|
86
115
|
};
|
|
87
116
|
export declare type FieldExtensionType = 'editor' | 'addon';
|
|
88
117
|
/**
|
|
89
|
-
* Field extensions extend the basic functionality of DatoCMS when it comes to
|
|
90
|
-
* record's fields to the final user. Depending on the extension type
|
|
91
|
-
* `addon`) they will be shown in different places of the interface.
|
|
118
|
+
* Field extensions extend the basic functionality of DatoCMS when it comes to
|
|
119
|
+
* presenting record's fields to the final user. Depending on the extension type
|
|
120
|
+
* (`editor` or `addon`) they will be shown in different places of the interface.
|
|
92
121
|
*/
|
|
93
122
|
export declare type ManualFieldExtension = {
|
|
94
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* ID of field extension. Will be the first argument for the
|
|
125
|
+
* `renderFieldExtension` function
|
|
126
|
+
*/
|
|
95
127
|
id: string;
|
|
96
128
|
/** Name to be shown when editing fields */
|
|
97
129
|
name: string;
|
|
98
130
|
/**
|
|
99
|
-
* Type of field extension. An `editor` extension replaces the default field
|
|
100
|
-
* DatoCMS provides, while an `addon` extension is placed
|
|
101
|
-
* provide additional info/behaviour. You can
|
|
131
|
+
* Type of field extension. An `editor` extension replaces the default field
|
|
132
|
+
* editor that DatoCMS provides, while an `addon` extension is placed
|
|
133
|
+
* underneath the field editor to provide additional info/behaviour. You can
|
|
134
|
+
* setup multiple field addons for every field.
|
|
102
135
|
*/
|
|
103
136
|
type: FieldExtensionType;
|
|
104
137
|
/**
|
|
105
|
-
* For `editor` extensions: moves the field to the sidebar of the record
|
|
106
|
-
* mimicking a sidebar panel
|
|
138
|
+
* For `editor` extensions: moves the field to the sidebar of the record
|
|
139
|
+
* editing page, mimicking a sidebar panel
|
|
107
140
|
*/
|
|
108
141
|
asSidebarPanel?: boolean | {
|
|
109
142
|
startOpen: boolean;
|
|
@@ -111,8 +144,9 @@ export declare type ManualFieldExtension = {
|
|
|
111
144
|
/** The type of fields that the field extension in compatible with */
|
|
112
145
|
fieldTypes: NonNullable<PluginAttributes['field_types']>;
|
|
113
146
|
/**
|
|
114
|
-
* Whether this field extension needs some configuration options before being
|
|
115
|
-
* in a field or not. Will trigger the
|
|
147
|
+
* Whether this field extension needs some configuration options before being
|
|
148
|
+
* installed in a field or not. Will trigger the
|
|
149
|
+
* `renderManualFieldExtensionConfigScreen` and
|
|
116
150
|
* `validateManualFieldExtensionParameters` methods
|
|
117
151
|
*/
|
|
118
152
|
configurable?: boolean | {
|
|
@@ -127,27 +161,32 @@ export declare type ItemFormSidebarPanelPlacement = [
|
|
|
127
161
|
];
|
|
128
162
|
/** A sidebar panel to be shown inside the record's editing page */
|
|
129
163
|
export declare type ItemFormSidebarPanel = {
|
|
130
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* ID of the panel. Will be the first argument for the
|
|
166
|
+
* `renderItemFormSidebarPanel` function
|
|
167
|
+
*/
|
|
131
168
|
id: string;
|
|
132
169
|
/** Label to be shown on the collapsible sidebar panel handle */
|
|
133
170
|
label: string;
|
|
134
171
|
/**
|
|
135
|
-
* An arbitrary configuration object that will be passed as the `parameters`
|
|
136
|
-
* the second argument of the `renderItemFormSidebarPanel` function
|
|
172
|
+
* An arbitrary configuration object that will be passed as the `parameters`
|
|
173
|
+
* property of the second argument of the `renderItemFormSidebarPanel` function
|
|
137
174
|
*/
|
|
138
175
|
parameters?: Record<string, unknown>;
|
|
139
176
|
/** Whether the sidebar panel will start open or collapsed */
|
|
140
177
|
startOpen?: boolean;
|
|
141
178
|
/**
|
|
142
|
-
* Expresses where you want the item to be placed inside the sidebar. If not
|
|
143
|
-
* the item will be placed after the standard panels provided by
|
|
179
|
+
* Expresses where you want the item to be placed inside the sidebar. If not
|
|
180
|
+
* specified, the item will be placed after the standard panels provided by
|
|
181
|
+
* DatoCMS itself.
|
|
144
182
|
*/
|
|
145
183
|
placement?: ItemFormSidebarPanelPlacement;
|
|
146
184
|
/**
|
|
147
|
-
* If multiple sidebar panels specify the same `placement`, they will be
|
|
148
|
-
* ascending `rank`. If you want to specify an explicit value for
|
|
149
|
-
* offer a way for final users to customize it inside the
|
|
150
|
-
* otherwise the hardcoded value you choose might
|
|
185
|
+
* If multiple sidebar panels specify the same `placement`, they will be
|
|
186
|
+
* sorted by ascending `rank`. If you want to specify an explicit value for
|
|
187
|
+
* `rank`, make sure to offer a way for final users to customize it inside the
|
|
188
|
+
* plugin's settings form, otherwise the hardcoded value you choose might
|
|
189
|
+
* clash with the one of another plugin! *
|
|
151
190
|
*/
|
|
152
191
|
rank?: number;
|
|
153
192
|
/** The initial height to set for the iframe that will render the sidebar panel */
|
|
@@ -155,7 +194,10 @@ export declare type ItemFormSidebarPanel = {
|
|
|
155
194
|
};
|
|
156
195
|
/** A field editor/sidebar forced on a field */
|
|
157
196
|
export declare type EditorOverride = {
|
|
158
|
-
/**
|
|
197
|
+
/**
|
|
198
|
+
* ID of field extension. Will be the first argument for the
|
|
199
|
+
* `renderFieldExtension` function
|
|
200
|
+
*/
|
|
159
201
|
id: string;
|
|
160
202
|
/** Moves the field to the sidebar of the record editing page, mimicking a sidebar panel */
|
|
161
203
|
asSidebarPanel?: boolean | {
|
|
@@ -163,15 +205,16 @@ export declare type EditorOverride = {
|
|
|
163
205
|
placement?: ItemFormSidebarPanelPlacement;
|
|
164
206
|
};
|
|
165
207
|
/**
|
|
166
|
-
* An arbitrary configuration object that will be passed as the `parameters`
|
|
167
|
-
* the second argument of the `renderFieldExtension` function
|
|
208
|
+
* An arbitrary configuration object that will be passed as the `parameters`
|
|
209
|
+
* property of the second argument of the `renderFieldExtension` function
|
|
168
210
|
*/
|
|
169
211
|
parameters?: Record<string, unknown>;
|
|
170
212
|
/**
|
|
171
|
-
* If multiple plugins override a field, the one with the highest `rank` will
|
|
172
|
-
* you want to specify an explicit value for `rank`, make sure to
|
|
173
|
-
* users to customize it inside the plugin's settings
|
|
174
|
-
* value you choose might clash with the one of
|
|
213
|
+
* If multiple plugins override a field, the one with the highest `rank` will
|
|
214
|
+
* win. If you want to specify an explicit value for `rank`, make sure to
|
|
215
|
+
* offer a way for final users to customize it inside the plugin's settings
|
|
216
|
+
* form, otherwise the hardcoded value you choose might clash with the one of
|
|
217
|
+
* another plugin! *
|
|
175
218
|
*/
|
|
176
219
|
rank?: number;
|
|
177
220
|
/** The initial height to set for the iframe that will render the field extension */
|
|
@@ -179,18 +222,22 @@ export declare type EditorOverride = {
|
|
|
179
222
|
};
|
|
180
223
|
/** A field addon extension forced on a field */
|
|
181
224
|
export declare type AddonOverride = {
|
|
182
|
-
/**
|
|
225
|
+
/**
|
|
226
|
+
* ID of field extension. Will be the first argument for the
|
|
227
|
+
* `renderFieldExtension` function
|
|
228
|
+
*/
|
|
183
229
|
id: string;
|
|
184
230
|
/**
|
|
185
|
-
* An arbitrary configuration object that will be passed as the `parameters`
|
|
186
|
-
* the second argument of the `renderFieldExtension` function
|
|
231
|
+
* An arbitrary configuration object that will be passed as the `parameters`
|
|
232
|
+
* property of the second argument of the `renderFieldExtension` function
|
|
187
233
|
*/
|
|
188
234
|
parameters?: Record<string, unknown>;
|
|
189
235
|
/**
|
|
190
|
-
* If multiple addons are present for a field, they will be sorted by
|
|
191
|
-
* If you want to specify an explicit value for `rank`, make
|
|
192
|
-
* final users to customize it inside the plugin's
|
|
193
|
-
* hardcoded value you choose might clash with
|
|
236
|
+
* If multiple addons are present for a field, they will be sorted by
|
|
237
|
+
* ascending `rank`. If you want to specify an explicit value for `rank`, make
|
|
238
|
+
* sure to offer a way for final users to customize it inside the plugin's
|
|
239
|
+
* settings form, otherwise the hardcoded value you choose might clash with
|
|
240
|
+
* the one of another plugin! *
|
|
194
241
|
*/
|
|
195
242
|
rank?: number;
|
|
196
243
|
/** The initial height to set for the iframe that will render the field extension */
|
|
@@ -242,13 +289,35 @@ export declare type Modal = {
|
|
|
242
289
|
/** Width of the modal. Can be a number, or one of the predefined sizes */
|
|
243
290
|
width?: 's' | 'm' | 'l' | 'xl' | 'fullWidth' | number;
|
|
244
291
|
/**
|
|
245
|
-
* An arbitrary configuration object that will be passed as the `parameters`
|
|
246
|
-
* the second argument of the `renderModal` function
|
|
292
|
+
* An arbitrary configuration object that will be passed as the `parameters`
|
|
293
|
+
* property of the second argument of the `renderModal` function
|
|
247
294
|
*/
|
|
248
295
|
parameters?: Record<string, unknown>;
|
|
249
296
|
/** The initial height to set for the iframe that will render the modal content */
|
|
250
297
|
initialHeight?: number;
|
|
251
298
|
};
|
|
299
|
+
/** An additional asset source */
|
|
300
|
+
export declare type AssetSource = {
|
|
301
|
+
/**
|
|
302
|
+
* ID of the asset source. Will be the first argument for the
|
|
303
|
+
* `renderAssetSource` function
|
|
304
|
+
*/
|
|
305
|
+
id: string;
|
|
306
|
+
/** Name of the asset that will be shown to the user */
|
|
307
|
+
name: string;
|
|
308
|
+
/**
|
|
309
|
+
* Icon to be shown alongside the name. Can be a FontAwesome icon name (ie.
|
|
310
|
+
* `"address-book"`) or a custom SVG definition. To maintain visual
|
|
311
|
+
* consistency with the rest of the interface, try to use FontAwesome icons
|
|
312
|
+
* whenever possible.
|
|
313
|
+
*/
|
|
314
|
+
icon: Icon;
|
|
315
|
+
/**
|
|
316
|
+
* Configuration options for the modal that will be opened to select a media
|
|
317
|
+
* file from this source
|
|
318
|
+
*/
|
|
319
|
+
modal?: Pick<Modal, 'width' | 'initialHeight'>;
|
|
320
|
+
};
|
|
252
321
|
/** A toast notification to present to the user */
|
|
253
322
|
export declare type Toast<CtaValue = unknown> = {
|
|
254
323
|
/** Message of the notification */
|
|
@@ -259,14 +328,17 @@ export declare type Toast<CtaValue = unknown> = {
|
|
|
259
328
|
cta?: {
|
|
260
329
|
/** Label for the button */
|
|
261
330
|
label: string;
|
|
262
|
-
/**
|
|
331
|
+
/**
|
|
332
|
+
* The value to be returned by the `customToast` promise if the button is
|
|
333
|
+
* clicked by the user
|
|
334
|
+
*/
|
|
263
335
|
value: CtaValue;
|
|
264
336
|
};
|
|
265
337
|
/** Whether the toast is to be automatically closed if the user changes page */
|
|
266
338
|
dismissOnPageChange?: boolean;
|
|
267
339
|
/**
|
|
268
|
-
* Whether the toast is to be automatically closed after some time (`true`
|
|
269
|
-
* default DatoCMS time interval)
|
|
340
|
+
* Whether the toast is to be automatically closed after some time (`true`
|
|
341
|
+
* will use the default DatoCMS time interval)
|
|
270
342
|
*/
|
|
271
343
|
dismissAfterTimeout?: boolean | number;
|
|
272
344
|
};
|
|
@@ -274,7 +346,10 @@ export declare type Toast<CtaValue = unknown> = {
|
|
|
274
346
|
export declare type ConfirmChoice = {
|
|
275
347
|
/** The label to be shown for the choice */
|
|
276
348
|
label: string;
|
|
277
|
-
/**
|
|
349
|
+
/**
|
|
350
|
+
* The value to be returned by the `openConfirm` promise if the button is
|
|
351
|
+
* clicked by the user
|
|
352
|
+
*/
|
|
278
353
|
value: unknown;
|
|
279
354
|
/** The intent of the button. Will present the button in a different color accent. */
|
|
280
355
|
intent?: 'positive' | 'negative';
|
|
@@ -299,20 +374,23 @@ export declare type CommonProperties = {
|
|
|
299
374
|
/** All the models of the current DatoCMS project, indexed by ID */
|
|
300
375
|
itemTypes: Partial<Record<string, ModelBlock>>;
|
|
301
376
|
/**
|
|
302
|
-
* The current DatoCMS user. It can either be the owner or one of the
|
|
303
|
-
* (regular or SSO).
|
|
377
|
+
* The current DatoCMS user. It can either be the owner or one of the
|
|
378
|
+
* collaborators (regular or SSO).
|
|
304
379
|
*/
|
|
305
380
|
currentUser: User | SsoUser | Account;
|
|
306
381
|
/** The role for the current DatoCMS user */
|
|
307
382
|
currentRole: Role;
|
|
308
383
|
/**
|
|
309
|
-
* The access token to perform API calls on behalf of the current user. Only
|
|
310
|
-
* if `currentUserAccessToken` additional permission is granted
|
|
384
|
+
* The access token to perform API calls on behalf of the current user. Only
|
|
385
|
+
* available if `currentUserAccessToken` additional permission is granted
|
|
311
386
|
*/
|
|
312
387
|
currentUserAccessToken: string | undefined;
|
|
313
388
|
/** The current plugin */
|
|
314
389
|
plugin: Plugin;
|
|
315
|
-
/**
|
|
390
|
+
/**
|
|
391
|
+
* UI preferences of the current user (right now, only the preferred locale is
|
|
392
|
+
* available)
|
|
393
|
+
*/
|
|
316
394
|
ui: {
|
|
317
395
|
/** Preferred locale */
|
|
318
396
|
locale: string;
|
|
@@ -329,24 +407,25 @@ export declare type InitPropertiesAndMethods = InitMethods & InitProperties;
|
|
|
329
407
|
/** Additional properties available in all `renderXXX` hooks */
|
|
330
408
|
export declare type RenderAdditionalProperties = {
|
|
331
409
|
/**
|
|
332
|
-
* All the fields currently loaded for the current DatoCMS project, indexed by
|
|
333
|
-
* will always contain the current model fields and all the fields of
|
|
334
|
-
* might contain via Modular Content/Structured Text fields. If
|
|
335
|
-
* not present, use the `loadItemTypeFields` function
|
|
410
|
+
* All the fields currently loaded for the current DatoCMS project, indexed by
|
|
411
|
+
* ID. It will always contain the current model fields and all the fields of
|
|
412
|
+
* the blocks it might contain via Modular Content/Structured Text fields. If
|
|
413
|
+
* some fields you need are not present, use the `loadItemTypeFields` function
|
|
414
|
+
* to load them.
|
|
336
415
|
*/
|
|
337
416
|
fields: Partial<Record<string, Field>>;
|
|
338
417
|
/** An object containing the theme colors for the current DatoCMS project */
|
|
339
418
|
theme: Theme;
|
|
340
419
|
/**
|
|
341
|
-
* All the regular users currently loaded for the current DatoCMS project,
|
|
342
|
-
* ID. It will always contain the current user. If some users you
|
|
343
|
-
* use the `loadUsers` function to load them.
|
|
420
|
+
* All the regular users currently loaded for the current DatoCMS project,
|
|
421
|
+
* indexed by ID. It will always contain the current user. If some users you
|
|
422
|
+
* need are not present, use the `loadUsers` function to load them.
|
|
344
423
|
*/
|
|
345
424
|
users: Partial<Record<string, User>>;
|
|
346
425
|
/**
|
|
347
|
-
* All the SSO users currently loaded for the current DatoCMS project, indexed
|
|
348
|
-
* will always contain the current user. If some users you need are
|
|
349
|
-
* `loadSsoUsers` function to load them.
|
|
426
|
+
* All the SSO users currently loaded for the current DatoCMS project, indexed
|
|
427
|
+
* by ID. It will always contain the current user. If some users you need are
|
|
428
|
+
* not present, use the `loadSsoUsers` function to load them.
|
|
350
429
|
*/
|
|
351
430
|
ssoUsers: Partial<Record<string, SsoUser>>;
|
|
352
431
|
/** The project owner */
|
|
@@ -380,151 +459,186 @@ export declare type FieldAppearanceChange = {
|
|
|
380
459
|
parameters: Record<string, unknown>;
|
|
381
460
|
};
|
|
382
461
|
/**
|
|
383
|
-
* These methods can be used to update both plugin parameters and manual field
|
|
384
|
-
* configuration.
|
|
462
|
+
* These methods can be used to update both plugin parameters and manual field
|
|
463
|
+
* extensions configuration.
|
|
385
464
|
*/
|
|
386
465
|
export declare type UpdateParametersMethods = {
|
|
387
466
|
/**
|
|
388
467
|
* Updates the plugin parameters.
|
|
389
468
|
*
|
|
390
|
-
* Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
|
|
391
|
-
* this, as the user might not have the permission to perform
|
|
469
|
+
* Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
|
|
470
|
+
* before calling this, as the user might not have the permission to perform
|
|
471
|
+
* the operation.
|
|
392
472
|
*
|
|
393
473
|
* @example
|
|
394
|
-
*
|
|
395
|
-
*
|
|
474
|
+
*
|
|
475
|
+
* ```js
|
|
476
|
+
* await ctx.updatePluginParameters({ debugMode: true });
|
|
477
|
+
* await ctx.notice('Plugin parameters successfully updated!');
|
|
478
|
+
* ```
|
|
396
479
|
*/
|
|
397
480
|
updatePluginParameters: (params: Record<string, unknown>) => Promise<void>;
|
|
398
481
|
/**
|
|
399
|
-
* Performs changes in the appearance of a field. You can install/remove a
|
|
400
|
-
* extension, or tweak their parameters. If multiple changes are
|
|
401
|
-
* applied sequencially.
|
|
482
|
+
* Performs changes in the appearance of a field. You can install/remove a
|
|
483
|
+
* manual field extension, or tweak their parameters. If multiple changes are
|
|
484
|
+
* passed, they will be applied sequencially.
|
|
402
485
|
*
|
|
403
|
-
* Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
|
|
404
|
-
* this, as the user might not have the permission to perform
|
|
486
|
+
* Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
|
|
487
|
+
* before calling this, as the user might not have the permission to perform
|
|
488
|
+
* the operation.
|
|
405
489
|
*
|
|
406
490
|
* @example
|
|
407
|
-
* const fields = await ctx.loadFieldsUsingPlugin();
|
|
408
491
|
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
492
|
+
* ```js
|
|
493
|
+
* const fields = await ctx.loadFieldsUsingPlugin();
|
|
494
|
+
*
|
|
495
|
+
* if (fields.length === 0) {
|
|
496
|
+
* ctx.alert('No field is using this plugin as a manual extension!');
|
|
497
|
+
* return;
|
|
498
|
+
* }
|
|
499
|
+
*
|
|
500
|
+
* for (const field of fields) {
|
|
501
|
+
* const { appearance } = field.attributes;
|
|
502
|
+
* const operations = [];
|
|
503
|
+
*
|
|
504
|
+
* if (appearance.editor === ctx.plugin.id) {
|
|
505
|
+
* operations.push({
|
|
506
|
+
* operation: 'updateEditor',
|
|
507
|
+
* newParameters: {
|
|
508
|
+
* ...appearance.parameters,
|
|
509
|
+
* foo: 'bar',
|
|
510
|
+
* },
|
|
511
|
+
* });
|
|
412
512
|
* }
|
|
413
513
|
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
* if (appearance.editor === ctx.plugin.id) {
|
|
419
|
-
* operations.push({
|
|
420
|
-
* operation: 'updateEditor',
|
|
421
|
-
* newParameters: {
|
|
422
|
-
* ...appearance.parameters,
|
|
423
|
-
* foo: 'bar',
|
|
424
|
-
* },
|
|
425
|
-
* });
|
|
514
|
+
* appearance.addons.forEach((addon, i) => {
|
|
515
|
+
* if (addon.id !== ctx.plugin.id) {
|
|
516
|
+
* return;
|
|
426
517
|
* }
|
|
427
518
|
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
* }
|
|
432
|
-
*
|
|
433
|
-
* operations.push({
|
|
434
|
-
* operation: 'updateAddon',
|
|
435
|
-
* index: i,
|
|
436
|
-
* newParameters: { ...addon.parameters, foo: 'bar' },
|
|
437
|
-
* });
|
|
519
|
+
* operations.push({
|
|
520
|
+
* operation: 'updateAddon',
|
|
521
|
+
* index: i,
|
|
522
|
+
* newParameters: { ...addon.parameters, foo: 'bar' },
|
|
438
523
|
* });
|
|
524
|
+
* });
|
|
439
525
|
*
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
526
|
+
* await ctx.updateFieldAppearance(field.id, operations);
|
|
527
|
+
* ctx.notice(`Successfully edited field ${field.attributes.api_key}`);
|
|
528
|
+
* }
|
|
529
|
+
* ```
|
|
443
530
|
*/
|
|
444
531
|
updateFieldAppearance: (fieldId: string, changes: FieldAppearanceChange[]) => Promise<void>;
|
|
445
532
|
};
|
|
446
|
-
/**
|
|
533
|
+
/**
|
|
534
|
+
* These methods can be used to asyncronously load additional information your
|
|
535
|
+
* plugin needs to work
|
|
536
|
+
*/
|
|
447
537
|
export declare type LoadDataMethods = {
|
|
448
538
|
/**
|
|
449
|
-
* Loads all the fields for a specific model (or block). Fields will be
|
|
450
|
-
* will also be available in the the `fields` property.
|
|
539
|
+
* Loads all the fields for a specific model (or block). Fields will be
|
|
540
|
+
* returned and will also be available in the the `fields` property.
|
|
451
541
|
*
|
|
452
542
|
* @example
|
|
453
|
-
* const itemTypeId = prompt('Please insert a model ID:');
|
|
454
543
|
*
|
|
455
|
-
*
|
|
544
|
+
* ```js
|
|
545
|
+
* const itemTypeId = prompt('Please insert a model ID:');
|
|
546
|
+
*
|
|
547
|
+
* const fields = await ctx.loadItemTypeFields(itemTypeId);
|
|
456
548
|
*
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
549
|
+
* ctx.notice(
|
|
550
|
+
* `Success! ${fields
|
|
551
|
+
* .map((field) => field.attributes.api_key)
|
|
552
|
+
* .join(', ')}`,
|
|
553
|
+
* );
|
|
554
|
+
* ```
|
|
460
555
|
*/
|
|
461
556
|
loadItemTypeFields: (itemTypeId: string) => Promise<Field[]>;
|
|
462
557
|
/**
|
|
463
|
-
* Loads all the fields in the project that are currently using the plugin for
|
|
464
|
-
* its manual field extensions.
|
|
558
|
+
* Loads all the fields in the project that are currently using the plugin for
|
|
559
|
+
* one of its manual field extensions.
|
|
465
560
|
*
|
|
466
561
|
* @example
|
|
467
|
-
* const fields = await ctx.loadFieldsUsingPlugin();
|
|
468
562
|
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
563
|
+
* ```js
|
|
564
|
+
* const fields = await ctx.loadFieldsUsingPlugin();
|
|
565
|
+
*
|
|
566
|
+
* ctx.notice(
|
|
567
|
+
* `Success! ${fields
|
|
568
|
+
* .map((field) => field.attributes.api_key)
|
|
569
|
+
* .join(', ')}`,
|
|
570
|
+
* );
|
|
571
|
+
* ```
|
|
472
572
|
*/
|
|
473
573
|
loadFieldsUsingPlugin: () => Promise<Field[]>;
|
|
474
574
|
/**
|
|
475
|
-
* Loads all regular users. Users will be returned and will also be available
|
|
476
|
-
* `users` property.
|
|
575
|
+
* Loads all regular users. Users will be returned and will also be available
|
|
576
|
+
* in the the `users` property.
|
|
477
577
|
*
|
|
478
578
|
* @example
|
|
479
|
-
* const users = await ctx.loadUsers();
|
|
480
579
|
*
|
|
481
|
-
*
|
|
580
|
+
* ```js
|
|
581
|
+
* const users = await ctx.loadUsers();
|
|
582
|
+
*
|
|
583
|
+
* ctx.notice(`Success! ${users.map((user) => user.id).join(', ')}`);
|
|
584
|
+
* ```
|
|
482
585
|
*/
|
|
483
586
|
loadUsers: () => Promise<User[]>;
|
|
484
587
|
/**
|
|
485
|
-
* Loads all SSO users. Users will be returned and will also be available in
|
|
486
|
-
* `ssoUsers` property.
|
|
588
|
+
* Loads all SSO users. Users will be returned and will also be available in
|
|
589
|
+
* the the `ssoUsers` property.
|
|
487
590
|
*
|
|
488
591
|
* @example
|
|
489
|
-
* const users = await ctx.loadSsoUsers();
|
|
490
592
|
*
|
|
491
|
-
*
|
|
593
|
+
* ```js
|
|
594
|
+
* const users = await ctx.loadSsoUsers();
|
|
595
|
+
*
|
|
596
|
+
* ctx.notice(`Success! ${users.map((user) => user.id).join(', ')}`);
|
|
597
|
+
* ```
|
|
492
598
|
*/
|
|
493
599
|
loadSsoUsers: () => Promise<SsoUser[]>;
|
|
494
600
|
};
|
|
495
601
|
/** These methods let you open the standard DatoCMS dialogs needed to interact with records */
|
|
496
602
|
export declare type ItemDialogMethods = {
|
|
497
603
|
/**
|
|
498
|
-
* Opens a dialog for creating a new record. It returns a promise resolved
|
|
499
|
-
* newly created record or `null` if the user closes the dialog
|
|
604
|
+
* Opens a dialog for creating a new record. It returns a promise resolved
|
|
605
|
+
* with the newly created record or `null` if the user closes the dialog
|
|
606
|
+
* without creating anything.
|
|
500
607
|
*
|
|
501
608
|
* @example
|
|
502
|
-
* const itemTypeId = prompt('Please insert a model ID:');
|
|
503
609
|
*
|
|
504
|
-
*
|
|
610
|
+
* ```js
|
|
611
|
+
* const itemTypeId = prompt('Please insert a model ID:');
|
|
505
612
|
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
613
|
+
* const item = await ctx.createNewItem(itemTypeId);
|
|
614
|
+
*
|
|
615
|
+
* if (item) {
|
|
616
|
+
* ctx.notice(`Success! ${item.id}`);
|
|
617
|
+
* } else {
|
|
618
|
+
* ctx.alert('Closed!');
|
|
619
|
+
* }
|
|
620
|
+
* ```
|
|
511
621
|
*/
|
|
512
622
|
createNewItem: (itemTypeId: string) => Promise<Item | null>;
|
|
513
623
|
/**
|
|
514
|
-
* Opens a dialog for selecting one (or multiple) record(s) from a list of
|
|
515
|
-
* records of type `itemTypeId`. It returns a promise resolved with
|
|
516
|
-
* record(s), or `null` if the user closes the dialog without
|
|
624
|
+
* Opens a dialog for selecting one (or multiple) record(s) from a list of
|
|
625
|
+
* existing records of type `itemTypeId`. It returns a promise resolved with
|
|
626
|
+
* the selected record(s), or `null` if the user closes the dialog without
|
|
627
|
+
* choosing any record.
|
|
517
628
|
*
|
|
518
629
|
* @example
|
|
519
|
-
* const itemTypeId = prompt('Please insert a model ID:');
|
|
520
630
|
*
|
|
521
|
-
*
|
|
631
|
+
* ```js
|
|
632
|
+
* const itemTypeId = prompt('Please insert a model ID:');
|
|
522
633
|
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
634
|
+
* const items = await ctx.selectItem(itemTypeId, { multiple: true });
|
|
635
|
+
*
|
|
636
|
+
* if (items) {
|
|
637
|
+
* ctx.notice(`Success! ${items.map((i) => i.id).join(', ')}`);
|
|
638
|
+
* } else {
|
|
639
|
+
* ctx.alert('Closed!');
|
|
640
|
+
* }
|
|
641
|
+
* ```
|
|
528
642
|
*/
|
|
529
643
|
selectItem: {
|
|
530
644
|
(itemTypeId: string, options: {
|
|
@@ -535,19 +649,23 @@ export declare type ItemDialogMethods = {
|
|
|
535
649
|
}): Promise<Item | null>;
|
|
536
650
|
};
|
|
537
651
|
/**
|
|
538
|
-
* Opens a dialog for editing an existing record. It returns a promise
|
|
539
|
-
* edited record, or `null` if the user closes the dialog
|
|
652
|
+
* Opens a dialog for editing an existing record. It returns a promise
|
|
653
|
+
* resolved with the edited record, or `null` if the user closes the dialog
|
|
654
|
+
* without persisting any change.
|
|
540
655
|
*
|
|
541
656
|
* @example
|
|
542
|
-
* const itemId = prompt('Please insert a record ID:');
|
|
543
657
|
*
|
|
544
|
-
*
|
|
658
|
+
* ```js
|
|
659
|
+
* const itemId = prompt('Please insert a record ID:');
|
|
545
660
|
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
661
|
+
* const item = await ctx.editItem(itemId);
|
|
662
|
+
*
|
|
663
|
+
* if (item) {
|
|
664
|
+
* ctx.notice(`Success! ${item.id}`);
|
|
665
|
+
* } else {
|
|
666
|
+
* ctx.alert('Closed!');
|
|
667
|
+
* }
|
|
668
|
+
* ```
|
|
551
669
|
*/
|
|
552
670
|
editItem: (itemId: string) => Promise<Item | null>;
|
|
553
671
|
};
|
|
@@ -557,56 +675,77 @@ export declare type ToastMethods = {
|
|
|
557
675
|
* Triggers an "error" toast displaying the selected message
|
|
558
676
|
*
|
|
559
677
|
* @example
|
|
560
|
-
* const message = prompt('Please insert a message:', 'This is an alert message!');
|
|
561
678
|
*
|
|
562
|
-
*
|
|
679
|
+
* ```js
|
|
680
|
+
* const message = prompt(
|
|
681
|
+
* 'Please insert a message:',
|
|
682
|
+
* 'This is an alert message!',
|
|
683
|
+
* );
|
|
684
|
+
*
|
|
685
|
+
* await ctx.alert(message);
|
|
686
|
+
* ```
|
|
563
687
|
*/
|
|
564
688
|
alert: (message: string) => Promise<void>;
|
|
565
689
|
/**
|
|
566
690
|
* Triggers a "success" toast displaying the selected message
|
|
567
691
|
*
|
|
568
692
|
* @example
|
|
569
|
-
* const message = prompt('Please insert a message:', 'This is a notice message!');
|
|
570
693
|
*
|
|
571
|
-
*
|
|
694
|
+
* ```js
|
|
695
|
+
* const message = prompt(
|
|
696
|
+
* 'Please insert a message:',
|
|
697
|
+
* 'This is a notice message!',
|
|
698
|
+
* );
|
|
699
|
+
*
|
|
700
|
+
* await ctx.notice(message);
|
|
701
|
+
* ```
|
|
572
702
|
*/
|
|
573
703
|
notice: (message: string) => Promise<void>;
|
|
574
704
|
/**
|
|
575
705
|
* Triggers a custom toast displaying the selected message (and optionally a CTA)
|
|
576
706
|
*
|
|
577
707
|
* @example
|
|
578
|
-
* const result = await ctx.customToast({
|
|
579
|
-
* type: 'warning',
|
|
580
|
-
* message: 'Just a sample warning notification!',
|
|
581
|
-
* dismissOnPageChange: true,
|
|
582
|
-
* dismissAfterTimeout: 5000,
|
|
583
|
-
* cta: {
|
|
584
|
-
* label: 'Execute call-to-action',
|
|
585
|
-
* value: 'cta',
|
|
586
|
-
* },
|
|
587
|
-
* });
|
|
588
708
|
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
709
|
+
* ```js
|
|
710
|
+
* const result = await ctx.customToast({
|
|
711
|
+
* type: 'warning',
|
|
712
|
+
* message: 'Just a sample warning notification!',
|
|
713
|
+
* dismissOnPageChange: true,
|
|
714
|
+
* dismissAfterTimeout: 5000,
|
|
715
|
+
* cta: {
|
|
716
|
+
* label: 'Execute call-to-action',
|
|
717
|
+
* value: 'cta',
|
|
718
|
+
* },
|
|
719
|
+
* });
|
|
720
|
+
*
|
|
721
|
+
* if (result === 'cta') {
|
|
722
|
+
* ctx.notice(`Clicked CTA!`);
|
|
723
|
+
* }
|
|
724
|
+
* ```
|
|
592
725
|
*/
|
|
593
726
|
customToast: <CtaValue = unknown>(toast: Toast<CtaValue>) => Promise<CtaValue | null>;
|
|
594
727
|
};
|
|
595
|
-
/**
|
|
728
|
+
/**
|
|
729
|
+
* These methods let you open the standard DatoCMS dialogs needed to interact
|
|
730
|
+
* with Media Area assets
|
|
731
|
+
*/
|
|
596
732
|
export declare type UploadDialogMethods = {
|
|
597
733
|
/**
|
|
598
|
-
* Opens a dialog for selecting one (or multiple) existing asset(s). It
|
|
599
|
-
* promise resolved with the selected asset(s), or `null` if the
|
|
600
|
-
* without selecting any upload.
|
|
734
|
+
* Opens a dialog for selecting one (or multiple) existing asset(s). It
|
|
735
|
+
* returns a promise resolved with the selected asset(s), or `null` if the
|
|
736
|
+
* user closes the dialog without selecting any upload.
|
|
601
737
|
*
|
|
602
738
|
* @example
|
|
603
|
-
* const item = await ctx.selectUpload({ multiple: false });
|
|
604
739
|
*
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
* }
|
|
740
|
+
* ```js
|
|
741
|
+
* const item = await ctx.selectUpload({ multiple: false });
|
|
742
|
+
*
|
|
743
|
+
* if (item) {
|
|
744
|
+
* ctx.notice(`Success! ${item.id}`);
|
|
745
|
+
* } else {
|
|
746
|
+
* ctx.alert('Closed!');
|
|
747
|
+
* }
|
|
748
|
+
* ```
|
|
610
749
|
*/
|
|
611
750
|
selectUpload: {
|
|
612
751
|
(options: {
|
|
@@ -621,44 +760,50 @@ export declare type UploadDialogMethods = {
|
|
|
621
760
|
*
|
|
622
761
|
* - The updated asset, if the user persists some changes to the asset itself
|
|
623
762
|
* - `null`, if the user closes the dialog without persisting any change
|
|
624
|
-
* - An asset structure with an additional `deleted` property set to true, if
|
|
625
|
-
* deletes the asset
|
|
763
|
+
* - An asset structure with an additional `deleted` property set to true, if
|
|
764
|
+
* the user deletes the asset
|
|
626
765
|
*
|
|
627
766
|
* @example
|
|
628
|
-
* const uploadId = prompt('Please insert an asset ID:');
|
|
629
767
|
*
|
|
630
|
-
*
|
|
768
|
+
* ```js
|
|
769
|
+
* const uploadId = prompt('Please insert an asset ID:');
|
|
631
770
|
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
*
|
|
771
|
+
* const item = await ctx.editUpload(uploadId);
|
|
772
|
+
*
|
|
773
|
+
* if (item) {
|
|
774
|
+
* ctx.notice(`Success! ${item.id}`);
|
|
775
|
+
* } else {
|
|
776
|
+
* ctx.alert('Closed!');
|
|
777
|
+
* }
|
|
778
|
+
* ```
|
|
637
779
|
*/
|
|
638
780
|
editUpload: (uploadId: string) => Promise<(Upload & {
|
|
639
781
|
deleted?: true;
|
|
640
782
|
}) | null>;
|
|
641
783
|
/**
|
|
642
|
-
* Opens a dialog for editing a "single asset" field structure. It returns a
|
|
643
|
-
* resolved with the updated structure, or `null` if the user closes
|
|
644
|
-
* persisting any change.
|
|
784
|
+
* Opens a dialog for editing a "single asset" field structure. It returns a
|
|
785
|
+
* promise resolved with the updated structure, or `null` if the user closes
|
|
786
|
+
* the dialog without persisting any change.
|
|
645
787
|
*
|
|
646
788
|
* @example
|
|
647
|
-
* const uploadId = prompt('Please insert an asset ID:');
|
|
648
|
-
*
|
|
649
|
-
* const result = await ctx.editUploadMetadata({
|
|
650
|
-
* upload_id: uploadId,
|
|
651
|
-
* alt: null,
|
|
652
|
-
* title: null,
|
|
653
|
-
* custom_data: {},
|
|
654
|
-
* focal_point: null,
|
|
655
|
-
* });
|
|
656
789
|
*
|
|
657
|
-
*
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
790
|
+
* ```js
|
|
791
|
+
* const uploadId = prompt('Please insert an asset ID:');
|
|
792
|
+
*
|
|
793
|
+
* const result = await ctx.editUploadMetadata({
|
|
794
|
+
* upload_id: uploadId,
|
|
795
|
+
* alt: null,
|
|
796
|
+
* title: null,
|
|
797
|
+
* custom_data: {},
|
|
798
|
+
* focal_point: null,
|
|
799
|
+
* });
|
|
800
|
+
*
|
|
801
|
+
* if (result) {
|
|
802
|
+
* ctx.notice(`Success! ${JSON.stringify(result)}`);
|
|
803
|
+
* } else {
|
|
804
|
+
* ctx.alert('Closed!');
|
|
805
|
+
* }
|
|
806
|
+
* ```
|
|
662
807
|
*/
|
|
663
808
|
editUploadMetadata: (
|
|
664
809
|
/** The "single asset" field structure */
|
|
@@ -669,56 +814,62 @@ export declare type UploadDialogMethods = {
|
|
|
669
814
|
/** These methods can be used to open custom dialogs/confirmation panels */
|
|
670
815
|
export declare type CustomDialogMethods = {
|
|
671
816
|
/**
|
|
672
|
-
* Opens a custom modal. Returns a promise resolved with what the modal itself
|
|
673
|
-
* calling the `resolve()` function
|
|
817
|
+
* Opens a custom modal. Returns a promise resolved with what the modal itself
|
|
818
|
+
* returns calling the `resolve()` function
|
|
674
819
|
*
|
|
675
820
|
* @example
|
|
676
|
-
* const result = await ctx.openModal({
|
|
677
|
-
* id: 'regular',
|
|
678
|
-
* title: 'Custom title!',
|
|
679
|
-
* width: 'l',
|
|
680
|
-
* parameters: { foo: 'bar' },
|
|
681
|
-
* });
|
|
682
821
|
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
822
|
+
* ```js
|
|
823
|
+
* const result = await ctx.openModal({
|
|
824
|
+
* id: 'regular',
|
|
825
|
+
* title: 'Custom title!',
|
|
826
|
+
* width: 'l',
|
|
827
|
+
* parameters: { foo: 'bar' },
|
|
828
|
+
* });
|
|
829
|
+
*
|
|
830
|
+
* if (result) {
|
|
831
|
+
* ctx.notice(`Success! ${JSON.stringify(result)}`);
|
|
832
|
+
* } else {
|
|
833
|
+
* ctx.alert('Closed!');
|
|
834
|
+
* }
|
|
835
|
+
* ```
|
|
688
836
|
*/
|
|
689
837
|
openModal: (modal: Modal) => Promise<unknown>;
|
|
690
838
|
/**
|
|
691
|
-
* Opens a UI-consistent confirmation dialog. Returns a promise resolved with
|
|
692
|
-
* of the choice made by the user
|
|
839
|
+
* Opens a UI-consistent confirmation dialog. Returns a promise resolved with
|
|
840
|
+
* the value of the choice made by the user
|
|
693
841
|
*
|
|
694
842
|
* @example
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
* label: 'Negative',
|
|
707
|
-
* value: 'negative',
|
|
708
|
-
* intent: 'negative',
|
|
709
|
-
* },
|
|
710
|
-
* ],
|
|
711
|
-
* cancel: {
|
|
712
|
-
* label: 'Cancel',
|
|
713
|
-
* value: false,
|
|
843
|
+
*
|
|
844
|
+
* ```js
|
|
845
|
+
* const result = await ctx.openConfirm({
|
|
846
|
+
* title: 'Custom title',
|
|
847
|
+
* content:
|
|
848
|
+
* 'Lorem Ipsum is simply dummy text of the printing and typesetting industry',
|
|
849
|
+
* choices: [
|
|
850
|
+
* {
|
|
851
|
+
* label: 'Positive',
|
|
852
|
+
* value: 'positive',
|
|
853
|
+
* intent: 'positive',
|
|
714
854
|
* },
|
|
715
|
-
*
|
|
855
|
+
* {
|
|
856
|
+
* label: 'Negative',
|
|
857
|
+
* value: 'negative',
|
|
858
|
+
* intent: 'negative',
|
|
859
|
+
* },
|
|
860
|
+
* ],
|
|
861
|
+
* cancel: {
|
|
862
|
+
* label: 'Cancel',
|
|
863
|
+
* value: false,
|
|
864
|
+
* },
|
|
865
|
+
* });
|
|
716
866
|
*
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
*
|
|
867
|
+
* if (result) {
|
|
868
|
+
* ctx.notice(`Success! ${result}`);
|
|
869
|
+
* } else {
|
|
870
|
+
* ctx.alert('Cancelled!');
|
|
871
|
+
* }
|
|
872
|
+
* ```
|
|
722
873
|
*/
|
|
723
874
|
openConfirm: (options: ConfirmOptions) => Promise<unknown>;
|
|
724
875
|
};
|
|
@@ -728,7 +879,10 @@ export declare type NavigateMethods = {
|
|
|
728
879
|
* Moves the user to another URL internal to the backend
|
|
729
880
|
*
|
|
730
881
|
* @example
|
|
731
|
-
*
|
|
882
|
+
*
|
|
883
|
+
* ```js
|
|
884
|
+
* await ctx.navigateTo('/');
|
|
885
|
+
* ```
|
|
732
886
|
*/
|
|
733
887
|
navigateTo: (path: string) => Promise<void>;
|
|
734
888
|
};
|
|
@@ -739,8 +893,8 @@ export declare type IframeMethods = {
|
|
|
739
893
|
};
|
|
740
894
|
export declare type RenderMethods = LoadDataMethods & UpdateParametersMethods & ToastMethods & CustomDialogMethods & NavigateMethods;
|
|
741
895
|
/**
|
|
742
|
-
* These information describe the current state of the form that's being shown
|
|
743
|
-
* end-user to edit a record
|
|
896
|
+
* These information describe the current state of the form that's being shown
|
|
897
|
+
* to the end-user to edit a record
|
|
744
898
|
*/
|
|
745
899
|
export declare type ItemFormAdditionalProperties = {
|
|
746
900
|
/** The currently active locale for the record */
|
|
@@ -760,64 +914,79 @@ export declare type ItemFormAdditionalProperties = {
|
|
|
760
914
|
};
|
|
761
915
|
export declare type ItemFormProperties = RenderProperties & ItemFormAdditionalProperties;
|
|
762
916
|
/**
|
|
763
|
-
* These methods can be used to interact with the form that's being shown to the
|
|
764
|
-
* to edit a record
|
|
917
|
+
* These methods can be used to interact with the form that's being shown to the
|
|
918
|
+
* end-user to edit a record
|
|
765
919
|
*/
|
|
766
920
|
export declare type ItemFormAdditionalMethods = {
|
|
767
921
|
/**
|
|
768
922
|
* Hides/shows a specific field in the form
|
|
769
923
|
*
|
|
770
924
|
* @example
|
|
771
|
-
* const fieldPath = prompt(
|
|
772
|
-
* 'Please insert the path of a field in the form',
|
|
773
|
-
* ctx.fieldPath,
|
|
774
|
-
* );
|
|
775
925
|
*
|
|
776
|
-
*
|
|
926
|
+
* ```js
|
|
927
|
+
* const fieldPath = prompt(
|
|
928
|
+
* 'Please insert the path of a field in the form',
|
|
929
|
+
* ctx.fieldPath,
|
|
930
|
+
* );
|
|
931
|
+
*
|
|
932
|
+
* await ctx.toggleField(fieldPath, true);
|
|
933
|
+
* ```
|
|
777
934
|
*/
|
|
778
935
|
toggleField: (path: string, show: boolean) => Promise<void>;
|
|
779
936
|
/**
|
|
780
937
|
* Disables/re-enables a specific field in the form
|
|
781
938
|
*
|
|
782
939
|
* @example
|
|
783
|
-
* const fieldPath = prompt(
|
|
784
|
-
* 'Please insert the path of a field in the form',
|
|
785
|
-
* ctx.fieldPath,
|
|
786
|
-
* );
|
|
787
940
|
*
|
|
788
|
-
*
|
|
941
|
+
* ```js
|
|
942
|
+
* const fieldPath = prompt(
|
|
943
|
+
* 'Please insert the path of a field in the form',
|
|
944
|
+
* ctx.fieldPath,
|
|
945
|
+
* );
|
|
946
|
+
*
|
|
947
|
+
* await ctx.disableField(fieldPath, true);
|
|
948
|
+
* ```
|
|
789
949
|
*/
|
|
790
950
|
disableField: (path: string, disable: boolean) => Promise<void>;
|
|
791
951
|
/**
|
|
792
|
-
* Smoothly navigates to a specific field in the form. If the field is
|
|
793
|
-
* switch language tab and then navigate to the chosen field.
|
|
952
|
+
* Smoothly navigates to a specific field in the form. If the field is
|
|
953
|
+
* localized it will switch language tab and then navigate to the chosen field.
|
|
794
954
|
*
|
|
795
955
|
* @example
|
|
796
|
-
* const fieldPath = prompt(
|
|
797
|
-
* 'Please insert the path of a field in the form',
|
|
798
|
-
* ctx.fieldPath,
|
|
799
|
-
* );
|
|
800
956
|
*
|
|
801
|
-
*
|
|
957
|
+
* ```js
|
|
958
|
+
* const fieldPath = prompt(
|
|
959
|
+
* 'Please insert the path of a field in the form',
|
|
960
|
+
* ctx.fieldPath,
|
|
961
|
+
* );
|
|
962
|
+
*
|
|
963
|
+
* await ctx.scrollToField(fieldPath);
|
|
964
|
+
* ```
|
|
802
965
|
*/
|
|
803
966
|
scrollToField: (path: string, locale?: string) => Promise<void>;
|
|
804
967
|
/**
|
|
805
968
|
* Changes a specific path of the `formValues` object
|
|
806
969
|
*
|
|
807
970
|
* @example
|
|
808
|
-
* const fieldPath = prompt(
|
|
809
|
-
* 'Please insert the path of a field in the form',
|
|
810
|
-
* ctx.fieldPath,
|
|
811
|
-
* );
|
|
812
971
|
*
|
|
813
|
-
*
|
|
972
|
+
* ```js
|
|
973
|
+
* const fieldPath = prompt(
|
|
974
|
+
* 'Please insert the path of a field in the form',
|
|
975
|
+
* ctx.fieldPath,
|
|
976
|
+
* );
|
|
977
|
+
*
|
|
978
|
+
* await ctx.setFieldValue(fieldPath, 'new value');
|
|
979
|
+
* ```
|
|
814
980
|
*/
|
|
815
981
|
setFieldValue: (path: string, value: unknown) => Promise<void>;
|
|
816
982
|
/**
|
|
817
983
|
* Triggers a submit form for current record
|
|
818
984
|
*
|
|
819
985
|
* @example
|
|
820
|
-
*
|
|
986
|
+
*
|
|
987
|
+
* ```js
|
|
988
|
+
* await ctx.saveCurrentItem();
|
|
989
|
+
* ```
|
|
821
990
|
*/
|
|
822
991
|
saveCurrentItem: () => Promise<void>;
|
|
823
992
|
};
|
|
@@ -827,7 +996,10 @@ export declare type RenderSidebarPanelAdditionalProperties = {
|
|
|
827
996
|
mode: 'renderItemFormSidebarPanel';
|
|
828
997
|
/** The ID of the sidebar panel that needs to be rendered */
|
|
829
998
|
sidebarPaneId: string;
|
|
830
|
-
/**
|
|
999
|
+
/**
|
|
1000
|
+
* The arbitrary `parameters` of the panel declared in the
|
|
1001
|
+
* `itemFormSidebarPanels` function
|
|
1002
|
+
*/
|
|
831
1003
|
parameters: Record<string, unknown>;
|
|
832
1004
|
};
|
|
833
1005
|
export declare type RenderSidebarPanelProperties = ItemFormProperties & RenderSidebarPanelAdditionalProperties;
|
|
@@ -836,7 +1008,10 @@ export declare type RenderSidebarPanelAdditionalMethods = {
|
|
|
836
1008
|
};
|
|
837
1009
|
export declare type RenderSidebarPanelMethods = ItemFormMethods & RenderSidebarPanelAdditionalMethods;
|
|
838
1010
|
export declare type RenderSidebarPanePropertiesAndMethods = RenderSidebarPanelMethods & RenderSidebarPanelProperties;
|
|
839
|
-
/**
|
|
1011
|
+
/**
|
|
1012
|
+
* Information regarding the state of a specific field where you need to render
|
|
1013
|
+
* the field extension
|
|
1014
|
+
*/
|
|
840
1015
|
export declare type RenderFieldExtensionAdditionalProperties = {
|
|
841
1016
|
mode: 'renderFieldExtension';
|
|
842
1017
|
/** The ID of the field extension that needs to be rendered */
|
|
@@ -852,8 +1027,8 @@ export declare type RenderFieldExtensionAdditionalProperties = {
|
|
|
852
1027
|
/** The field where the field extension is installed to */
|
|
853
1028
|
field: Field;
|
|
854
1029
|
/**
|
|
855
|
-
* If the field extension is installed in a field of a block, returns the top
|
|
856
|
-
* Modular Content/Structured Text field containing the block itself
|
|
1030
|
+
* If the field extension is installed in a field of a block, returns the top
|
|
1031
|
+
* level Modular Content/Structured Text field containing the block itself
|
|
857
1032
|
*/
|
|
858
1033
|
parentField: Field | undefined;
|
|
859
1034
|
};
|
|
@@ -876,21 +1051,100 @@ export declare type RenderModalProperties = RenderProperties & RenderModalAdditi
|
|
|
876
1051
|
export declare type RenderModalAdditionalMethods = {
|
|
877
1052
|
getSettings: () => Promise<RenderModalProperties>;
|
|
878
1053
|
/**
|
|
879
|
-
* A function to be called by the plugin to close the modal. The `openModal`
|
|
880
|
-
* be resolved with the passed return value
|
|
1054
|
+
* A function to be called by the plugin to close the modal. The `openModal`
|
|
1055
|
+
* call will be resolved with the passed return value
|
|
881
1056
|
*
|
|
882
1057
|
* @example
|
|
883
|
-
* const returnValue = prompt(
|
|
884
|
-
* 'Please specify the value to return to the caller:',
|
|
885
|
-
* 'success',
|
|
886
|
-
* );
|
|
887
1058
|
*
|
|
888
|
-
*
|
|
1059
|
+
* ```js
|
|
1060
|
+
* const returnValue = prompt(
|
|
1061
|
+
* 'Please specify the value to return to the caller:',
|
|
1062
|
+
* 'success',
|
|
1063
|
+
* );
|
|
1064
|
+
*
|
|
1065
|
+
* await ctx.resolve(returnValue);
|
|
1066
|
+
* ```
|
|
889
1067
|
*/
|
|
890
1068
|
resolve: (returnValue: unknown) => Promise<void>;
|
|
891
1069
|
};
|
|
892
1070
|
export declare type RenderModalMethods = RenderMethods & IframeMethods & RenderModalAdditionalMethods;
|
|
893
1071
|
export declare type RenderModalPropertiesAndMethods = RenderModalMethods & RenderModalProperties;
|
|
1072
|
+
/** Information regarding the specific asset source browser that you need to render */
|
|
1073
|
+
export declare type RenderAssetSourceAdditionalProperties = {
|
|
1074
|
+
mode: 'renderAssetSource';
|
|
1075
|
+
/** The ID of the assetSource that needs to be rendered */
|
|
1076
|
+
assetSourceId: string;
|
|
1077
|
+
};
|
|
1078
|
+
export declare type RenderAssetSourceProperties = RenderProperties & RenderAssetSourceAdditionalProperties;
|
|
1079
|
+
export declare type NewUploadResourceAsUrl = {
|
|
1080
|
+
/**
|
|
1081
|
+
* URL for the resource. The URL must respond with a
|
|
1082
|
+
* `Access-Control-Allow-Origin` header — for instance `*`, which will allow
|
|
1083
|
+
* all hosts — allowing the image to be read by DatoCMS
|
|
1084
|
+
*/
|
|
1085
|
+
url: string;
|
|
1086
|
+
/**
|
|
1087
|
+
* Optional filename to be used to generate the final DatoCMS URL. If not
|
|
1088
|
+
* passed, the URL will be used
|
|
1089
|
+
*/
|
|
1090
|
+
filename?: string;
|
|
1091
|
+
};
|
|
1092
|
+
export declare type NewUploadResourceAsBase64 = {
|
|
1093
|
+
/**
|
|
1094
|
+
* Base64 encoded data URI for the resource.
|
|
1095
|
+
*
|
|
1096
|
+
* Format:
|
|
1097
|
+
*
|
|
1098
|
+
* `data:[<mime type>][;charset=<charset>];base64,<encoded data>`
|
|
1099
|
+
*/
|
|
1100
|
+
base64: string;
|
|
1101
|
+
/** Filename to be used to generate the final DatoCMS URL */
|
|
1102
|
+
filename: string;
|
|
1103
|
+
};
|
|
1104
|
+
export declare type NewUpload = {
|
|
1105
|
+
/** The actual resource that will be uploaded */
|
|
1106
|
+
resource: NewUploadResourceAsUrl | NewUploadResourceAsBase64;
|
|
1107
|
+
/** Copyright to apply to the asset */
|
|
1108
|
+
copyright?: string;
|
|
1109
|
+
/** Author to apply to the asset */
|
|
1110
|
+
author?: string;
|
|
1111
|
+
/** Notes to apply to the asset */
|
|
1112
|
+
notes?: string;
|
|
1113
|
+
/** Tags to apply to the asset */
|
|
1114
|
+
tags?: string[];
|
|
1115
|
+
/**
|
|
1116
|
+
* An hash containing, for each locale of the project, the default metadata to
|
|
1117
|
+
* apply to the asset
|
|
1118
|
+
*/
|
|
1119
|
+
defaultFieldMetadata?: NonNullable<Record<string, UploadCreateSchema['data']['attributes']['default_field_metadata']>>;
|
|
1120
|
+
};
|
|
1121
|
+
/** Use these methods to confirm */
|
|
1122
|
+
export declare type RenderAssetSourceAdditionalMethods = {
|
|
1123
|
+
getSettings: () => Promise<RenderAssetSourceProperties>;
|
|
1124
|
+
/**
|
|
1125
|
+
* Function to be called when the user selects the asset: it will trigger the
|
|
1126
|
+
* creation of a new `Upload` that will be added in the Media Area.
|
|
1127
|
+
*
|
|
1128
|
+
* @example
|
|
1129
|
+
*
|
|
1130
|
+
* ```js
|
|
1131
|
+
* await ctx.select({
|
|
1132
|
+
* resource: {
|
|
1133
|
+
* url:
|
|
1134
|
+
* 'https://images.unsplash.com/photo-1416339306562-f3d12fefd36f',
|
|
1135
|
+
* filename: 'man-drinking-coffee.jpg',
|
|
1136
|
+
* },
|
|
1137
|
+
* copyright: 'Royalty free (Unsplash)',
|
|
1138
|
+
* author: 'Jeff Sheldon',
|
|
1139
|
+
* notes: 'A man drinking a coffee',
|
|
1140
|
+
* tags: ['man', 'coffee'],
|
|
1141
|
+
* });
|
|
1142
|
+
* ```
|
|
1143
|
+
*/
|
|
1144
|
+
select: (newUpload: NewUpload) => Promise<void>;
|
|
1145
|
+
};
|
|
1146
|
+
export declare type RenderAssetSourceMethods = RenderMethods & IframeMethods & RenderAssetSourceAdditionalMethods;
|
|
1147
|
+
export declare type RenderAssetSourcePropertiesAndMethods = RenderAssetSourceMethods & RenderAssetSourceProperties;
|
|
894
1148
|
/** Information regarding the specific page that you need to render */
|
|
895
1149
|
export declare type RenderPageAdditionalProperties = {
|
|
896
1150
|
mode: 'renderPage';
|
|
@@ -903,9 +1157,23 @@ export declare type RenderPageAdditionalMethods = {
|
|
|
903
1157
|
};
|
|
904
1158
|
export declare type RenderPageMethods = RenderMethods & RenderPageAdditionalMethods;
|
|
905
1159
|
export declare type RenderPagePropertiesAndMethods = RenderPageMethods & RenderPageProperties;
|
|
1160
|
+
export declare type PendingField = {
|
|
1161
|
+
id?: string;
|
|
1162
|
+
type: 'field';
|
|
1163
|
+
attributes: {
|
|
1164
|
+
api_key: Field['attributes']['api_key'];
|
|
1165
|
+
appearance: Field['attributes']['appearance'];
|
|
1166
|
+
default_value: Field['attributes']['default_value'];
|
|
1167
|
+
field_type: Field['attributes']['field_type'];
|
|
1168
|
+
hint: Field['attributes']['hint'];
|
|
1169
|
+
label: Field['attributes']['label'];
|
|
1170
|
+
localized: Field['attributes']['localized'];
|
|
1171
|
+
validators: Field['attributes']['validators'];
|
|
1172
|
+
};
|
|
1173
|
+
};
|
|
906
1174
|
/**
|
|
907
|
-
* Information regarding the specific form that you need to render to let the
|
|
908
|
-
* edit the configuration object of a field extension
|
|
1175
|
+
* Information regarding the specific form that you need to render to let the
|
|
1176
|
+
* end-user edit the configuration object of a field extension
|
|
909
1177
|
*/
|
|
910
1178
|
export declare type RenderManualFieldExtensionConfigScreenAdditionalProperties = {
|
|
911
1179
|
mode: 'renderManualFieldExtensionConfigScreen';
|
|
@@ -917,20 +1185,30 @@ export declare type RenderManualFieldExtensionConfigScreenAdditionalProperties =
|
|
|
917
1185
|
*/
|
|
918
1186
|
parameters: Record<string, unknown>;
|
|
919
1187
|
/**
|
|
920
|
-
* The current validation errors for the parameters (you can set them
|
|
921
|
-
* `validateManualFieldExtensionParameters` function)
|
|
1188
|
+
* The current validation errors for the parameters (you can set them
|
|
1189
|
+
* implementing the `validateManualFieldExtensionParameters` function)
|
|
922
1190
|
*/
|
|
923
1191
|
errors: Record<string, unknown>;
|
|
1192
|
+
/** The field entity that is being edited in the form */
|
|
1193
|
+
pendingField: PendingField;
|
|
1194
|
+
/** The model for the field being edited */
|
|
1195
|
+
itemType: ModelBlock;
|
|
924
1196
|
};
|
|
925
1197
|
export declare type RenderManualFieldExtensionConfigScreenProperties = RenderProperties & RenderManualFieldExtensionConfigScreenAdditionalProperties;
|
|
926
|
-
/**
|
|
1198
|
+
/**
|
|
1199
|
+
* These methods can be used to update the configuration object of a specific
|
|
1200
|
+
* field extension
|
|
1201
|
+
*/
|
|
927
1202
|
export declare type RenderManualFieldExtensionConfigScreenAdditionalMethods = {
|
|
928
1203
|
getSettings: () => Promise<RenderManualFieldExtensionConfigScreenProperties>;
|
|
929
1204
|
/**
|
|
930
1205
|
* Sets a new value for the parameters
|
|
931
1206
|
*
|
|
932
1207
|
* @example
|
|
933
|
-
*
|
|
1208
|
+
*
|
|
1209
|
+
* ```js
|
|
1210
|
+
* await ctx.setParameters({ color: '#ff0000' });
|
|
1211
|
+
* ```
|
|
934
1212
|
*/
|
|
935
1213
|
setParameters: (params: Record<string, unknown>) => Promise<void>;
|
|
936
1214
|
};
|