datocms-plugin-sdk 0.3.10 → 0.3.24-alpha.3

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.
@@ -1,17 +1,18 @@
1
1
  import { Field, ModelBlock } from './SiteApiSchema';
2
- import { ContentAreaSidebarItem, FieldExtensionOverride, InitPropertiesAndMethods, ItemFormSidebarPanel, MainNavigationTab, ManualFieldExtension, OnBootPropertiesAndMethods, RenderConfigScreenPropertiesAndMethods, RenderFieldExtensionPropertiesAndMethods, RenderManualFieldExtensionConfigScreenPropertiesAndMethods, RenderModalPropertiesAndMethods, RenderPagePropertiesAndMethods, RenderSidebarPanePropertiesAndMethods, SettingsAreaSidebarItemGroup } from './types';
2
+ import { AssetSource, ContentAreaSidebarItem, FieldExtensionOverride, InitPropertiesAndMethods, ItemFormSidebarPanel, MainNavigationTab, ManualFieldExtension, OnBootPropertiesAndMethods, RenderAssetSourcePropertiesAndMethods, RenderConfigScreenPropertiesAndMethods, RenderFieldExtensionPropertiesAndMethods, RenderManualFieldExtensionConfigScreenPropertiesAndMethods, RenderModalPropertiesAndMethods, RenderPagePropertiesAndMethods, RenderSidebarPanePropertiesAndMethods, SettingsAreaSidebarItemGroup } from './types';
3
3
  export declare type SizingUtilities = {
4
4
  /**
5
- * Listens for DOM changes and automatically calls `setHeight` when it detects a change.
6
- * If you're using `datocms-react-ui` package, the `<Canvas />` component already takes
7
- * care of calling this method for you.
5
+ * Listens for DOM changes and automatically calls `setHeight` when it detects
6
+ * a change. If you're using `datocms-react-ui` package, the `<Canvas />`
7
+ * component already takes care of calling this method for you.
8
8
  */
9
9
  startAutoResizer: () => void;
10
10
  /** Stops resizing the iframe automatically */
11
11
  stopAutoResizer: () => void;
12
12
  /**
13
- * Triggers a change in the size of the iframe. If you don't explicitely pass a
14
- * `newHeight` it will be automatically calculated using the iframe content at the moment
13
+ * Triggers a change in the size of the iframe. If you don't explicitely pass
14
+ * a `newHeight` it will be automatically calculated using the iframe content
15
+ * at the moment
15
16
  */
16
17
  updateHeight: (newHeight?: number) => void;
17
18
  };
@@ -23,6 +24,7 @@ export declare type FieldIntentCtx = InitPropertiesAndMethods & {
23
24
  };
24
25
  export declare type RenderPageCtx = RenderPagePropertiesAndMethods;
25
26
  export declare type RenderModalCtx = RenderModalPropertiesAndMethods & SizingUtilities;
27
+ export declare type RenderAssetSourceCtx = RenderAssetSourcePropertiesAndMethods & SizingUtilities;
26
28
  export declare type RenderItemFormSidebarPanelCtx = RenderSidebarPanePropertiesAndMethods & SizingUtilities;
27
29
  export declare type RenderFieldExtensionCtx = RenderFieldExtensionPropertiesAndMethods & SizingUtilities;
28
30
  export declare type RenderManualFieldExtensionConfigScreenCtx = RenderManualFieldExtensionConfigScreenPropertiesAndMethods & SizingUtilities;
@@ -30,8 +32,8 @@ export declare type RenderConfigScreenCtx = RenderConfigScreenPropertiesAndMetho
30
32
  /** The full options you can pass to the `connect` function */
31
33
  export declare type FullConnectParameters = {
32
34
  /**
33
- * This function will be called once at boot time and can be used to perform ie. some
34
- * initial integrity checks on the configuration.
35
+ * This function will be called once at boot time and can be used to perform
36
+ * ie. some initial integrity checks on the configuration.
35
37
  *
36
38
  * @group boot
37
39
  */
@@ -55,69 +57,86 @@ export declare type FullConnectParameters = {
55
57
  */
56
58
  contentAreaSidebarItems: (ctx: IntentCtx) => ContentAreaSidebarItem[];
57
59
  /**
58
- * Use this function to declare new field extensions that users will be able to install
59
- * manually in some field
60
+ * Use this function to declare new field extensions that users will be able
61
+ * to install manually in some field
60
62
  *
61
63
  * @group manualFieldExtensions
62
64
  */
63
65
  manualFieldExtensions: (ctx: IntentCtx) => ManualFieldExtension[];
64
66
  /**
65
- * Use this function to declare new sidebar panels to be shown when the user edits
66
- * records of a particular model
67
+ * Use this function to declare additional sources to be shown when users want
68
+ * to upload new assets
69
+ *
70
+ * @group assetSources
71
+ */
72
+ assetSources: (ctx: IntentCtx) => AssetSource[] | void;
73
+ /**
74
+ * Use this function to declare new sidebar panels to be shown when the user
75
+ * edits records of a particular model
67
76
  *
68
77
  * @group sidebarPanels
69
78
  */
70
79
  itemFormSidebarPanels: (itemType: ModelBlock, ctx: IntentCtx) => ItemFormSidebarPanel[];
71
80
  /**
72
- * Use this function to automatically force one or more field extensions to a particular field
81
+ * Use this function to automatically force one or more field extensions to a
82
+ * particular field
73
83
  *
74
84
  * @group forcedFieldExtensions
75
85
  */
76
86
  overrideFieldExtensions: (field: Field, ctx: FieldIntentCtx) => FieldExtensionOverride | void;
77
87
  /**
78
- * This function will be called when the plugin needs to render the plugin's configuration form
88
+ * This function will be called when the plugin needs to render the plugin's
89
+ * configuration form
79
90
  *
80
91
  * @group configScreen
81
92
  */
82
93
  renderConfigScreen: (ctx: RenderConfigScreenCtx) => void;
83
94
  /**
84
- * This function will be called when the plugin needs to render a specific page (see the
85
- * `mainNavigationTabs`, `settingsAreaSidebarItemGroups` and `contentAreaSidebarItems` functions)
95
+ * This function will be called when the plugin needs to render a specific
96
+ * page (see the `mainNavigationTabs`, `settingsAreaSidebarItemGroups` and
97
+ * `contentAreaSidebarItems` functions)
86
98
  *
87
99
  * @group pages
88
100
  */
89
101
  renderPage: (pageId: string, ctx: RenderPageCtx) => void;
90
102
  /**
91
- * This function will be called when the plugin requested to open a modal (see the
92
- * `openModal` function)
103
+ * This function will be called when the plugin requested to open a modal (see
104
+ * the `openModal` function)
93
105
  *
94
106
  * @group modals
95
107
  */
96
108
  renderModal: (modalId: string, ctx: RenderModalCtx) => void;
97
109
  /**
98
- * This function will be called when the plugin needs to render a sidebar panel (see the
99
- * `itemFormSidebarPanels` function)
110
+ * This function will be called when the plugin needs to render a sidebar
111
+ * panel (see the `itemFormSidebarPanels` function)
100
112
  *
101
113
  * @group sidebarPanels
102
114
  */
103
115
  renderItemFormSidebarPanel: (sidebarPaneId: string, ctx: RenderItemFormSidebarPanelCtx) => void;
104
116
  /**
105
- * This function will be called when the plugin needs to render a field extension (see
106
- * the `manualFieldExtensions` and `overrideFieldExtensions` functions)
117
+ * This function will be called when the user selects one of the plugin's
118
+ * asset sources to upload a new media file.
119
+ *
120
+ * @group assetSources
121
+ */
122
+ renderAssetSource: (assetSourceId: string, ctx: RenderAssetSourceCtx) => void;
123
+ /**
124
+ * This function will be called when the plugin needs to render a field
125
+ * extension (see the `manualFieldExtensions` and `overrideFieldExtensions` functions)
107
126
  *
108
127
  * @group forcedFieldExtensions
109
128
  */
110
129
  renderFieldExtension: (fieldExtensionId: string, ctx: RenderFieldExtensionCtx) => void;
111
130
  /**
112
- * This function will be called when the plugin needs to render the configuration form
113
- * for installing a field extension inside a particular field
131
+ * This function will be called when the plugin needs to render the
132
+ * configuration form for installing a field extension inside a particular field
114
133
  *
115
134
  * @group manualFieldExtensions
116
135
  */
117
136
  renderManualFieldExtensionConfigScreen: (fieldExtensionId: string, ctx: RenderManualFieldExtensionConfigScreenCtx) => void;
118
137
  /**
119
- * This function will be called each time the configuration object changes. It must
120
- * return an object containing possible validation errors
138
+ * This function will be called each time the configuration object changes. It
139
+ * must return an object containing possible validation errors
121
140
  *
122
141
  * @group manualFieldExtensions
123
142
  */
@@ -1,4 +1,4 @@
1
- import { InitMethods, OnBootMethods, RenderPageMethods, RenderFieldExtensionMethods, RenderConfigScreenMethods, RenderManualFieldExtensionConfigScreenMethods, RenderSidebarPanelMethods, RenderModalMethods } from './types';
1
+ import { InitMethods, OnBootMethods, RenderPageMethods, RenderFieldExtensionMethods, RenderConfigScreenMethods, RenderManualFieldExtensionConfigScreenMethods, RenderSidebarPanelMethods, RenderModalMethods, RenderAssetSourceMethods } from './types';
2
2
  export declare type Parent = {
3
3
  getSettings: () => Promise<{
4
4
  mode: string;
@@ -28,3 +28,6 @@ export declare const isRenderFieldExtensionParent: (parent: Parent, settings: {
28
28
  export declare const isRenderManualFieldExtensionConfigScreenParent: (parent: Parent, settings: {
29
29
  mode: string;
30
30
  }) => parent is RenderManualFieldExtensionConfigScreenMethods;
31
+ export declare const isRenderAssetSourceParent: (parent: Parent, settings: {
32
+ mode: string;
33
+ }) => parent is RenderAssetSourceMethods;
@@ -1,10 +1,20 @@
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
- /** FontAwesome icon name to be shown alongside the label */
7
- icon: string;
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;
@@ -30,8 +40,13 @@ export declare type MainNavigationTab = {
30
40
  export declare type SettingsAreaSidebarItem = {
31
41
  /** Label to be shown. Must be unique. */
32
42
  label: string;
33
- /** FontAwesome icon name to be shown alongside the label */
34
- icon: string;
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;
35
50
  /** ID of the page linked to the item */
36
51
  pointsTo: {
37
52
  pageId: string;
@@ -72,8 +87,13 @@ export declare type SettingsAreaSidebarItemGroup = {
72
87
  export declare type ContentAreaSidebarItem = {
73
88
  /** Label to be shown. Must be unique. */
74
89
  label: string;
75
- /** FontAwesome icon name to be shown alongside the label */
76
- icon: string;
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;
77
97
  /** ID of the page linked to the item */
78
98
  pointsTo: {
79
99
  pageId: string;
@@ -276,6 +296,33 @@ export declare type Modal = {
276
296
  /** The initial height to set for the iframe that will render the modal content */
277
297
  initialHeight?: number;
278
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?: {
320
+ /** Width of the modal. Can be a number, or one of the predefined sizes */
321
+ width?: 's' | 'm' | 'l' | 'xl' | number;
322
+ /** The initial height to set for the iframe that will render the modal content */
323
+ initialHeight?: number;
324
+ };
325
+ };
279
326
  /** A toast notification to present to the user */
280
327
  export declare type Toast<CtaValue = unknown> = {
281
328
  /** Message of the notification */
@@ -1027,6 +1074,82 @@ export declare type RenderModalAdditionalMethods = {
1027
1074
  };
1028
1075
  export declare type RenderModalMethods = RenderMethods & IframeMethods & RenderModalAdditionalMethods;
1029
1076
  export declare type RenderModalPropertiesAndMethods = RenderModalMethods & RenderModalProperties;
1077
+ /** Information regarding the specific asset source browser that you need to render */
1078
+ export declare type RenderAssetSourceAdditionalProperties = {
1079
+ mode: 'renderAssetSource';
1080
+ /** The ID of the assetSource that needs to be rendered */
1081
+ assetSourceId: string;
1082
+ };
1083
+ export declare type RenderAssetSourceProperties = RenderProperties & RenderAssetSourceAdditionalProperties;
1084
+ export declare type NewUploadResourceAsUrl = {
1085
+ /**
1086
+ * URL for the resource. The URL must respond with a
1087
+ * `Access-Control-Allow-Origin` header — for instance `*`, which will allow
1088
+ * all hosts — allowing the image to be read by DatoCMS
1089
+ */
1090
+ url: string;
1091
+ /**
1092
+ * Optional filename to be used to generate the final DatoCMS URL. If not
1093
+ * passed, the URL will be used
1094
+ */
1095
+ filename?: string;
1096
+ };
1097
+ export declare type NewUploadResourceAsBase64 = {
1098
+ /**
1099
+ * Base64 encoded data URI for the resource.
1100
+ *
1101
+ * Format:
1102
+ *
1103
+ * `data:[<mime type>][;charset=<charset>];base64,<encoded data>`
1104
+ */
1105
+ base64: string;
1106
+ /** Filename to be used to generate the final DatoCMS URL */
1107
+ filename: string;
1108
+ };
1109
+ export declare type NewUpload = {
1110
+ /** The actual resource that will be uploaded */
1111
+ resource: NewUploadResourceAsUrl | NewUploadResourceAsBase64;
1112
+ /** Copyright to apply to the asset */
1113
+ copyright?: string;
1114
+ /** Author to apply to the asset */
1115
+ author?: string;
1116
+ /** Notes to apply to the asset */
1117
+ notes?: string;
1118
+ /** Tags to apply to the asset */
1119
+ tags?: string[];
1120
+ /**
1121
+ * An hash containing, for each locale of the project, the default metadata to
1122
+ * apply to the asset
1123
+ */
1124
+ defaultFieldMetadata?: NonNullable<Record<string, UploadCreateSchema['data']['attributes']['default_field_metadata']>>;
1125
+ };
1126
+ /** Use these methods to confirm */
1127
+ export declare type RenderAssetSourceAdditionalMethods = {
1128
+ getSettings: () => Promise<RenderAssetSourceProperties>;
1129
+ /**
1130
+ * Function to be called when the user selects the asset: it will trigger the
1131
+ * creation of a new `Upload` that will be added in the Media Area.
1132
+ *
1133
+ * @example
1134
+ *
1135
+ * ```js
1136
+ * await ctx.select({
1137
+ * resource: {
1138
+ * url:
1139
+ * 'https://images.unsplash.com/photo-1416339306562-f3d12fefd36f',
1140
+ * filename: 'man-drinking-coffee.jpg',
1141
+ * },
1142
+ * copyright: 'Royalty free (Unsplash)',
1143
+ * author: 'Jeff Sheldon',
1144
+ * notes: 'A man drinking a coffee',
1145
+ * tags: ['man', 'coffee'],
1146
+ * });
1147
+ * ```
1148
+ */
1149
+ select: (newUpload: NewUpload) => void;
1150
+ };
1151
+ export declare type RenderAssetSourceMethods = RenderMethods & IframeMethods & RenderAssetSourceAdditionalMethods;
1152
+ export declare type RenderAssetSourcePropertiesAndMethods = RenderAssetSourceMethods & RenderAssetSourceProperties;
1030
1153
  /** Information regarding the specific page that you need to render */
1031
1154
  export declare type RenderPageAdditionalProperties = {
1032
1155
  mode: 'renderPage';
@@ -1039,6 +1162,20 @@ export declare type RenderPageAdditionalMethods = {
1039
1162
  };
1040
1163
  export declare type RenderPageMethods = RenderMethods & RenderPageAdditionalMethods;
1041
1164
  export declare type RenderPagePropertiesAndMethods = RenderPageMethods & RenderPageProperties;
1165
+ export declare type PendingField = {
1166
+ id?: string;
1167
+ type: 'field';
1168
+ attributes: {
1169
+ api_key: Field['attributes']['api_key'];
1170
+ appearance: Field['attributes']['appearance'];
1171
+ default_value: Field['attributes']['default_value'];
1172
+ field_type: Field['attributes']['field_type'];
1173
+ hint: Field['attributes']['hint'];
1174
+ label: Field['attributes']['label'];
1175
+ localized: Field['attributes']['localized'];
1176
+ validators: Field['attributes']['validators'];
1177
+ };
1178
+ };
1042
1179
  /**
1043
1180
  * Information regarding the specific form that you need to render to let the
1044
1181
  * end-user edit the configuration object of a field extension
@@ -1057,6 +1194,10 @@ export declare type RenderManualFieldExtensionConfigScreenAdditionalProperties =
1057
1194
  * implementing the `validateManualFieldExtensionParameters` function)
1058
1195
  */
1059
1196
  errors: Record<string, unknown>;
1197
+ /** The field entity that is being edited in the form */
1198
+ pendingField: PendingField;
1199
+ /** The model for the field being edited */
1200
+ itemType: ModelBlock;
1060
1201
  };
1061
1202
  export declare type RenderManualFieldExtensionConfigScreenProperties = RenderProperties & RenderManualFieldExtensionConfigScreenAdditionalProperties;
1062
1203
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datocms-plugin-sdk",
3
- "version": "0.3.10",
3
+ "version": "0.3.24-alpha.3",
4
4
  "description": "DatoCMS Plugin SDK",
5
5
  "keywords": [
6
6
  "datocms",
@@ -41,5 +41,5 @@
41
41
  "devDependencies": {
42
42
  "typedoc": "^0.22.8"
43
43
  },
44
- "gitHead": "73616f8cbc087607c38281529f64eb849e718139"
44
+ "gitHead": "e0d3595cc0a4b048f5f10fbd65a5b8aa3be13936"
45
45
  }