datocms-plugin-sdk 0.4.0 → 0.5.0-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 +19 -7
- package/dist/cjs/connect.js.map +1 -1
- package/dist/cjs/guards.js +3 -2
- package/dist/cjs/guards.js.map +1 -1
- package/dist/esm/connect.d.ts +18 -3
- package/dist/esm/connect.js +20 -8
- package/dist/esm/connect.js.map +1 -1
- package/dist/esm/guards.d.ts +5 -1
- package/dist/esm/guards.js +2 -1
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/types.d.ts +32 -6
- package/dist/types/connect.d.ts +18 -3
- package/dist/types/guards.d.ts +5 -1
- package/dist/types/types.d.ts +32 -6
- package/package.json +3 -2
- package/src/connect.ts +56 -5
- package/src/guards.ts +6 -1
- package/src/types.ts +41 -6
- package/types.json +2011 -1484
package/src/connect.ts
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
RenderPageMethods,
|
|
24
24
|
RenderPagePropertiesAndMethods,
|
|
25
25
|
RenderSidebarPanelMethods,
|
|
26
|
-
|
|
26
|
+
RenderSidebarPanelPropertiesAndMethods,
|
|
27
27
|
SettingsAreaSidebarItemGroup,
|
|
28
28
|
} from './types';
|
|
29
29
|
import {
|
|
@@ -32,13 +32,20 @@ import {
|
|
|
32
32
|
isRenderAssetSourceParent,
|
|
33
33
|
isRenderConfigScreenParent,
|
|
34
34
|
isRenderFieldExtensionParent,
|
|
35
|
+
isRenderItemFormOutletParent,
|
|
35
36
|
isRenderManualFieldExtensionConfigScreenParent,
|
|
36
37
|
isRenderModalParent,
|
|
37
38
|
isRenderPageParent,
|
|
38
|
-
|
|
39
|
+
isRenderSidebarPanelParent,
|
|
39
40
|
Parent,
|
|
40
41
|
} from './guards';
|
|
41
|
-
import {
|
|
42
|
+
import {
|
|
43
|
+
ItemFormOutlet,
|
|
44
|
+
RenderItemFormOutletMethods,
|
|
45
|
+
RenderItemFormOutletPropertiesAndMethods,
|
|
46
|
+
StructuredTextCustomBlockStyle,
|
|
47
|
+
StructuredTextCustomMark,
|
|
48
|
+
} from '.';
|
|
42
49
|
|
|
43
50
|
export type SizingUtilities = {
|
|
44
51
|
/**
|
|
@@ -68,7 +75,9 @@ export type RenderPageCtx = RenderPagePropertiesAndMethods;
|
|
|
68
75
|
export type RenderModalCtx = RenderModalPropertiesAndMethods & SizingUtilities;
|
|
69
76
|
export type RenderAssetSourceCtx = RenderAssetSourcePropertiesAndMethods &
|
|
70
77
|
SizingUtilities;
|
|
71
|
-
export type RenderItemFormSidebarPanelCtx =
|
|
78
|
+
export type RenderItemFormSidebarPanelCtx = RenderSidebarPanelPropertiesAndMethods &
|
|
79
|
+
SizingUtilities;
|
|
80
|
+
export type RenderItemFormOutletCtx = RenderItemFormOutletPropertiesAndMethods &
|
|
72
81
|
SizingUtilities;
|
|
73
82
|
export type RenderFieldExtensionCtx = RenderFieldExtensionPropertiesAndMethods &
|
|
74
83
|
SizingUtilities;
|
|
@@ -130,6 +139,15 @@ export type FullConnectParameters = {
|
|
|
130
139
|
itemType: ModelBlock,
|
|
131
140
|
ctx: IntentCtx,
|
|
132
141
|
) => ItemFormSidebarPanel[];
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Use this function to declare custom outlets to be shown at the top of the
|
|
145
|
+
* record's editing page
|
|
146
|
+
*
|
|
147
|
+
* @group sidebarPanels
|
|
148
|
+
*/
|
|
149
|
+
itemFormOutlets: (itemType: ModelBlock, ctx: IntentCtx) => ItemFormOutlet[];
|
|
150
|
+
|
|
133
151
|
/**
|
|
134
152
|
* Use this function to automatically force one or more field extensions to a
|
|
135
153
|
* particular field
|
|
@@ -195,6 +213,16 @@ export type FullConnectParameters = {
|
|
|
195
213
|
sidebarPaneId: string,
|
|
196
214
|
ctx: RenderItemFormSidebarPanelCtx,
|
|
197
215
|
) => void;
|
|
216
|
+
/**
|
|
217
|
+
* This function will be called when the plugin needs to render an outlet (see
|
|
218
|
+
* the `itemFormOutlets` function)
|
|
219
|
+
*
|
|
220
|
+
* @group sidebarPanels
|
|
221
|
+
*/
|
|
222
|
+
renderItemFormOutlet: (
|
|
223
|
+
itemFormOutletId: string,
|
|
224
|
+
ctx: RenderItemFormOutletCtx,
|
|
225
|
+
) => void;
|
|
198
226
|
/**
|
|
199
227
|
* This function will be called when the user selects one of the plugin's
|
|
200
228
|
* asset sources to upload a new media file.
|
|
@@ -338,6 +366,7 @@ export async function connect(
|
|
|
338
366
|
contentAreaSidebarItems,
|
|
339
367
|
manualFieldExtensions,
|
|
340
368
|
itemFormSidebarPanels,
|
|
369
|
+
itemFormOutlets,
|
|
341
370
|
} = configuration;
|
|
342
371
|
|
|
343
372
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -362,6 +391,7 @@ export async function connect(
|
|
|
362
391
|
contentAreaSidebarItems,
|
|
363
392
|
manualFieldExtensions,
|
|
364
393
|
itemFormSidebarPanels,
|
|
394
|
+
itemFormOutlets,
|
|
365
395
|
overrideFieldExtensions: toMultifield(
|
|
366
396
|
configuration.overrideFieldExtensions,
|
|
367
397
|
),
|
|
@@ -487,7 +517,7 @@ export async function connect(
|
|
|
487
517
|
render(initialSettings as Settings);
|
|
488
518
|
}
|
|
489
519
|
|
|
490
|
-
if (
|
|
520
|
+
if (isRenderSidebarPanelParent(parent, initialSettings)) {
|
|
491
521
|
type Settings = AsyncReturnType<RenderSidebarPanelMethods['getSettings']>;
|
|
492
522
|
|
|
493
523
|
const renderUtils = buildRenderUtils(parent);
|
|
@@ -508,6 +538,27 @@ export async function connect(
|
|
|
508
538
|
render(initialSettings as Settings);
|
|
509
539
|
}
|
|
510
540
|
|
|
541
|
+
if (isRenderItemFormOutletParent(parent, initialSettings)) {
|
|
542
|
+
type Settings = AsyncReturnType<RenderItemFormOutletMethods['getSettings']>;
|
|
543
|
+
|
|
544
|
+
const renderUtils = buildRenderUtils(parent);
|
|
545
|
+
|
|
546
|
+
const render = (settings: Settings) => {
|
|
547
|
+
if (!configuration.renderItemFormOutlet) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
configuration.renderItemFormOutlet(settings.itemFormOutletId, {
|
|
552
|
+
...parent,
|
|
553
|
+
...settings,
|
|
554
|
+
...renderUtils,
|
|
555
|
+
});
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
listener = render;
|
|
559
|
+
render(initialSettings as Settings);
|
|
560
|
+
}
|
|
561
|
+
|
|
511
562
|
if (isRenderFieldExtensionParent(parent, initialSettings)) {
|
|
512
563
|
type Settings = AsyncReturnType<RenderFieldExtensionMethods['getSettings']>;
|
|
513
564
|
|
package/src/guards.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RenderItemFormOutletMethods } from '.';
|
|
1
2
|
import {
|
|
2
3
|
InitMethods,
|
|
3
4
|
OnBootMethods,
|
|
@@ -31,10 +32,14 @@ export const isRenderModalParent = buildGuard<RenderModalMethods>(
|
|
|
31
32
|
'renderModal',
|
|
32
33
|
);
|
|
33
34
|
|
|
34
|
-
export const
|
|
35
|
+
export const isRenderSidebarPanelParent = buildGuard<RenderSidebarPanelMethods>(
|
|
35
36
|
'renderItemFormSidebarPanel',
|
|
36
37
|
);
|
|
37
38
|
|
|
39
|
+
export const isRenderItemFormOutletParent = buildGuard<RenderItemFormOutletMethods>(
|
|
40
|
+
'renderItemFormOutlet',
|
|
41
|
+
);
|
|
42
|
+
|
|
38
43
|
export const isRenderFieldExtensionParent = buildGuard<RenderFieldExtensionMethods>(
|
|
39
44
|
'renderFieldExtension',
|
|
40
45
|
);
|
package/src/types.ts
CHANGED
|
@@ -99,7 +99,7 @@ export type SettingsAreaSidebarItemGroup = {
|
|
|
99
99
|
* will be displayed by ascending `rank`. If you want to specify an explicit
|
|
100
100
|
* value for `rank`, make sure to offer a way for final users to customize it
|
|
101
101
|
* inside the plugin's settings form, otherwise the hardcoded value you choose
|
|
102
|
-
* might clash with the one of another plugin!
|
|
102
|
+
* might clash with the one of another plugin!
|
|
103
103
|
*/
|
|
104
104
|
rank?: number;
|
|
105
105
|
};
|
|
@@ -133,7 +133,7 @@ export type ContentAreaSidebarItem = {
|
|
|
133
133
|
* will be displayed by ascending `rank`. If you want to specify an explicit
|
|
134
134
|
* value for `rank`, make sure to offer a way for final users to customize it
|
|
135
135
|
* inside the plugin's settings form, otherwise the hardcoded value you choose
|
|
136
|
-
* might clash with the one of another plugin!
|
|
136
|
+
* might clash with the one of another plugin!
|
|
137
137
|
*/
|
|
138
138
|
rank?: number;
|
|
139
139
|
};
|
|
@@ -234,7 +234,22 @@ export type ItemFormSidebarPanel = {
|
|
|
234
234
|
* sorted by ascending `rank`. If you want to specify an explicit value for
|
|
235
235
|
* `rank`, make sure to offer a way for final users to customize it inside the
|
|
236
236
|
* plugin's settings form, otherwise the hardcoded value you choose might
|
|
237
|
-
* clash with the one of another plugin!
|
|
237
|
+
* clash with the one of another plugin!
|
|
238
|
+
*/
|
|
239
|
+
rank?: number;
|
|
240
|
+
/** The initial height to set for the iframe that will render the sidebar panel */
|
|
241
|
+
initialHeight?: number;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/** An outlet to be shown at the top of a record's editing page */
|
|
245
|
+
export type ItemFormOutlet = {
|
|
246
|
+
/** ID of the outlet. Will be the first argument for the `renderItemFormOutlet` function */
|
|
247
|
+
id: string;
|
|
248
|
+
/**
|
|
249
|
+
* Multiple outlets will be sorted by ascending `rank`. If you want to specify
|
|
250
|
+
* an explicit value for `rank`, make sure to offer a way for final users to
|
|
251
|
+
* customize it inside the plugin's settings form, otherwise the hardcoded
|
|
252
|
+
* value you choose might clash with the one of another plugin!
|
|
238
253
|
*/
|
|
239
254
|
rank?: number;
|
|
240
255
|
/** The initial height to set for the iframe that will render the sidebar panel */
|
|
@@ -262,7 +277,7 @@ export type EditorOverride = {
|
|
|
262
277
|
* win. If you want to specify an explicit value for `rank`, make sure to
|
|
263
278
|
* offer a way for final users to customize it inside the plugin's settings
|
|
264
279
|
* form, otherwise the hardcoded value you choose might clash with the one of
|
|
265
|
-
* another plugin!
|
|
280
|
+
* another plugin!
|
|
266
281
|
*/
|
|
267
282
|
rank?: number;
|
|
268
283
|
/** The initial height to set for the iframe that will render the field extension */
|
|
@@ -286,7 +301,7 @@ export type AddonOverride = {
|
|
|
286
301
|
* ascending `rank`. If you want to specify an explicit value for `rank`, make
|
|
287
302
|
* sure to offer a way for final users to customize it inside the plugin's
|
|
288
303
|
* settings form, otherwise the hardcoded value you choose might clash with
|
|
289
|
-
* the one of another plugin!
|
|
304
|
+
* the one of another plugin!
|
|
290
305
|
*/
|
|
291
306
|
rank?: number;
|
|
292
307
|
/** The initial height to set for the iframe that will render the field extension */
|
|
@@ -1202,9 +1217,29 @@ export type RenderSidebarPanelAdditionalMethods = {
|
|
|
1202
1217
|
export type RenderSidebarPanelMethods = ItemFormMethods &
|
|
1203
1218
|
RenderSidebarPanelAdditionalMethods;
|
|
1204
1219
|
|
|
1205
|
-
export type
|
|
1220
|
+
export type RenderSidebarPanelPropertiesAndMethods = RenderSidebarPanelMethods &
|
|
1206
1221
|
RenderSidebarPanelProperties;
|
|
1207
1222
|
|
|
1223
|
+
/** Information regarding the specific outlet that you need to render */
|
|
1224
|
+
export type RenderItemFormOutletAdditionalProperties = {
|
|
1225
|
+
mode: 'renderItemFormOutlet';
|
|
1226
|
+
/** The ID of the outlet that needs to be rendered */
|
|
1227
|
+
itemFormOutletId: string;
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
export type RenderItemFormOutletProperties = ItemFormProperties &
|
|
1231
|
+
RenderItemFormOutletAdditionalProperties;
|
|
1232
|
+
|
|
1233
|
+
export type RenderItemFormOutletAdditionalMethods = {
|
|
1234
|
+
getSettings: () => Promise<RenderItemFormOutletProperties>;
|
|
1235
|
+
};
|
|
1236
|
+
|
|
1237
|
+
export type RenderItemFormOutletMethods = ItemFormMethods &
|
|
1238
|
+
RenderItemFormOutletAdditionalMethods;
|
|
1239
|
+
|
|
1240
|
+
export type RenderItemFormOutletPropertiesAndMethods = RenderItemFormOutletMethods &
|
|
1241
|
+
RenderItemFormOutletProperties;
|
|
1242
|
+
|
|
1208
1243
|
/**
|
|
1209
1244
|
* Information regarding the state of a specific field where you need to render
|
|
1210
1245
|
* the field extension
|