datocms-plugin-sdk 0.6.10 → 0.6.15-alpha.0

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/src/connect.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import connectToParent from 'penpal/lib/connectToParent';
2
- import { Field, ItemType } from './SiteApiSchema';
2
+ import { Field, Item, ItemType } from './SiteApiSchema';
3
3
  import {
4
4
  AssetSource,
5
5
  ContentAreaSidebarItem,
@@ -92,21 +92,62 @@ export type FullConnectParameters = {
92
92
  * This function will be called once at boot time and can be used to perform
93
93
  * ie. some initial integrity checks on the configuration.
94
94
  *
95
- * @group boot
95
+ * @tag boot
96
96
  */
97
97
  onBoot: (ctx: OnBootCtx) => void;
98
+
99
+ /**
100
+ * This function will be called before destroying a record. You can stop the
101
+ * action by returning `false`
102
+ *
103
+ * @tag beforeHooks
104
+ */
105
+ onBeforeItemDestroy: (item: Item, ctx: OnBootCtx) => Promise<boolean>;
106
+
107
+ /**
108
+ * This function will be called before saving a new version of a record. You
109
+ * can stop the action by returning `false`
110
+ *
111
+ * @tag beforeHooks
112
+ */
113
+ onBeforeItemSave: (item: Item, ctx: OnBootCtx) => Promise<boolean>;
114
+
115
+ /**
116
+ * This function will be called before publishing a record. You can stop the
117
+ * action by returning `false`
118
+ *
119
+ * @tag beforeHooks
120
+ */
121
+ onBeforeItemPublish: (item: Item, ctx: OnBootCtx) => Promise<boolean>;
122
+
123
+ /**
124
+ * This function will be called before unpublishing a record. You can stop the
125
+ * action by returning `false`
126
+ *
127
+ * @tag beforeHooks
128
+ */
129
+ onBeforeItemUnpublish: (item: Item, ctx: OnBootCtx) => Promise<boolean>;
130
+
131
+ /**
132
+ * This function will be called before duplicating a record. You can stop the
133
+ * action by returning `false`
134
+ *
135
+ * @tag beforeHooks
136
+ */
137
+ onBeforeItemDuplicate: (item: Item, ctx: OnBootCtx) => Promise<boolean>;
138
+
98
139
  /**
99
140
  * Use this function to declare new tabs you want to add in the top-bar of the
100
141
  * UI
101
142
  *
102
- * @group pages
143
+ * @tag pages
103
144
  */
104
145
  mainNavigationTabs: (ctx: IntentCtx) => MainNavigationTab[];
105
146
  /**
106
147
  * Use this function to declare new navigation sections in the Settings Area
107
148
  * sidebar
108
149
  *
109
- * @group pages
150
+ * @tag pages
110
151
  */
111
152
  settingsAreaSidebarItemGroups: (
112
153
  ctx: IntentCtx,
@@ -115,28 +156,28 @@ export type FullConnectParameters = {
115
156
  * Use this function to declare new navigation items in the Content Area
116
157
  * sidebar
117
158
  *
118
- * @group pages
159
+ * @tag pages
119
160
  */
120
161
  contentAreaSidebarItems: (ctx: IntentCtx) => ContentAreaSidebarItem[];
121
162
  /**
122
163
  * Use this function to declare new field extensions that users will be able
123
164
  * to install manually in some field
124
165
  *
125
- * @group manualFieldExtensions
166
+ * @tag manualFieldExtensions
126
167
  */
127
168
  manualFieldExtensions: (ctx: IntentCtx) => ManualFieldExtension[];
128
169
  /**
129
170
  * Use this function to declare additional sources to be shown when users want
130
171
  * to upload new assets
131
172
  *
132
- * @group assetSources
173
+ * @tag assetSources
133
174
  */
134
175
  assetSources: (ctx: IntentCtx) => AssetSource[] | void;
135
176
  /**
136
177
  * Use this function to declare new sidebar panels to be shown when the user
137
178
  * edits records of a particular model
138
179
  *
139
- * @group sidebarPanels
180
+ * @tag sidebarPanels
140
181
  */
141
182
  itemFormSidebarPanels: (
142
183
  itemType: ItemType,
@@ -147,7 +188,7 @@ export type FullConnectParameters = {
147
188
  * Use this function to declare custom outlets to be shown at the top of the
148
189
  * record's editing page
149
190
  *
150
- * @group itemFormOutlets
191
+ * @tag itemFormOutlets
151
192
  */
152
193
  itemFormOutlets: (itemType: ItemType, ctx: IntentCtx) => ItemFormOutlet[];
153
194
 
@@ -155,7 +196,7 @@ export type FullConnectParameters = {
155
196
  * Use this function to automatically force one or more field extensions to a
156
197
  * particular field
157
198
  *
158
- * @group forcedFieldExtensions
199
+ * @tag forcedFieldExtensions
159
200
  */
160
201
  overrideFieldExtensions: (
161
202
  field: Field,
@@ -166,7 +207,7 @@ export type FullConnectParameters = {
166
207
  * Use this function to define a number of custom marks for a specific
167
208
  * Structured Text field
168
209
  *
169
- * @group structuredText
210
+ * @tag structuredText
170
211
  */
171
212
  customMarksForStructuredTextField: (
172
213
  field: Field,
@@ -177,7 +218,7 @@ export type FullConnectParameters = {
177
218
  * Use this function to define a number of custom block styles for a specific
178
219
  * Structured Text field
179
220
  *
180
- * @group structuredText
221
+ * @tag structuredText
181
222
  */
182
223
  customBlockStylesForStructuredTextField: (
183
224
  field: Field,
@@ -188,7 +229,7 @@ export type FullConnectParameters = {
188
229
  * This function will be called when the plugin needs to render the plugin's
189
230
  * configuration form
190
231
  *
191
- * @group configScreen
232
+ * @tag configScreen
192
233
  */
193
234
  renderConfigScreen: (ctx: RenderConfigScreenCtx) => void;
194
235
  /**
@@ -196,21 +237,21 @@ export type FullConnectParameters = {
196
237
  * page (see the `mainNavigationTabs`, `settingsAreaSidebarItemGroups` and
197
238
  * `contentAreaSidebarItems` functions)
198
239
  *
199
- * @group pages
240
+ * @tag pages
200
241
  */
201
242
  renderPage: (pageId: string, ctx: RenderPageCtx) => void;
202
243
  /**
203
244
  * This function will be called when the plugin requested to open a modal (see
204
245
  * the `openModal` function)
205
246
  *
206
- * @group modals
247
+ * @tag modals
207
248
  */
208
249
  renderModal: (modalId: string, ctx: RenderModalCtx) => void;
209
250
  /**
210
251
  * This function will be called when the plugin needs to render a sidebar
211
252
  * panel (see the `itemFormSidebarPanels` function)
212
253
  *
213
- * @group sidebarPanels
254
+ * @tag sidebarPanels
214
255
  */
215
256
  renderItemFormSidebarPanel: (
216
257
  sidebarPaneId: string,
@@ -220,7 +261,7 @@ export type FullConnectParameters = {
220
261
  * This function will be called when the plugin needs to render an outlet (see
221
262
  * the `itemFormOutlets` function)
222
263
  *
223
- * @group itemFormOutlets
264
+ * @tag itemFormOutlets
224
265
  */
225
266
  renderItemFormOutlet: (
226
267
  itemFormOutletId: string,
@@ -230,7 +271,7 @@ export type FullConnectParameters = {
230
271
  * This function will be called when the user selects one of the plugin's
231
272
  * asset sources to upload a new media file.
232
273
  *
233
- * @group assetSources
274
+ * @tag assetSources
234
275
  */
235
276
  renderAssetSource: (assetSourceId: string, ctx: RenderAssetSourceCtx) => void;
236
277
  /**
@@ -238,7 +279,7 @@ export type FullConnectParameters = {
238
279
  * extension (see the `manualFieldExtensions` and `overrideFieldExtensions`
239
280
  * functions)
240
281
  *
241
- * @group forcedFieldExtensions
282
+ * @tag forcedFieldExtensions
242
283
  */
243
284
  renderFieldExtension: (
244
285
  fieldExtensionId: string,
@@ -249,7 +290,7 @@ export type FullConnectParameters = {
249
290
  * configuration form for installing a field extension inside a particular
250
291
  * field
251
292
  *
252
- * @group manualFieldExtensions
293
+ * @tag manualFieldExtensions
253
294
  */
254
295
  renderManualFieldExtensionConfigScreen: (
255
296
  fieldExtensionId: string,
@@ -259,7 +300,7 @@ export type FullConnectParameters = {
259
300
  * This function will be called each time the configuration object changes. It
260
301
  * must return an object containing possible validation errors
261
302
  *
262
- * @group manualFieldExtensions
303
+ * @tag manualFieldExtensions
263
304
  */
264
305
  validateManualFieldExtensionParameters: (
265
306
  fieldExtensionId: string,
@@ -387,6 +428,11 @@ export async function connect(
387
428
  manualFieldExtensions,
388
429
  itemFormSidebarPanels,
389
430
  itemFormOutlets,
431
+ onBeforeItemDestroy,
432
+ onBeforeItemPublish,
433
+ onBeforeItemUnpublish,
434
+ onBeforeItemSave,
435
+ onBeforeItemDuplicate,
390
436
  } = configuration;
391
437
 
392
438
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -412,6 +458,11 @@ export async function connect(
412
458
  manualFieldExtensions,
413
459
  itemFormSidebarPanels,
414
460
  itemFormOutlets,
461
+ onBeforeItemDestroy,
462
+ onBeforeItemPublish,
463
+ onBeforeItemUnpublish,
464
+ onBeforeItemSave,
465
+ onBeforeItemDuplicate,
415
466
  overrideFieldExtensions: toMultifield(
416
467
  configuration.overrideFieldExtensions,
417
468
  ),