datocms-plugin-sdk 1.0.0-alpha.0 → 1.0.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/dist/cjs/connect.js +42 -20
- 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 +36 -2
- package/dist/esm/connect.js +43 -21
- 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/index.d.ts +11 -1
- package/dist/esm/types.d.ts +123 -4
- package/dist/types/connect.d.ts +36 -2
- package/dist/types/guards.d.ts +4 -1
- package/dist/types/index.d.ts +11 -1
- package/dist/types/types.d.ts +123 -4
- package/package.json +3 -2
- package/src/connect.ts +101 -21
- package/src/guards.ts +5 -0
- package/src/index.ts +12 -12
- package/src/types.ts +4340 -20
- package/types.json +22728 -8513
- package/dist/cjs/SiteApiSchema.js +0 -8
- package/dist/cjs/SiteApiSchema.js.map +0 -1
- package/dist/esm/SiteApiSchema.d.ts +0 -8273
- package/dist/esm/SiteApiSchema.js +0 -7
- package/dist/esm/SiteApiSchema.js.map +0 -1
- package/dist/types/SiteApiSchema.d.ts +0 -8273
- package/src/SiteApiSchema.ts +0 -9000
package/src/connect.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import connectToParent from 'penpal/lib/connectToParent';
|
|
2
|
-
import {
|
|
3
|
-
Field,
|
|
4
|
-
Item,
|
|
5
|
-
ItemCreateSchema,
|
|
6
|
-
ItemType,
|
|
7
|
-
ItemUpdateSchema,
|
|
8
|
-
} from './SiteApiSchema';
|
|
2
|
+
import { SchemaTypes } from '@datocms/cma-client';
|
|
9
3
|
import {
|
|
10
4
|
AssetSource,
|
|
11
5
|
ContentAreaSidebarItem,
|
|
12
6
|
FieldExtensionOverride,
|
|
7
|
+
InitialLocationQueryForItemSelector,
|
|
13
8
|
InitPropertiesAndMethods,
|
|
9
|
+
ItemFormSidebar,
|
|
14
10
|
ItemFormSidebarPanel,
|
|
11
|
+
ItemPresentationInfo,
|
|
15
12
|
MainNavigationTab,
|
|
16
13
|
ManualFieldExtension,
|
|
17
14
|
OnBootMethods,
|
|
@@ -30,6 +27,8 @@ import {
|
|
|
30
27
|
RenderPagePropertiesAndMethods,
|
|
31
28
|
RenderSidebarPanelMethods,
|
|
32
29
|
RenderSidebarPanelPropertiesAndMethods,
|
|
30
|
+
RenderSidebarPropertiesAndMethods,
|
|
31
|
+
RenderSidebarMethods,
|
|
33
32
|
SettingsAreaSidebarItemGroup,
|
|
34
33
|
} from './types';
|
|
35
34
|
import {
|
|
@@ -42,6 +41,7 @@ import {
|
|
|
42
41
|
isRenderModalParent,
|
|
43
42
|
isRenderPageParent,
|
|
44
43
|
isRenderSidebarPanelParent,
|
|
44
|
+
isRenderSidebarParent,
|
|
45
45
|
Parent,
|
|
46
46
|
} from './guards';
|
|
47
47
|
import {
|
|
@@ -52,6 +52,12 @@ import {
|
|
|
52
52
|
StructuredTextCustomMark,
|
|
53
53
|
} from '.';
|
|
54
54
|
|
|
55
|
+
type Field = SchemaTypes.Field;
|
|
56
|
+
type Item = SchemaTypes.Item;
|
|
57
|
+
type ItemCreateSchema = SchemaTypes.ItemCreateSchema;
|
|
58
|
+
type ItemType = SchemaTypes.ItemType;
|
|
59
|
+
type ItemUpdateSchema = SchemaTypes.ItemUpdateSchema;
|
|
60
|
+
|
|
55
61
|
export type SizingUtilities = {
|
|
56
62
|
/**
|
|
57
63
|
* Listens for DOM changes and automatically calls `setHeight` when it detects
|
|
@@ -82,6 +88,8 @@ export type RenderAssetSourceCtx = RenderAssetSourcePropertiesAndMethods &
|
|
|
82
88
|
SizingUtilities;
|
|
83
89
|
export type RenderItemFormSidebarPanelCtx =
|
|
84
90
|
RenderSidebarPanelPropertiesAndMethods & SizingUtilities;
|
|
91
|
+
export type RenderItemFormSidebarCtx = RenderSidebarPropertiesAndMethods &
|
|
92
|
+
SizingUtilities;
|
|
85
93
|
export type RenderItemFormOutletCtx = RenderItemFormOutletPropertiesAndMethods &
|
|
86
94
|
SizingUtilities;
|
|
87
95
|
export type RenderFieldExtensionCtx = RenderFieldExtensionPropertiesAndMethods &
|
|
@@ -147,6 +155,29 @@ export type FullConnectParameters = {
|
|
|
147
155
|
ctx: OnBootCtx,
|
|
148
156
|
) => MaybePromise<boolean>;
|
|
149
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Use this function to customize the presentation of a record in records
|
|
160
|
+
* collections and "Single link" or "Multiple links" field
|
|
161
|
+
*
|
|
162
|
+
* @tag presentation
|
|
163
|
+
*/
|
|
164
|
+
buildItemPresentationInfo: (
|
|
165
|
+
item: Item,
|
|
166
|
+
ctx: OnBootCtx,
|
|
167
|
+
) => MaybePromise<ItemPresentationInfo | undefined>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Use this function to customize the initial filters when opening an record
|
|
171
|
+
* selector via a "Single link" or "Multiple links" field
|
|
172
|
+
*
|
|
173
|
+
* @tag locationQuery
|
|
174
|
+
*/
|
|
175
|
+
initialLocationQueryForItemSelector: (
|
|
176
|
+
openerfield: Item,
|
|
177
|
+
itemType: ItemType,
|
|
178
|
+
ctx: OnBootCtx,
|
|
179
|
+
) => MaybePromise<InitialLocationQueryForItemSelector | undefined>;
|
|
180
|
+
|
|
150
181
|
/**
|
|
151
182
|
* Use this function to declare new tabs you want to add in the top-bar of the
|
|
152
183
|
* UI
|
|
@@ -195,6 +226,14 @@ export type FullConnectParameters = {
|
|
|
195
226
|
ctx: IntentCtx,
|
|
196
227
|
) => ItemFormSidebarPanel[];
|
|
197
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Use this function to declare new sidebar to be shown when the user edits
|
|
231
|
+
* records of a particular model
|
|
232
|
+
*
|
|
233
|
+
* @tag sidebarPanels
|
|
234
|
+
*/
|
|
235
|
+
itemFormSidebars: (itemType: ItemType, ctx: IntentCtx) => ItemFormSidebar[];
|
|
236
|
+
|
|
198
237
|
/**
|
|
199
238
|
* Use this function to declare custom outlets to be shown at the top of the
|
|
200
239
|
* record's editing page
|
|
@@ -268,6 +307,16 @@ export type FullConnectParameters = {
|
|
|
268
307
|
sidebarPaneId: string,
|
|
269
308
|
ctx: RenderItemFormSidebarPanelCtx,
|
|
270
309
|
) => void;
|
|
310
|
+
/**
|
|
311
|
+
* This function will be called when the plugin needs to render a sidebar (see
|
|
312
|
+
* the `itemFormSidebars` function)
|
|
313
|
+
*
|
|
314
|
+
* @tag sidebarPanels
|
|
315
|
+
*/
|
|
316
|
+
renderItemFormSidebar: (
|
|
317
|
+
sidebarId: string,
|
|
318
|
+
ctx: RenderItemFormSidebarCtx,
|
|
319
|
+
) => void;
|
|
271
320
|
/**
|
|
272
321
|
* This function will be called when the plugin needs to render an outlet (see
|
|
273
322
|
* the `itemFormOutlets` function)
|
|
@@ -357,9 +406,7 @@ const buildRenderUtils = (parent: { setHeight: (number: number) => void }) => {
|
|
|
357
406
|
? Math.max(
|
|
358
407
|
document.body.scrollHeight,
|
|
359
408
|
document.body.offsetHeight,
|
|
360
|
-
document.documentElement.
|
|
361
|
-
document.documentElement.scrollHeight,
|
|
362
|
-
document.documentElement.offsetHeight,
|
|
409
|
+
document.documentElement.getBoundingClientRect().height,
|
|
363
410
|
)
|
|
364
411
|
: height;
|
|
365
412
|
|
|
@@ -370,29 +417,39 @@ const buildRenderUtils = (parent: { setHeight: (number: number) => void }) => {
|
|
|
370
417
|
};
|
|
371
418
|
|
|
372
419
|
let resizeObserver: ResizeObserver | null = null;
|
|
420
|
+
let mutationObserver: MutationObserver | null = null;
|
|
421
|
+
const onMutation = () => updateHeight();
|
|
373
422
|
|
|
374
423
|
const startAutoResizer = () => {
|
|
375
424
|
updateHeight();
|
|
376
425
|
|
|
377
|
-
if (resizeObserver) {
|
|
378
|
-
|
|
426
|
+
if (!resizeObserver) {
|
|
427
|
+
resizeObserver = new ResizeObserver(onMutation);
|
|
428
|
+
resizeObserver.observe(document.documentElement);
|
|
379
429
|
}
|
|
380
430
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
updateHeight();
|
|
384
|
-
});
|
|
431
|
+
if (!mutationObserver) {
|
|
432
|
+
mutationObserver = new MutationObserver(onMutation);
|
|
385
433
|
|
|
386
|
-
|
|
434
|
+
mutationObserver.observe(window.document.body, {
|
|
435
|
+
attributes: true,
|
|
436
|
+
childList: true,
|
|
437
|
+
subtree: true,
|
|
438
|
+
characterData: true,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
387
441
|
};
|
|
388
442
|
|
|
389
443
|
const stopAutoResizer = () => {
|
|
390
|
-
if (
|
|
391
|
-
|
|
444
|
+
if (resizeObserver) {
|
|
445
|
+
resizeObserver.disconnect();
|
|
446
|
+
resizeObserver = null;
|
|
392
447
|
}
|
|
393
448
|
|
|
394
|
-
|
|
395
|
-
|
|
449
|
+
if (mutationObserver) {
|
|
450
|
+
mutationObserver.disconnect();
|
|
451
|
+
mutationObserver = null;
|
|
452
|
+
}
|
|
396
453
|
};
|
|
397
454
|
|
|
398
455
|
return { updateHeight, startAutoResizer, stopAutoResizer };
|
|
@@ -408,6 +465,7 @@ export async function connect(
|
|
|
408
465
|
contentAreaSidebarItems,
|
|
409
466
|
manualFieldExtensions,
|
|
410
467
|
itemFormSidebarPanels,
|
|
468
|
+
itemFormSidebars,
|
|
411
469
|
itemFormOutlets,
|
|
412
470
|
} = configuration;
|
|
413
471
|
// rome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
@@ -439,6 +497,7 @@ export async function connect(
|
|
|
439
497
|
contentAreaSidebarItems,
|
|
440
498
|
manualFieldExtensions,
|
|
441
499
|
itemFormSidebarPanels,
|
|
500
|
+
itemFormSidebars,
|
|
442
501
|
itemFormOutlets,
|
|
443
502
|
overrideFieldExtensions: toMultifield(
|
|
444
503
|
configuration.overrideFieldExtensions,
|
|
@@ -609,6 +668,27 @@ export async function connect(
|
|
|
609
668
|
render(initialSettings as Settings);
|
|
610
669
|
}
|
|
611
670
|
|
|
671
|
+
if (isRenderSidebarParent(parent, initialSettings)) {
|
|
672
|
+
type Settings = AwaitedReturnType<RenderSidebarMethods['getSettings']>;
|
|
673
|
+
|
|
674
|
+
const renderUtils = buildRenderUtils(parent);
|
|
675
|
+
|
|
676
|
+
const render = (settings: Settings) => {
|
|
677
|
+
if (!configuration.renderItemFormSidebar) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
configuration.renderItemFormSidebar(settings.sidebarId, {
|
|
682
|
+
...parent,
|
|
683
|
+
...settings,
|
|
684
|
+
...renderUtils,
|
|
685
|
+
});
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
listener = render;
|
|
689
|
+
render(initialSettings as Settings);
|
|
690
|
+
}
|
|
691
|
+
|
|
612
692
|
if (isRenderItemFormOutletParent(parent, initialSettings)) {
|
|
613
693
|
type Settings = AwaitedReturnType<
|
|
614
694
|
RenderItemFormOutletMethods['getSettings']
|
package/src/guards.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
RenderSidebarPanelMethods,
|
|
9
9
|
RenderModalMethods,
|
|
10
10
|
RenderAssetSourceMethods,
|
|
11
|
+
RenderSidebarMethods,
|
|
11
12
|
} from './types';
|
|
12
13
|
|
|
13
14
|
export type Parent = { getSettings: () => Promise<{ mode: string }> };
|
|
@@ -31,6 +32,10 @@ export const isRenderSidebarPanelParent = buildGuard<RenderSidebarPanelMethods>(
|
|
|
31
32
|
'renderItemFormSidebarPanel',
|
|
32
33
|
);
|
|
33
34
|
|
|
35
|
+
export const isRenderSidebarParent = buildGuard<RenderSidebarMethods>(
|
|
36
|
+
'renderItemFormSidebar',
|
|
37
|
+
);
|
|
38
|
+
|
|
34
39
|
export const isRenderItemFormOutletParent =
|
|
35
40
|
buildGuard<RenderItemFormOutletMethods>('renderItemFormOutlet');
|
|
36
41
|
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { SchemaTypes } from '@datocms/cma-client';
|
|
2
|
+
|
|
3
|
+
type Account = SchemaTypes.Account;
|
|
4
|
+
type Field = SchemaTypes.Field;
|
|
5
|
+
type Item = SchemaTypes.Item;
|
|
6
|
+
type ItemType = SchemaTypes.ItemType;
|
|
7
|
+
type Plugin = SchemaTypes.Plugin;
|
|
8
|
+
type Site = SchemaTypes.Site;
|
|
9
|
+
type SsoUser = SchemaTypes.SsoUser;
|
|
10
|
+
type Upload = SchemaTypes.Upload;
|
|
11
|
+
type User = SchemaTypes.User;
|
|
12
|
+
type Role = SchemaTypes.Role;
|
|
13
13
|
|
|
14
14
|
export type {
|
|
15
15
|
Account,
|