-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.ts
5932 lines (5823 loc) · 129 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import type { SchemaTypes } from '@datocms/cma-client';
import type { BlockNodeTypeWithCustomStyle } from 'datocms-structured-text-utils';
type Account = SchemaTypes.Account;
type Organization = SchemaTypes.Organization;
type Field = SchemaTypes.Field;
type Fieldset = SchemaTypes.Fieldset;
type Item = SchemaTypes.Item;
type ItemType = SchemaTypes.ItemType;
type Plugin = SchemaTypes.Plugin;
type Role = SchemaTypes.Role;
type Site = SchemaTypes.Site;
type SsoUser = SchemaTypes.SsoUser;
type Upload = SchemaTypes.Upload;
type User = SchemaTypes.User;
export type Icon =
| AwesomeFontIconIdentifier
| { type: 'svg'; viewBox: string; content: string };
export type ItemListLocationQuery = {
locale?: string;
filter?: {
query?: string;
fields?: Record<string, unknown>;
};
};
export type ItemPresentationInfo = {
/** The title to present the record */
title: string;
/** An image representative of the record */
imageUrl?: string;
/**
* If different plugins implement the `buildItemPresentationInfo` hook, the
* one with the lowest `rank` will be used. If you want to specify an explicit
* value for `rank`, make sure to offer a way for final users to customize it
* inside the plugin's settings form, otherwise the hardcoded value you choose
* might clash with the one of another plugin!
*/
rank?: number;
};
export type InitialLocationQueryForItemSelector = {
locationQuery: ItemListLocationQuery;
/**
* If different plugins implement the `initialLocationQueryForItemSelector`
* hook, the one with the lowest `rank` will be used. If you want to specify
* an explicit value for `rank`, make sure to offer a way for final users to
* customize it inside the plugin's settings form, otherwise the hardcoded
* value you choose might clash with the one of another plugin!
*/
rank?: number;
};
/** A tab to be displayed in the top-bar of the UI */
export type MainNavigationTab = {
/** Label to be shown. Must be unique. */
label: string;
/**
* Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
* `"address-book"`) or a custom SVG definition. To maintain visual
* consistency with the rest of the interface, try to use FontAwesome icons
* whenever possible.
*/
icon: Icon;
/** ID of the page linked to the tab */
pointsTo: {
pageId: string;
};
/**
* Expresses where you want to place the tab in the top-bar. If not specified,
* the tab will be placed after the standard tabs provided by DatoCMS itself.
*/
placement?: [
'before' | 'after',
'content' | 'media' | 'schema' | 'configuration' | 'cdaPlayground',
];
/**
* If different plugins specify the same `placement` for their tabs, they will
* be displayed by ascending `rank`. If you want to specify an explicit value
* for `rank`, make sure to offer a way for final users to customize it inside
* the plugin's settings form, otherwise the hardcoded value you choose might
* clash with the one of another plugin!
*/
rank?: number;
};
/** An item contained in a Settings Area group */
export type SettingsAreaSidebarItem = {
/** Label to be shown. Must be unique. */
label: string;
/**
* Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
* `"address-book"`) or a custom SVG definition. To maintain visual
* consistency with the rest of the interface, try to use FontAwesome icons
* whenever possible.
*/
icon: Icon;
/** ID of the page linked to the item */
pointsTo: {
pageId: string;
};
};
/**
* The sidebar in the Settings Area presents a number of pages grouped by topic.
* This object represents a new group to be added in the sideebar to the
* standard ones DatoCMS provides.
*/
export type SettingsAreaSidebarItemGroup = {
/** Label to be shown. Must be unique. */
label: string;
/** The list of items it contains * */
items: SettingsAreaSidebarItem[];
/**
* Expresses where you want the group to be placed inside the sidebar. If not
* specified, the item will be placed after the standard items provided by
* DatoCMS itself.
*/
placement?: ['before' | 'after', 'properties' | 'permissions'];
/**
* If different plugins specify the same `placement` for their sections, they
* will be displayed by ascending `rank`. If you want to specify an explicit
* value for `rank`, make sure to offer a way for final users to customize it
* inside the plugin's settings form, otherwise the hardcoded value you choose
* might clash with the one of another plugin!
*/
rank?: number;
};
/**
* The sidebar in the Content Area presents a number of user-defined menu-items.
* This object represents a new item to be added in the sidebar.
*/
export type ContentAreaSidebarItem = {
/** Label to be shown. Must be unique. */
label: string;
/**
* Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
* `"address-book"`) or a custom SVG definition. To maintain visual
* consistency with the rest of the interface, try to use FontAwesome icons
* whenever possible.
*/
icon: Icon;
/** ID of the page linked to the item */
pointsTo: {
pageId: string;
};
/**
* Expresses where you want the item to be placed inside the sidebar. If not
* specified, the item will be placed after the standard items provided by
* DatoCMS itself.
*/
placement?: ['before' | 'after', 'menuItems' | 'seoPreferences'];
/**
* If different plugins specify the same `placement` for their panels, they
* will be displayed by ascending `rank`. If you want to specify an explicit
* value for `rank`, make sure to offer a way for final users to customize it
* inside the plugin's settings form, otherwise the hardcoded value you choose
* might clash with the one of another plugin!
*/
rank?: number;
};
export type FieldExtensionType = 'editor' | 'addon';
export type FieldType =
| 'boolean'
| 'color'
| 'date_time'
| 'date'
| 'file'
| 'float'
| 'gallery'
| 'integer'
| 'json'
| 'lat_lon'
| 'link'
| 'links'
| 'rich_text'
| 'seo'
| 'slug'
| 'string'
| 'structured_text'
| 'text'
| 'video';
/**
* Field extensions extend the basic functionality of DatoCMS when it comes to
* presenting record's fields to the final user. Depending on the extension type
* (`editor` or `addon`) they will be shown in different places of the
* interface.
*/
export type ManualFieldExtension = {
/**
* ID of field extension. Will be the first argument for the
* `renderFieldExtension` function
*/
id: string;
/** Name to be shown when editing fields */
name: string;
/**
* Type of field extension. An `editor` extension replaces the default field
* editor that DatoCMS provides, while an `addon` extension is placed
* underneath the field editor to provide additional info/behaviour. You can
* setup multiple field addons for every field.
*/
type: FieldExtensionType;
/**
* For `editor` extensions: moves the field to the sidebar of the record
* editing page, mimicking a sidebar panel
*/
asSidebarPanel?: boolean | { startOpen: boolean };
/**
* The type of fields that the field extension in compatible with. You can use
* the shortcut `all` to target all types of fields
*/
fieldTypes: 'all' | FieldType[];
/**
* Whether this field extension needs some configuration options before being
* installed in a field or not. Will trigger the
* `renderManualFieldExtensionConfigScreen` and
* `validateManualFieldExtensionParameters` methods
*/
configurable?: boolean | { initialHeight: number };
/**
* The initial height to set for the iframe that will render the field
* extension
*/
initialHeight?: number;
};
export type ItemFormSidebarPanelPlacement = [
'before' | 'after',
'info' | 'publishedVersion' | 'schedule' | 'links' | 'history',
];
/** A sidebar panel to be shown inside the record's editing page */
export type ItemFormSidebarPanel = {
/**
* ID of the panel. Will be the first argument for the
* `renderItemFormSidebarPanel` function
*/
id: string;
/** Label to be shown on the collapsible sidebar panel handle */
label: string;
/**
* An arbitrary configuration object that will be passed as the `parameters`
* property of the second argument of the `renderItemFormSidebarPanel`
* function
*/
parameters?: Record<string, unknown>;
/** Whether the sidebar panel will start open or collapsed */
startOpen?: boolean;
/**
* Expresses where you want the item to be placed inside the sidebar. If not
* specified, the item will be placed after the standard panels provided by
* DatoCMS itself.
*/
placement?: ItemFormSidebarPanelPlacement;
/**
* If multiple sidebar panels specify the same `placement`, they will be
* sorted by ascending `rank`. If you want to specify an explicit value for
* `rank`, make sure to offer a way for final users to customize it inside the
* plugin's settings form, otherwise the hardcoded value you choose might
* clash with the one of another plugin!
*/
rank?: number;
/** The initial height to set for the iframe that will render the sidebar panel */
initialHeight?: number;
};
/** A sidebar to be shown inside the record's editing page */
export type ItemFormSidebar = {
/**
* ID of the sidebar. Will be the first argument for the
* `renderItemFormSidebar` function
*/
id: string;
/** Label to be shown on the collapsible sidebar handle */
label: string;
/**
* An arbitrary configuration object that will be passed as the `parameters`
* property of the second argument of the `renderItemFormSidebar` function
*/
parameters?: Record<string, unknown>;
/**
* If multiple sidebars specify the same `placement`, they will be sorted by
* ascending `rank`. If you want to specify an explicit value for `rank`, make
* sure to offer a way for final users to customize it inside the plugin's
* settings form, otherwise the hardcoded value you choose might clash with
* the one of another plugin!
*/
rank?: number;
/** The preferred width for the sidebar */
preferredWidth?: number;
};
/** An outlet to be shown at the top of a record's editing page */
export type ItemFormOutlet = {
/**
* ID of the outlet. Will be the first argument for the `renderItemFormOutlet`
* function
*/
id: string;
/**
* Multiple outlets will be sorted by ascending `rank`. If you want to specify
* an explicit value for `rank`, make sure to offer a way for final users to
* customize it inside the plugin's settings form, otherwise the hardcoded
* value you choose might clash with the one of another plugin!
*/
rank?: number;
/** The initial height to set for the iframe that will render the outlet */
initialHeight?: number;
};
/** A field editor/sidebar forced on a field */
export type EditorOverride = {
/**
* ID of field extension. Will be the first argument for the
* `renderFieldExtension` function
*/
id: string;
/**
* Moves the field to the sidebar of the record editing page, mimicking a
* sidebar panel
*/
asSidebarPanel?:
| boolean
| { startOpen?: boolean; placement?: ItemFormSidebarPanelPlacement };
/**
* An arbitrary configuration object that will be passed as the `parameters`
* property of the second argument of the `renderFieldExtension` function
*/
parameters?: Record<string, unknown>;
/**
* If multiple plugins override a field, the one with the lowest `rank` will
* win. If you want to specify an explicit value for `rank`, make sure to
* offer a way for final users to customize it inside the plugin's settings
* form, otherwise the hardcoded value you choose might clash with the one of
* another plugin!
*/
rank?: number;
/**
* The initial height to set for the iframe that will render the field
* extension
*/
initialHeight?: number;
};
/** A field addon extension forced on a field */
export type AddonOverride = {
/**
* ID of field extension. Will be the first argument for the
* `renderFieldExtension` function
*/
id: string;
/**
* An arbitrary configuration object that will be passed as the `parameters`
* property of the second argument of the `renderFieldExtension` function
*/
parameters?: Record<string, unknown>;
/**
* If multiple addons are present for a field, they will be sorted by
* ascending `rank`. If you want to specify an explicit value for `rank`, make
* sure to offer a way for final users to customize it inside the plugin's
* settings form, otherwise the hardcoded value you choose might clash with
* the one of another plugin!
*/
rank?: number;
/**
* The initial height to set for the iframe that will render the field
* extension
*/
initialHeight?: number;
};
export type StructuredTextCustomMarkPlacement = [
'before' | 'after',
'strong' | 'emphasis' | 'underline' | 'code' | 'highlight' | 'strikethrough',
];
/** An object expressing a custom mark for a Structured Text field */
export type StructuredTextCustomMark = {
/** ID of mark */
id: string;
/** Label representing the custom mark */
label: string;
/**
* Icon to be shown alongside the label. Can be a FontAwesome icon name (ie.
* `"address-book"`) or a custom SVG definition. To maintain visual
* consistency with the rest of the interface, try to use FontAwesome icons
* whenever possible
*/
icon: Icon;
/**
* Expresses where you want the custom mark button to be placed inside the
* toolbar. If not specified, the item will be placed after the standard marks
* provided by DatoCMS itself.
*/
placement?: StructuredTextCustomMarkPlacement;
/**
* If multiple custom marks specify the same `placement` for their toolbar
* button, they will be sorted by ascending `rank`. If you want to specify an
* explicit value for `rank`, make sure to offer a way for final users to
* customize it inside the plugin's settings form, otherwise the hardcoded
* value you choose might clash with the one of another plugin!
*/
rank?: number;
/**
* Keyboard shortcut associated with the custom mark, expressed using the
* https://github.com/ianstormtaylor/is-hotkey syntax (ie. `mod+shift+x`)
*/
keyboardShortcut?: string;
/** How the custom mark will be styled inside the editor */
appliedStyle: React.CSSProperties;
};
/** An object expressing a custom block style for a Structured Text field */
export type StructuredTextCustomBlockStyle = {
/** ID of custom block style */
id: string;
/** The block node that can apply this style */
node: BlockNodeTypeWithCustomStyle;
/** ID of custom block style */
label: string;
/** How the block will be styled inside the editor to represent the style */
appliedStyle: React.CSSProperties;
/**
* Custom styles for a block node will be sorted by ascending `rank`. If you
* want to specify an explicit value for `rank`, make sure to offer a way for
* final users to customize it inside the plugin's settings form, otherwise
* the hardcoded value you choose might clash with the one of another plugin!
*/
rank?: number;
};
/**
* An object expressing some field extensions you want to force on a particular
* field
*/
export type FieldExtensionOverride = {
/** Force a field editor/sidebar extension on a field */
editor?: EditorOverride;
/** One or more field sidebar extensions to forcefully add to a field */
addons?: AddonOverride[];
};
/** An object containing the theme colors for the current DatoCMS project */
export type Theme = {
primaryColor: string;
accentColor: string;
semiTransparentAccentColor: string;
lightColor: string;
darkColor: string;
};
/** Focal point of an image asset */
export type FocalPoint = {
/** Horizontal position expressed as float between 0 and 1 */
x: number;
/** Vertical position expressed as float between 0 and 1 */
y: number;
};
/** The structure contained in a "single asset" field */
export type FileFieldValue = {
/** ID of the asset */
// eslint-disable-next-line camelcase
upload_id: string;
/** Alternate text for the asset */
alt: string | null;
/** Title for the asset */
title: string | null;
/** Focal point of an asset */
// eslint-disable-next-line camelcase
focal_point: FocalPoint | null;
/** Object with arbitrary metadata related to the asset */
// eslint-disable-next-line camelcase
custom_data: Record<string, string>;
};
/** A modal to present to the user */
export type Modal = {
/** ID of the modal. Will be the first argument for the `renderModal` function */
id: string;
/** Title for the modal. Ignored by `fullWidth` modals */
title?: string;
/** Whether to present a close button for the modal or not */
closeDisabled?: boolean;
/** Width of the modal. Can be a number, or one of the predefined sizes */
width?: 's' | 'm' | 'l' | 'xl' | 'fullWidth' | number;
/**
* An arbitrary configuration object that will be passed as the `parameters`
* property of the second argument of the `renderModal` function
*/
parameters?: Record<string, unknown>;
/** The initial height to set for the iframe that will render the modal content */
initialHeight?: number;
};
/** An additional asset source */
export type AssetSource = {
/**
* ID of the asset source. Will be the first argument for the
* `renderAssetSource` function
*/
id: string;
/** Name of the asset that will be shown to the user */
name: string;
/**
* Icon to be shown alongside the name. Can be a FontAwesome icon name (ie.
* `"address-book"`) or a custom SVG definition. To maintain visual
* consistency with the rest of the interface, try to use FontAwesome icons
* whenever possible.
*/
icon: Icon;
/**
* Configuration options for the modal that will be opened to select a media
* file from this source
*/
modal?: {
/** Width of the modal. Can be a number, or one of the predefined sizes */
width?: 's' | 'm' | 'l' | 'xl' | number;
/**
* The initial height to set for the iframe that will render the modal
* content
*/
initialHeight?: number;
};
};
/** A toast notification to present to the user */
export type Toast<CtaValue = unknown> = {
/** Message of the notification */
message: string;
/** Type of notification. Will present the toast in a different color accent. */
type: 'notice' | 'alert' | 'warning';
/** An optional button to show inside the toast */
cta?: {
/** Label for the button */
label: string;
/**
* The value to be returned by the `customToast` promise if the button is
* clicked by the user
*/
value: CtaValue;
};
/** Whether the toast is to be automatically closed if the user changes page */
dismissOnPageChange?: boolean;
/**
* Whether the toast is to be automatically closed after some time (`true`
* will use the default DatoCMS time interval)
*/
dismissAfterTimeout?: boolean | number;
};
/** A choice presented in a `openConfirm` panel */
export type ConfirmChoice = {
/** The label to be shown for the choice */
label: string;
/**
* The value to be returned by the `openConfirm` promise if the button is
* clicked by the user
*/
value: unknown;
/**
* The intent of the button. Will present the button in a different color
* accent.
*/
intent?: 'positive' | 'negative';
};
/** Options for the `openConfirm` function */
export type ConfirmOptions = {
/** The title to be shown inside the confirmation panel */
title: string;
/** The main message to be shown inside the confirmation panel */
content: string;
/** The different options the user can choose from */
choices: ConfirmChoice[];
/** The cancel option to present to the user */
cancel: ConfirmChoice;
};
/** Generic properties available in all the hooks */
export type CommonProperties = {
/** The current DatoCMS project */
site: Site;
/** The ID of the current environment */
environment: string;
/** All the models of the current DatoCMS project, indexed by ID */
itemTypes: Partial<Record<string, ItemType>>;
/**
* The current DatoCMS user. It can either be the owner or one of the
* collaborators (regular or SSO).
*/
currentUser: User | SsoUser | Account | Organization;
/** The role for the current DatoCMS user */
currentRole: Role;
/**
* The access token to perform API calls on behalf of the current user. Only
* available if `currentUserAccessToken` additional permission is granted
*/
currentUserAccessToken: string | undefined;
/** The current plugin */
plugin: Plugin;
/**
* UI preferences of the current user (right now, only the preferred locale is
* available)
*/
ui: {
/** Preferred locale */
locale: string;
};
};
export type InitAdditionalProperties = {
mode: 'init';
};
export type InitProperties = CommonProperties & InitAdditionalProperties;
export type InitMethods = {
getSettings: () => Promise<InitProperties>;
};
export type InitPropertiesAndMethods = InitMethods & InitProperties;
/** Additional properties available in all `renderXXX` hooks */
export type RenderAdditionalProperties = {
/**
* All the fields currently loaded for the current DatoCMS project, indexed by
* ID. It will always contain the current model fields and all the fields of
* the blocks it might contain via Modular Content/Structured Text fields. If
* some fields you need are not present, use the `loadItemTypeFields` function
* to load them.
*/
fields: Partial<Record<string, Field>>;
/**
* All the fieldsets currently loaded for the current DatoCMS project, indexed
* by ID. It will always contain the current model fields and all the fields
* of the blocks it might contain via Modular Content/Structured Text fields.
* If some fields you need are not present, use the `loadItemTypeFieldsets`
* function to load them.
*/
fieldsets: Partial<Record<string, Fieldset>>;
/** An object containing the theme colors for the current DatoCMS project */
theme: Theme;
/**
* All the regular users currently loaded for the current DatoCMS project,
* indexed by ID. It will always contain the current user. If some users you
* need are not present, use the `loadUsers` function to load them.
*/
users: Partial<Record<string, User>>;
/**
* All the SSO users currently loaded for the current DatoCMS project, indexed
* by ID. It will always contain the current user. If some users you need are
* not present, use the `loadSsoUsers` function to load them.
*/
ssoUsers: Partial<Record<string, SsoUser>>;
/**
* The account that is the project owner
*
* @deprecated Please use `.owner` instead, as the project owner can also be
* an organization
*/
account: Account | undefined;
/** The account that is the project owner */
owner: Account | Organization;
/** The padding in px that must be applied to the body */
bodyPadding: [number, number, number, number];
};
export type RenderProperties = CommonProperties & RenderAdditionalProperties;
export type FieldAppearanceChange =
| {
operation: 'removeEditor';
}
| {
operation: 'updateEditor';
newFieldExtensionId?: string;
newParameters?: Record<string, unknown>;
}
| {
operation: 'setEditor';
fieldExtensionId: string;
parameters: Record<string, unknown>;
}
| {
operation: 'removeAddon';
index: number;
}
| {
operation: 'updateAddon';
index: number;
newFieldExtensionId?: string;
newParameters?: Record<string, unknown>;
}
| {
operation: 'insertAddon';
index: number;
fieldExtensionId: string;
parameters: Record<string, unknown>;
};
/**
* These methods can be used to update both plugin parameters and manual field
* extensions configuration.
*/
export type UpdateParametersMethods = {
/**
* Updates the plugin parameters.
*
* Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
* before calling this, as the user might not have the permission to perform
* the operation.
*
* @example
*
* ```js
* await ctx.updatePluginParameters({ debugMode: true });
* await ctx.notice('Plugin parameters successfully updated!');
* ```
*/
updatePluginParameters: (params: Record<string, unknown>) => Promise<void>;
/**
* Performs changes in the appearance of a field. You can install/remove a
* manual field extension, or tweak their parameters. If multiple changes are
* passed, they will be applied sequencially.
*
* Always check `ctx.currentRole.meta.final_permissions.can_edit_schema`
* before calling this, as the user might not have the permission to perform
* the operation.
*
* @example
*
* ```js
* const fields = await ctx.loadFieldsUsingPlugin();
*
* if (fields.length === 0) {
* ctx.alert('No field is using this plugin as a manual extension!');
* return;
* }
*
* for (const field of fields) {
* const { appearance } = field.attributes;
* const operations = [];
*
* if (appearance.editor === ctx.plugin.id) {
* operations.push({
* operation: 'updateEditor',
* newParameters: {
* ...appearance.parameters,
* foo: 'bar',
* },
* });
* }
*
* appearance.addons.forEach((addon, i) => {
* if (addon.id !== ctx.plugin.id) {
* return;
* }
*
* operations.push({
* operation: 'updateAddon',
* index: i,
* newParameters: { ...addon.parameters, foo: 'bar' },
* });
* });
*
* await ctx.updateFieldAppearance(field.id, operations);
* ctx.notice(`Successfully edited field ${field.attributes.api_key}`);
* }
* ```
*/
updateFieldAppearance: (
fieldId: string,
changes: FieldAppearanceChange[],
) => Promise<void>;
};
/**
* These methods can be used to asyncronously load additional information your
* plugin needs to work
*/
export type LoadDataMethods = {
/**
* Loads all the fields for a specific model (or block). Fields will be
* returned and will also be available in the the `fields` property.
*
* @example
*
* ```js
* const itemTypeId = prompt('Please insert a model ID:');
*
* const fields = await ctx.loadItemTypeFields(itemTypeId);
*
* ctx.notice(
* `Success! ${fields
* .map((field) => field.attributes.api_key)
* .join(', ')}`,
* );
* ```
*/
loadItemTypeFields: (itemTypeId: string) => Promise<Field[]>;
/**
* Loads all the fieldsets for a specific model (or block). Fieldsets will be
* returned and will also be available in the the `fieldsets` property.
*
* @example
*
* ```js
* const itemTypeId = prompt('Please insert a model ID:');
*
* const fieldsets = await ctx.loadItemTypeFieldsets(itemTypeId);
*
* ctx.notice(
* `Success! ${fieldsets
* .map((fieldset) => fieldset.attributes.title)
* .join(', ')}`,
* );
* ```
*/
loadItemTypeFieldsets: (itemTypeId: string) => Promise<Fieldset[]>;
/**
* Loads all the fields in the project that are currently using the plugin for
* one of its manual field extensions.
*
* @example
*
* ```js
* const fields = await ctx.loadFieldsUsingPlugin();
*
* ctx.notice(
* `Success! ${fields
* .map((field) => field.attributes.api_key)
* .join(', ')}`,
* );
* ```
*/
loadFieldsUsingPlugin: () => Promise<Field[]>;
/**
* Loads all regular users. Users will be returned and will also be available
* in the the `users` property.
*
* @example
*
* ```js
* const users = await ctx.loadUsers();
*
* ctx.notice(`Success! ${users.map((user) => user.id).join(', ')}`);
* ```
*/
loadUsers: () => Promise<User[]>;
/**
* Loads all SSO users. Users will be returned and will also be available in
* the the `ssoUsers` property.
*
* @example
*
* ```js
* const users = await ctx.loadSsoUsers();
*
* ctx.notice(`Success! ${users.map((user) => user.id).join(', ')}`);
* ```
*/
loadSsoUsers: () => Promise<SsoUser[]>;
};
/**
* These methods let you open the standard DatoCMS dialogs needed to interact
* with records
*/
export type ItemDialogMethods = {
/**
* Opens a dialog for creating a new record. It returns a promise resolved
* with the newly created record or `null` if the user closes the dialog
* without creating anything.
*
* @example
*
* ```js
* const itemTypeId = prompt('Please insert a model ID:');
*
* const item = await ctx.createNewItem(itemTypeId);
*
* if (item) {
* ctx.notice(`Success! ${item.id}`);
* } else {
* ctx.alert('Closed!');
* }
* ```
*/
createNewItem: (itemTypeId: string) => Promise<Item | null>;
/**
* Opens a dialog for selecting one (or multiple) record(s) from a list of
* existing records of type `itemTypeId`. It returns a promise resolved with
* the selected record(s), or `null` if the user closes the dialog without
* choosing any record.
*
* @example
*
* ```js
* const itemTypeId = prompt('Please insert a model ID:');
*
* const items = await ctx.selectItem(itemTypeId, { multiple: true });
*
* if (items) {
* ctx.notice(`Success! ${items.map((i) => i.id).join(', ')}`);
* } else {
* ctx.alert('Closed!');
* }
* ```
*/
selectItem: {
(
itemTypeId: string,
options: { multiple: true; initialLocationQuery?: ItemListLocationQuery },
): Promise<Item[] | null>;
(
itemTypeId: string,
options?: {
multiple: false;
initialLocationQuery?: ItemListLocationQuery;
},
): Promise<Item | null>;
};
/**
* Opens a dialog for editing an existing record. It returns a promise
* resolved with the edited record, or `null` if the user closes the dialog
* without persisting any change.
*
* @example
*
* ```js
* const itemId = prompt('Please insert a record ID:');
*
* const item = await ctx.editItem(itemId);
*
* if (item) {
* ctx.notice(`Success! ${item.id}`);
* } else {
* ctx.alert('Closed!');
* }
* ```
*/
editItem: (itemId: string) => Promise<Item | null>;
};
/**
* These methods can be used to show UI-consistent toast notifications to the
* end-user
*/
export type ToastMethods = {
/**
* Triggers an "error" toast displaying the selected message
*
* @example
*
* ```js
* const message = prompt(
* 'Please insert a message:',
* 'This is an alert message!',
* );
*
* await ctx.alert(message);
* ```
*/
alert: (message: string) => Promise<void>;
/**
* Triggers a "success" toast displaying the selected message
*
* @example
*
* ```js
* const message = prompt(
* 'Please insert a message:',
* 'This is a notice message!',
* );
*
* await ctx.notice(message);
* ```
*/
notice: (message: string) => Promise<void>;
/**
* Triggers a custom toast displaying the selected message (and optionally a
* CTA)
*
* @example
*
* ```js
* const result = await ctx.customToast({
* type: 'warning',
* message: 'Just a sample warning notification!',
* dismissOnPageChange: true,
* dismissAfterTimeout: 5000,
* cta: {